The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
virtual_servers.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: 43956c8e38a7467c6ad7f5ec877997ee42803e1d $
19 *
20 * @file virtual_servers.c
21 * @brief Defines functions for virtual_server initialisation.
22 *
23 * @copyright 2003,2006 The FreeRADIUS server project
24 * @copyright 2000 Alan DeKok (aland@freeradius.org)
25 * @copyright 2000 Alan Curry (pacman@world.std.com)
26 */
27RCSID("$Id: 43956c8e38a7467c6ad7f5ec877997ee42803e1d $")
28
29#include <freeradius-devel/protocol/freeradius/freeradius.internal.h>
30#include <freeradius-devel/server/base.h>
31#include <freeradius-devel/server/cf_util.h>
32#include <freeradius-devel/server/command.h>
33#include <freeradius-devel/server/module.h>
34#include <freeradius-devel/server/dl_module.h>
35#include <freeradius-devel/server/global_lib.h>
36#include <freeradius-devel/server/modpriv.h>
37#include <freeradius-devel/server/process.h>
38#include <freeradius-devel/server/protocol.h>
39#include <freeradius-devel/server/section.h>
40#include <freeradius-devel/server/virtual_servers.h>
41
42#include <freeradius-devel/unlang/compile.h>
43#include <freeradius-devel/unlang/function.h>
44
45#include <freeradius-devel/io/application.h>
46#include <freeradius-devel/io/master.h>
47#include <freeradius-devel/io/listen.h>
48
49typedef struct {
50 module_instance_t *proto_mi; //!< The proto_* module for a listen section.
51 fr_app_t const *proto_module; //!< Public interface to the proto_mi.
52 ///< cached for convenience.
54
56 CONF_SECTION *server_cs; //!< The server section.
57 fr_virtual_listen_t **listeners; //!< Listeners in this virtual server.
58
59 module_instance_t *process_mi; //!< The process_* module for a virtual server.
60 ///< Contains the dictionary used by the virtual
61 ///< server and the entry point for the state machine.
62 fr_process_module_t const *process_module; //!< Public interface to the process_mi.
63 ///< cached for convenience.
64
65 fr_rb_tree_t *sections; //!< List of sections that need to be compiled.
66
67 fr_log_t *log; //!< log destination
68 char const *log_name; //!< name of log destination
69};
70
72
74
77 { .out = &dict_freeradius, .proto = "freeradius" },
78 { NULL }
79};
80
83 { .out = &attr_auth_type, .name = "Auth-Type", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
84
85 { NULL }
86};
87
88/** List of process modules we've loaded
89 *
90 * This is global for all virtual servers. Must be initialised
91 * _before_ the configuration is loaded.
92 */
94
95/** List of proto modules we've loaded
96 *
97 * This is global for all virtual servers. Must be initialised
98 * _before_ the configuration is loaded.
99 */
101
102/** Top level structure holding all virtual servers
103 *
104 */
106
107/** CONF_SECTION holding all the virtual servers
108 *
109 * Set during the call to virtual_server_bootstrap and used by
110 * other virtual server functions.
111 */
113
115
116static int namespace_on_read(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
117
118static int namespace_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
119static int listen_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
120static int server_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule);
121
128
130 /*
131 * Not really ok if it's missing but we want to
132 * let logic elsewhere handle the issue.
133 */
135 .subcs_size = sizeof(virtual_server_t), .subcs_type = "virtual_server_t",
136 .subcs = (void const *) server_on_read_config, .name2 = CF_IDENT_ANY,
137 .on_read = cf_null_on_read },
138
140};
141
142static const conf_parser_t server_config[] = {
145
147 virtual_server_t, listeners),
148 .name2 = CF_IDENT_ANY,
149 .subcs_size = sizeof(fr_virtual_listen_t), .subcs_type = "fr_virtual_listen_t",
150 .func = listen_parse },
151
152 { FR_CONF_OFFSET("log", virtual_server_t, log_name), },
153
155};
156
158 /*
159 * Not really ok if it's missing but we want to
160 * let logic elsewhere handle the issue.
161 */
163 .subcs_size = sizeof(virtual_server_t), .subcs_type = "virtual_server_t",
164 .subcs = (void const *) server_config, .name2 = CF_IDENT_ANY,
165 .func = server_parse },
166
168};
169
170/** Print all the loaded listener instances
171 *
172 */
177
178/** Print all the loaded process module instances
179 *
180 */
185
186/** Resolve proto data to a module instance
187 *
188 * @param[in] data Pointer to the proto data.
189 * @return
190 * - The module instance for the proto data.
191 * - NULL if no data matches.
192 */
197
198/** Generic conf_parser_t func for loading drivers
199 *
200 */
201int virtual_server_listen_transport_parse(TALLOC_CTX *ctx, void *out, void *parent,
202 CONF_ITEM *ci, conf_parser_t const *rule)
203{
204 conf_parser_t our_rule = *rule;
205
206 our_rule.uctx = &proto_modules;
207
208 return module_submodule_parse(ctx, out, parent, ci, &our_rule);
209}
210
211/** Parse a "namespace" parameter
212 *
213 * We need to load the process module before continuing to parse the virtual server contents
214 * as we need to know the namespace so that we can resolve attribute names.
215 *
216 * We also need the compilation list from the proto module to figure out which sections we
217 * need to compile.
218 *
219 * @param[in] ctx to allocate data in.
220 * @param[out] out always NULL
221 * @param[in] parent Base structure address.
222 * @param[in] ci #CONF_SECTION containing the listen section.
223 * @param[in] rule unused.
224 * @return
225 * - 0 on success.
226 * - -1 on failure.
227 */
228static int namespace_on_read(TALLOC_CTX *ctx, UNUSED void *out, UNUSED void *parent,
229 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
230{
231 CONF_PAIR *cp = cf_item_to_pair(ci);
232 CONF_SECTION *server_cs = cf_item_to_section(cf_parent(ci));
234 char const *namespace;
235 char *module_name, *p, *end;
236 char const *inst_name;
237 fr_process_module_t const *process;
238
240 "virtual_servers_init MUST be called before reading virtual server config");
241
242 namespace = cf_pair_value(cp);
243 module_name = talloc_strdup(ctx, namespace);
244
245 /*
246 * Smush all hyphens to underscores for module names
247 */
248 for (p = module_name, end = module_name + talloc_array_length(module_name) - 1;
249 p < end;
250 p++) if (*p == '-') *p = '_';
251
252 if (module_instance_name_from_conf(&inst_name, server_cs) < 0) return -1;
253
254 /*
255 * The module being loaded is the namespace with all '-'
256 * transformed to '_'.
257 *
258 * The instance name is the virtual server name.
259 */
261 module_name, inst_name,
262 0);
263 talloc_free(module_name);
264 if (mi == NULL) {
265 error:
266 cf_log_perr(ci, "Failed loading process module");
267 return -1;
268 }
269 if (unlikely(module_instance_conf_parse(mi, mi->conf) < 0)) goto error;
270
271 process = (fr_process_module_t const *)mi->module->exported;
272 if (!*(process->dict)) {
273 cf_log_err(ci, "Process module is invalid - missing namespace dictionary");
274 talloc_free(mi);
275 return -1;
276 }
277 cf_data_add(server_cs, mi, "process_module", false);
278 cf_data_add(server_cs, *(process->dict), "dict", false);
279
280 return 0;
281}
282
283static inline CC_HINT(always_inline)
285{
286 int i;
288
289 if (!compile_list) return 0;
290
291 for (i = 0; list[i].section; i++) {
292#ifndef NDEBUG
293 /*
294 * We can't have a wildcard for name1. It MUST be a real name.
295 *
296 * The wildcard was allowed previously for ideas which later didn't turn out.
297 */
298 if (list[i].section->name1 == CF_IDENT_ANY) {
299 fr_assert(0);
300 continue;
301 }
302
303#endif
304 if (virtual_server_section_register(vs, &list[i]) < 0) {
305 cf_log_err(cs, "Failed registering processing section name %s for %s",
306 list[i].section->name1, name);
307 return -1;
308 }
309 }
310
311 return 0;
312}
313
314/** dl_open a process_* module
315 *
316 * @param[in] ctx to allocate data in.
317 * @param[out] out Where to our listen configuration. Is a #fr_virtual_listen_t structure.
318 * @param[in] parent Base structure address.
319 * @param[in] ci #CONF_SECTION containing the listen section.
320 * @param[in] rule unused.
321 * @return
322 * - 0 on success.
323 * - -1 on failure.
324 */
325static int namespace_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
326{
327 CONF_PAIR *cp = cf_item_to_pair(ci);
328 CONF_SECTION *server_cs = cf_item_to_section(cf_parent(ci));
329 CONF_SECTION *process_cs;
330 virtual_server_t *server = talloc_get_type_abort(((uint8_t *) out) - offsetof(virtual_server_t, process_mi), virtual_server_t);
331 char const *namespace = cf_pair_value(cp);
332 module_instance_t *mi = cf_data_value(cf_data_find(server_cs, module_instance_t, "process_module"));
333
334 /*
335 * We don't have access to virtual_server_t
336 * in the onread callback, so we need to do the
337 * fixups here.
338 */
339 server->process_mi = mi;
340 server->process_module = (fr_process_module_t const *)mi->module->exported;
341
342 *(module_instance_t const **)out = mi;
343
344 /*
345 * Enforce that the protocol process configuration is in
346 * a subsection named for the protocol.
347 */
348 process_cs = cf_section_find(server_cs, namespace, NULL);
349 if (!process_cs) {
350 process_cs = cf_section_alloc(server_cs, server_cs, namespace, NULL);
351 }
352
353 if (module_instance_conf_parse(mi, process_cs) < 0) {
354 cf_log_perr(ci, "Failed bootstrapping process module");
355 cf_data_remove(server_cs, module_instance_t, "process_module");
356 cf_data_remove(server_cs, fr_dict_t, "dict");
357 TALLOC_FREE(server->process_mi);
358 return -1;
359 }
360
361 /*
362 * Pull the list of sections we need to compile out of
363 * the process module's public struct.
364 */
365 add_compile_list(server, server->process_mi->conf, server->process_module->compile_list, namespace);
366
367 return 0;
368}
369
370/** dl_open a proto_* module
371 *
372 * @param[in] ctx to allocate data in.
373 * @param[out] out Where to our listen configuration. Is a #fr_virtual_listen_t structure.
374 * @param[in] parent Base structure address.
375 * @param[in] ci #CONF_SECTION containing the listen section.
376 * @param[in] rule unused.
377 * @return
378 * - 0 on success.
379 * - -1 on failure.
380 */
381static int listen_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
382{
383 fr_virtual_listen_t *listener = talloc_get_type_abort(out, fr_virtual_listen_t); /* Pre-allocated for us */
384 CONF_SECTION *listener_cs = cf_item_to_section(ci);
385 CONF_SECTION *server_cs = cf_item_to_section(cf_parent(ci));
386 CONF_PAIR *namespace = cf_pair_find(server_cs, "namespace");
387
388 CONF_PAIR *proto;
389 char const *mod_name;
390 char const *inst_name;
391 char *qual_inst_name;
392
394
396 "virtual_servers_init MUST be called before reading virtual server config");
397
398 if (!namespace) {
399 cf_log_err(server_cs, "No 'namespace' set for virtual server");
400 cf_log_err(server_cs, "Please add 'namespace = <protocol>' inside of the 'server %s { ... }' section",
401 cf_section_name2(server_cs));
402 return -1;
403 }
404
405 /*
406 * Module name comes from the 'proto' pair if the
407 * listen section has one else it comes from the
408 * namespace of the virtual server.
409 *
410 * The following results in proto_radius being loaded:
411 *
412 * server foo {
413 * namespace = radius
414 * listen {
415 *
416 * }
417 * }
418 *
419 * The following results in proto_load being loaded:
420 *
421 * server foo {
422 * namespace = radius
423 * listen {
424 * proto = load
425 *
426 * }
427 * }
428 *
429 * In this way the server behaves reasonably out
430 * of the box, but allows foreign or generic listeners
431 * to be included in the server.
432 *
433 */
434 proto = cf_pair_find(listener_cs, "proto");
435 if (proto) {
436 mod_name = cf_pair_value(proto);
437 } else {
438 mod_name = cf_pair_value(namespace);
439 }
440
441 /*
442 * Inst name comes from the 'listen' name2
443 * or from the module name.
444 *
445 * The inst name is qualified with the name
446 * of the server the listener appears in.
447 *
448 * The following results in the instance name of 'foo.radius':
449 *
450 * server foo {
451 * namespace = radius
452 * listen {
453 *
454 * }
455 * }
456 *
457 * The following results in the instance name 'foo.my_network':
458 *
459 * server foo {
460 * namespace = radius
461 * listen my_network {
462 *
463 * }
464 * }
465 */
466 inst_name = cf_section_name2(listener_cs);
467 if (!inst_name) inst_name = mod_name;
468
469 if (module_instance_name_valid(inst_name) < 0) {
470 error:
471 cf_log_err(listener_cs, "Failed loading listener");
472 return -1;
473 }
474
475 MEM(qual_inst_name = talloc_asprintf(NULL, "%s.%s", cf_section_name2(server_cs), inst_name));
476 mi = module_instance_alloc(proto_modules, NULL, DL_MODULE_TYPE_PROTO, mod_name, qual_inst_name, 0);
477 talloc_free(qual_inst_name);
478 if (!mi) goto error;
479
480 if (unlikely(module_instance_conf_parse(mi, listener_cs) < 0)) goto error;
481
482 if (DEBUG_ENABLED4) cf_log_debug(ci, "Loading %s listener into %p", inst_name, out);
483
484 listener->proto_mi = mi;
485 listener->proto_module = (fr_app_t const *)listener->proto_mi->module->exported;
486 cf_data_add(listener_cs, mi, "proto_module", false);
487
488 return 0;
489}
490
491static int8_t virtual_server_compile_name_cmp(void const *a, void const *b)
492{
493 virtual_server_compile_t const *sa = a;
494 virtual_server_compile_t const *sb = b;
495
496 return section_name_cmp(sa->section, sb->section);
497}
498
499/** Callback to validate the server section
500 *
501 * @param[in] ctx to allocate data in.
502 * @param[out] out Where to our listen configuration. Is a #virtual_server_t structure.
503 * @param[in] parent Base structure address.
504 * @param[in] ci #CONF_SECTION containing the listen section.
505 * @param[in] rule unused.
506 * @return
507 * - 0 on success.
508 * - -1 on failure.
509 */
510static int server_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
511 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
512{
513 virtual_server_t *server = talloc_get_type_abort(out, virtual_server_t);
514 CONF_SECTION *server_cs = cf_item_to_section(ci);
515 CONF_PAIR *namespace;
516
517 namespace = cf_pair_find(server_cs, "namespace");
518 if (!namespace) {
519 cf_log_err(server_cs, "virtual server %s MUST contain a 'namespace' option",
520 cf_section_name2(server_cs));
521 return -1;
522 }
523
525 server->server_cs = server_cs;
526
527 /*
528 * Now parse the listeners
529 */
530 if (cf_section_parse(out, server, server_cs) < 0) return -1;
531
532 /*
533 * And cache this struct for later referencing.
534 */
535 cf_data_add(server_cs, server, NULL, false);
536
537 return 0;
538}
539
540/** Return the namespace for the named virtual server
541 *
542 * @param[in] virtual_server to look for namespace in.
543 * @return
544 * - NULL on error.
545 * - Namespace on success.
546 */
547fr_dict_t const *virtual_server_dict_by_name(char const *virtual_server)
548{
549 virtual_server_t const *vs;
550
551 vs = virtual_server_find(virtual_server);
552 if (!vs) return NULL;
553
555}
556
557/** Return the namespace for the virtual server specified by a config section
558 *
559 * @param[in] server_cs to look for namespace in.
560 * @return
561 * - NULL on error.
562 * - Namespace on success.
563 */
565{
566 CONF_DATA const *cd;
567 fr_dict_t *dict;
568
569 cd = cf_data_find(server_cs, fr_dict_t, "dict");
570 if (!cd) return NULL;
571
572 dict = cf_data_value(cd);
573 (void) talloc_get_type_abort(dict, fr_dict_t);
574
575 return dict;
576}
577
578/** Return the namespace for a given virtual server specified by a CONF_ITEM within the virtual server
579 *
580 * @param[in] ci to look for namespace in.
581 * @return
582 * - NULL on error.
583 * - Namespace on success.
584 */
586{
587 CONF_DATA const *cd;
588 fr_dict_t *dict;
589
590 cd = cf_data_find_in_parent(ci, fr_dict_t, "dict");
591 if (!cd) return NULL;
592
593 dict = cf_data_value(cd);
594 (void) talloc_get_type_abort(dict, fr_dict_t);
595
596 return dict;
597}
598
599/** Verify that a given virtual_server exists and is of a particular namespace
600 *
601 * Mostly used by modules to check virtual servers specified by their configs.
602 *
603 * @param[out] out we found. May be NULL if just checking for existence.
604 * @param[in] virtual_server to check.
605 * @param[in] namespace the virtual server must belong to.
606 * @param[in] ci to log errors against. May be NULL if caller
607 * doesn't want errors logged.
608 * @return
609 * - 0 on success.
610 * - -1 if no virtual server could be found.
611 * - -2 if virtual server is not of the correct namespace.
612 */
614 char const *virtual_server, fr_dict_t const *namespace, CONF_ITEM *ci)
615{
616 virtual_server_t const *vs;
617 CONF_SECTION *server_cs;
618 fr_dict_t const *dict;
619
620 if (out) *out = NULL;
621
622 vs = virtual_server_find(virtual_server);
623 if (!vs) {
624 if (ci) cf_log_err(ci, "Can't find virtual server \"%s\"", virtual_server);
625 return -1;
626 }
627 server_cs = virtual_server_cs(vs);
628
629 dict = virtual_server_dict_by_name(virtual_server);
630 if (!dict) {
631 /*
632 * Not sure this is even a valid state?
633 */
634 if (ci) cf_log_err(ci, "No namespace found in virtual server \"%s\"", virtual_server);
635 return -2;
636 }
637
638 if (dict != namespace) {
639 if (ci) {
640 cf_log_err(ci,
641 "Expected virtual server \"%s\" to be of namespace \"%s\", got namespace \"%s\"",
642 virtual_server, fr_dict_root(namespace)->name, fr_dict_root(dict)->name);
643 }
644 return -2;
645 }
646
647 if (out) *out = server_cs;
648
649 return 0;
650}
651
652/*
653 * If we pushed a log destination, we need to pop it/
654 */
656 request_t *request, void *uctx)
657{
658 virtual_server_t *server = uctx;
659
660 request_log_prepend(request, server->log, L_DBG_LVL_DISABLE);
661
663}
664
665static void server_signal_remove_log_destination(request_t *request, UNUSED fr_signal_t action, void *uctx)
666{
667 virtual_server_t *server = uctx;
668
669 request_log_prepend(request, server->log, L_DBG_LVL_DISABLE);
670}
671
672/** Set the request processing function.
673 *
674 * Short-term hack
675 */
676unlang_action_t virtual_server_push(request_t *request, CONF_SECTION *server_cs, bool top_frame)
677{
678 virtual_server_t *server;
679
680 server = cf_data_value(cf_data_find(server_cs, virtual_server_t, NULL));
681 if (!server) {
682 cf_log_err(server_cs, "server_cs does not contain virtual server data");
683 return UNLANG_ACTION_FAIL;
684 }
685
686 /*
687 * Add a log destination specific to this virtual server.
688 *
689 * If we add a log destination, make sure to remove it when we walk back up the stack.
690 * But ONLY if we're not at the top of the stack.
691 *
692 * When a brand new request comes in, it has a "call" frame pushed, and then this function is
693 * called. So if we're at the top of the stack, we don't need to pop any logging function,
694 * because the request will die immediately after the top "call" frame is popped.
695 *
696 * However, if we're being reached from a "call" frame in the middle of the stack, then
697 * we do have to pop the log destination when we return.
698 */
699 if (server->log) {
700 request_log_prepend(request, server->log, fr_debug_lvl);
701
702 if (unlang_interpret_stack_depth(request) > 1) {
703 unlang_action_t action;
704
705 action = unlang_function_push(request, NULL, /* don't call it immediately */
706 server_remove_log_destination, /* but when we pop the frame */
708 top_frame, server);
709 if (action != UNLANG_ACTION_PUSHED_CHILD) return action;
710
711 /*
712 * The pushed function may be a top frame, but the virtual server
713 * we're about to push is now definitely a sub frame.
714 */
715 top_frame = UNLANG_SUB_FRAME;
716 }
717 }
718
719 /*
720 * Bootstrap the stack with a module instance.
721 */
722 if (unlang_module_push(&request->rcode, request, server->process_mi,
723 server->process_module->process, top_frame) < 0) return UNLANG_ACTION_FAIL;
724
726}
727
728static int cmd_show_server_list(FILE *fp, UNUSED FILE *fp_err, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info)
729{
730 size_t i, server_cnt = virtual_servers ? talloc_array_length(virtual_servers) : 0;
731
732 if (!server_cnt) return 0;
733
734 for (i = 0; i < server_cnt; i++) {
735 fprintf(fp, "%-30snamespace = %s\n", cf_section_name2(virtual_servers[i]->server_cs),
736 fr_dict_root(*(virtual_servers[i]->process_module->dict))->name);
737 }
738
739 return 0;
740}
741
743 {
744 .parent = "show",
745 .name = "server",
746 .help = "Show virtual server settings.",
747 .read_only = true,
748 },
749
750 {
751 .parent = "show server",
752 .name = "list",
753 .func = cmd_show_server_list,
754 .help = "Show the list of virtual servers loaded in the server.",
755 .read_only = true,
756 },
757
759
760};
761
762/** Compare listeners by app_io_addr
763 *
764 * Only works for IP addresses, and will blow up on file names
765 */
766static int8_t listen_addr_cmp(void const *one, void const *two)
767{
768 fr_listen_t const *a = one;
769 fr_listen_t const *b = two;
770 fr_ipaddr_t aip, bip;
771 int ret;
772
773 /*
774 * The caller must ensure that the address field is set.
775 */
776 if (!a->app_io_addr && !b->app_io_addr) return 0;
777 if (!a->app_io_addr && b->app_io_addr) return -1;
778 if (a->app_io_addr && !b->app_io_addr) return +1;
779
780 /*
781 * Address family
782 */
783 CMP_RETURN(a, b, app_io_addr->af);
784
785 fr_assert((a->app_io_addr->af == AF_INET) || ((a->app_io_addr->af == AF_INET6)));
786
787 /*
788 * UDP vs TCP
789 */
790 CMP_RETURN(a, b, app_io_addr->type);
791
792 /*
793 * Check ports.
794 */
795 CMP_RETURN(a, b, app_io_addr->inet.src_port);
796
797 /*
798 * Don't call fr_ipaddr_cmp(), as we need to do our own
799 * checks here. We have various wildcard checks which
800 * aren't globally applicable.
801 */
802
803 /*
804 * Different address families.
805 */
806 CMP_RETURN(a, b, app_io_addr->inet.src_ipaddr.af);
807
808 /*
809 * If both are bound to interfaces, AND the interfaces
810 * are different, then there is no conflict.
811 */
812 if (a->app_io_addr->inet.src_ipaddr.scope_id && b->app_io_addr->inet.src_ipaddr.scope_id) {
813 CMP_RETURN(a, b, app_io_addr->inet.src_ipaddr.scope_id);
814 }
815
816 ret = a->app_io_addr->inet.src_ipaddr.prefix - b->app_io_addr->inet.src_ipaddr.prefix;
817 aip = a->app_io_addr->inet.src_ipaddr;
818 bip = b->app_io_addr->inet.src_ipaddr;
819
820 /*
821 * Mask out the longer prefix to match the shorter
822 * prefix.
823 */
824 if (ret < 0) {
825 fr_ipaddr_mask(&bip, a->app_io_addr->inet.src_ipaddr.prefix);
826
827 } else if (ret > 0) {
828 fr_ipaddr_mask(&aip, b->app_io_addr->inet.src_ipaddr.prefix);
829
830 }
831
832 return fr_ipaddr_cmp(&aip, &bip);
833}
834
835/** See if another global listener is using a particular IP / port
836 *
837 */
839{
840 if (!listen_addr_root) return false;
841
842 return fr_rb_find(listen_addr_root, li);
843}
844
845
846/** Record that we're listening on a particular IP / port
847 *
848 */
850{
851 if (!listen_addr_root) return false;
852
853 if (!li->app_io_addr) return true;
854
855 if (listen_find_any(li) != NULL) return false;
856
857 return fr_rb_insert(listen_addr_root, li);
858}
859
860/** Return the configuration section for a virtual server
861 *
862 * @param[in] vs to return conf section for
863 * @return
864 * - The CONF_SECTION of the virtual server.
865 */
867{
868 return vs->server_cs;
869}
870
871/** Return virtual server matching the specified name
872 *
873 * @note May be called in bootstrap or instantiate as all servers should be present.
874 *
875 * @param[in] name of virtual server.
876 * @return
877 * - NULL if no virtual server was found.
878 * - The CONF_SECTION of the named virtual server.
879 */
881{
882 CONF_SECTION *server_cs = cf_section_find(virtual_server_root, "server", name);
883 CONF_DATA const *cd;
884
885 if (unlikely(server_cs == NULL)) return NULL;
886
887 cd = cf_data_find(server_cs, virtual_server_t, NULL);
888 if (unlikely(cd == NULL)) return NULL;
889
890 return cf_data_value(cd);
891}
892
893/** Find a virtual server using one of its sections
894 *
895 * @param[in] ci to find parent virtual server for.
896 * @return
897 * - The virtual server section on success.
898 * - NULL if the child isn't associated with any virtual server section.
899 */
901{
902 CONF_SECTION *cs;
903 CONF_DATA const *cd;
904
905 cs = cf_section_find_parent(ci, "server", CF_IDENT_ANY);
906 if (unlikely(!cs)) {
907 cf_log_err(ci, "Child section is not associated with a virtual server");
908 return NULL;
909 }
910
911 cd = cf_data_find(cs, virtual_server_t, NULL);
912 if (unlikely(!cd)) {
913 cf_log_err(ci, "Virtual server section missing virtual_server_t data");
914 return NULL;
915 }
916
917 return cf_data_value(cd);
918}
919
920/** Wrapper for the config parser to allow pass1 resolution of virtual servers
921 *
922 */
923int virtual_server_cf_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
924 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
925{
926 virtual_server_t const *vs;
927
929 if (!vs) {
930 cf_log_err(ci, "virtual-server \"%s\" not found", cf_pair_value(cf_item_to_pair(ci)));
931 return -1;
932 }
933
934 *((CONF_SECTION **)out) = vs->server_cs;
935
936 return 0;
937}
938
939/** Compile sections for a virtual server.
940 *
941 * When the "proto_foo" module calls fr_app_process_instantiate(), it
942 * loads the compile list from the #fr_app_worker_t, and calls this
943 * function.
944 *
945 * This function walks down the registration table, compiling each
946 * named section.
947 *
948 * @param[in] vs to to compile sections for.
949 * @param[in] rules to apply for pass1.
950 */
952{
954 void *instance = vs->process_mi->data;
955 CONF_SECTION *server = vs->server_cs;
956 int i, found;
957 CONF_SECTION *subcs = NULL;
958
959 found = 0;
960
961 /*
962 * Complain about v3 things being used in v4.
963 *
964 * Don't complain when running in normal mode, because the server will just ignore the new
965 * sections. But the check_config stuff is generally run before the service starts, and we
966 * definitely want to tell people when running in debug mode.
967 */
969 bool fail = false;
970
971 while ((subcs = cf_section_next(server, subcs)) != NULL) {
972 char const *name;
973
974 if (cf_section_name2(subcs) != NULL) continue;
975
976 name = cf_section_name1(subcs);
977 if ((strcmp(name, "authorize") == 0) ||
978 (strcmp(name, "authenticate") == 0) ||
979 (strcmp(name, "post-auth") == 0) ||
980 (strcmp(name, "preacct") == 0) ||
981 (strcmp(name, "accounting") == 0) ||
982 (strcmp(name, "pre-proxy") == 0) ||
983 (strcmp(name, "post-proxy") == 0)) {
984 cf_log_err(subcs, "Version 3 processing section '%s' is not valid in version 4.",
985 name);
986 fail = true;
987 }
988 }
989
990 /*
991 * Complain about _all_ of the sections, and not just the first one.
992 */
993 if (fail) return -1;
994 }
995
996 /*
997 * The sections are in trees, so this isn't as bad as it
998 * looks. It's not O(n^2), but O(n logn). But it could
999 * still be improved.
1000 */
1001 for (i = 0; list[i].section; i++) {
1002 int rcode;
1003 CONF_SECTION *bad;
1004
1005 /*
1006 * We are looking for a specific subsection.
1007 * Warn if it isn't found, or compile it if
1008 * found.
1009 */
1010 if (list[i].section->name2 != CF_IDENT_ANY) {
1011 void *instruction = NULL;
1012
1013 subcs = cf_section_find(server, list[i].section->name1, list[i].section->name2);
1014 if (!subcs) {
1015 DEBUG3("Warning: Skipping %s %s { ... } as it was not found.",
1016 list[i].section->name1, list[i].section->name2);
1017 /*
1018 * Initialise CONF_SECTION pointer for missing section
1019 */
1020 if ((instance) && !list[i].dont_cache) {
1021 *(CONF_SECTION **) (((uint8_t *) instance) + list[i].offset) = NULL;
1022 }
1023 continue;
1024 }
1025
1026 /*
1027 * Duplicate sections are forbidden.
1028 */
1029 bad = cf_section_find_next(server, subcs, list[i].section->name1, list[i].section->name2);
1030 if (bad) {
1031 forbidden:
1032 cf_log_err(bad, "Duplicate sections are forbidden.");
1033 cf_log_err(subcs, "Previous definition occurs here.");
1034 return -1;
1035 }
1036
1037 rcode = unlang_compile(vs, subcs, list[i].actions, rules, &instruction);
1038 if (rcode < 0) return -1;
1039
1040 /*
1041 * Cache the CONF_SECTION which was found.
1042 */
1043 if (instance) {
1044 if (!list[i].dont_cache) {
1045 *(CONF_SECTION **) (((uint8_t *) instance) + list[i].offset) = subcs;
1046 }
1047 if (list[i].instruction > 0) {
1048 *(void **) (((uint8_t *) instance) + list[i].instruction) = instruction;
1049 }
1050 }
1051
1052 found++;
1053 continue;
1054 }
1055
1056 /*
1057 * Reset this so that we start from the beginning
1058 * again, instead of starting from the last "send
1059 * foo" block.
1060 */
1061 subcs = NULL;
1062
1063 /*
1064 * Find all subsections with the given first name
1065 * and compile them.
1066 */
1067 while ((subcs = cf_section_find_next(server, subcs, list[i].section->name1, CF_IDENT_ANY))) {
1068 char const *name2;
1069
1070 name2 = cf_section_name2(subcs);
1071 if (!name2) {
1072 cf_log_err(subcs, "Invalid '%s { ... }' section, it must have a name", list[i].section->name1);
1073 return -1;
1074 }
1075
1076 /*
1077 * Duplicate sections are forbidden.
1078 */
1079 bad = cf_section_find_next(server, subcs, list[i].section->name1, name2);
1080 if (bad) goto forbidden;
1081
1082 rcode = unlang_compile(vs, subcs, list[i].actions, rules, NULL);
1083 if (rcode < 0) return -1;
1084
1085 /*
1086 * Note that we don't store the
1087 * CONF_SECTION here, as it's a wildcard.
1088 *
1089 * @todo - count number of subsections
1090 * and store them in an array?
1091 */
1092 found++;
1093 }
1094 }
1095
1096 return found;
1097}
1098
1099/** Register name1 / name2 as allowed processing sections
1100 *
1101 * This function is called from the virtual server bootstrap routine,
1102 * which happens before module_bootstrap();
1103 */
1105{
1107
1108 old = fr_rb_find(vs->sections, entry);
1109 if (old) return 0;
1110
1111#ifndef NDEBUG
1112 /*
1113 * Catch stupid programmers.
1114 *
1115 * Processing sections can't allow "*" for module
1116 * methods, because otherwise you would be allowed to run
1117 * DHCP things in a RADIUS accounting section. And that
1118 * would be bad.
1119 */
1120 if (entry->methods) {
1121 int i;
1122
1123 for (i = 0; entry->methods[i]; i++) {
1124 if (entry->methods[i]->name1 == CF_IDENT_ANY) {
1125 ERROR("Processing sections cannot allow \"*\"");
1126 return -1;
1127 }
1128
1129 if (entry->methods[i]->name2 == CF_IDENT_ANY) {
1130 ERROR("Processing sections cannot allow \"%s *\"",
1131 entry->methods[i]->name1);
1132 return -1;
1133 }
1134 }
1135 }
1136#endif
1137
1138 if (!fr_rb_insert(vs->sections, entry)) {
1139 fr_strerror_const("Failed inserting entry into internal tree");
1140 return -1;
1141 }
1142
1143 return 0;
1144}
1145
1146/** Find the component for a section
1147 *
1148 */
1150{
1152
1153 /*
1154 * Look up the specific name first. That way we can
1155 * define both "accounting on", and "accounting *".
1156 */
1157 if (section->name2 != CF_IDENT_ANY) {
1158 entry = fr_rb_find(vs->sections,
1160 .section = section
1161 });
1162 if (entry) return entry->methods;
1163 }
1164
1165 /*
1166 * Then look up the wildcard, if we didn't find any matching name2.
1167 */
1168 entry = fr_rb_find(vs->sections,
1170 .section = SECTION_NAME(section->name1, CF_IDENT_ANY)
1171 });
1172 if (!entry) return NULL;
1173
1174 return entry->methods;
1175}
1176
1177/** Define a values for Auth-Type attributes by the sections present in a virtual-server
1178 *
1179 * The.name2 value of any sections found will be converted into values of the specified da.
1180 *
1181 * @param[in] server_cs The virtual server containing the sections.
1182 * @param[in] subcs_name of the subsection to search for.
1183 * @param[in] da to add enumeration values for.
1184 * @return
1185 * - 0 all values added successfully.
1186 * - -1 an error occurred.
1187 */
1188int virtual_server_section_attribute_define(CONF_SECTION *server_cs, char const *subcs_name, fr_dict_attr_t const *da)
1189{
1190 int rcode = 0;
1191 CONF_SECTION *subcs = NULL;
1192
1193 fr_assert(strcmp(cf_section_name1(server_cs), "server") == 0);
1194
1195 while ((subcs = cf_section_find_next(server_cs, subcs, subcs_name, CF_IDENT_ANY))) {
1196 char const *name2;
1198
1199 name2 = cf_section_name2(subcs);
1200 if (!name2) {
1201 cf_log_err(subcs, "Invalid '%s { ... }' section, it must have a name", subcs_name);
1202 return -1;
1203 }
1204
1205 /*
1206 * If the value already exists, don't
1207 * create it again.
1208 */
1209 dv = fr_dict_enum_by_name(da, name2, -1);
1210 if (dv) continue;
1211
1212 cf_log_debug(subcs, "Creating %s = %s", da->name, name2);
1213
1214 /*
1215 * Create a new unique value with a meaningless
1216 * number. You can't look at it from outside of
1217 * this code, so it doesn't matter. The only
1218 * requirement is that it's unique.
1219 */
1221 PERROR("Failed adding section value");
1222 return -1;
1223 }
1224
1225 rcode = 1;
1226 }
1227
1228 return rcode;
1229}
1230
1232{
1233 char const *ref;
1234 fr_dict_attr_t const *da;
1235 CONF_ITEM *ci = NULL;
1236
1237 ref = cf_section_name2(cs);
1238 if (!ref) {
1239 cf_log_err(cs, "Expected 'values <name> { ... }'");
1240 return -1;
1241 }
1242
1243 da = fr_dict_attr_by_name(NULL, parent, ref);
1244 if (!da) {
1245 cf_log_err(cs, "No such attribute \"%s\"", ref);
1246 return -1;
1247 }
1248
1249 if (fr_type_is_structural(da->type)) {
1250 cf_log_err(cs, "Cannot define value for structural attribute \"%s\"", ref);
1251 return -1;
1252 }
1253
1254 /*
1255 * This both does not make any sense, and does not get
1256 * parsed correctly if the string contains backslashes.
1257 */
1258 if (da->type == FR_TYPE_STRING) {
1259 cf_log_err(cs, "Cannot define value for 'string' attribute \"%s\"", ref);
1260 return -1;
1261 }
1262
1263 while ((ci = cf_item_next(cs, ci))) {
1264 ssize_t slen, len;
1265 char const *attr, *value;
1266 CONF_PAIR *cp;
1268 fr_value_box_t box;
1269
1270 if (cf_item_is_section(ci)) {
1271 cf_log_err(ci, "Unexpected subsection");
1272 return -1;
1273 }
1274
1275 if (!cf_item_is_pair(ci)) continue;
1276
1277 cp = cf_item_to_pair(ci);
1278 fr_assert(cp != NULL);
1279
1280 /*
1281 * =* is a hack by the cf parser to say "no operator"
1282 */
1283 if ((cf_pair_operator(cp) != T_OP_EQ) ||
1285 cf_log_err(ci, "Definition is not in 'name = value' format");
1286 return -1;
1287 }
1288
1289 attr = cf_pair_attr(cp);
1290 value = cf_pair_value(cp);
1291
1292 dv = fr_dict_enum_by_name(parent, attr, talloc_array_length(attr) - 1);
1293 if (dv) {
1294 cf_log_err(cp, "Duplicate value name");
1295 return -1;
1296 }
1297
1299
1300 len = talloc_array_length(value) - 1;
1301
1302 /*
1303 * @todo - unescape for double quoted strings. Whoops.
1304 */
1305 slen = fr_value_box_from_str(NULL, &box, da->type, da, value, len, NULL, false);
1306 if (slen < 0) {
1307 cf_log_err(cp, "Failed parsing value - %s", fr_strerror());
1308 return -1;
1309 }
1310
1311 if (slen != len) {
1312 cf_log_err(cp, "Unexpected text after value");
1313 return -1;
1314 }
1315
1316 if (fr_dict_enum_add_name(UNCONST(fr_dict_attr_t *, da), attr, &box, false, false) < 0) {
1317 cf_log_err(cp, "Failed adding value - %s", fr_strerror());
1318 return -1;
1319 }
1320
1321 fr_value_box_clear(&box);
1322 }
1323
1324 return 0;
1325}
1326
1327
1329{
1330 CONF_ITEM *ci = NULL;
1331
1332 fr_dict_attr_flags_t flags = {
1333 .internal = true,
1334 .name_only = true,
1335 .local = true,
1336 };
1337
1338 fr_assert(dict != NULL);
1339 fr_assert(parent != NULL);
1340
1341 while ((ci = cf_item_next(cs, ci))) {
1343 char const *attr, *value;
1344 CONF_PAIR *cp;
1345 CONF_SECTION *subcs = NULL;
1346
1347 if (cf_item_is_section(ci)) {
1348 subcs = cf_item_to_section(ci);
1349 fr_assert(subcs != NULL);
1350
1351 attr = cf_section_name1(subcs);
1352
1353 if (strcmp(attr, "values") == 0) {
1354 if (define_server_values(subcs, parent) < 0) return -1;
1355 continue;
1356 }
1357
1358 if (strcmp(attr, "tlv") != 0) goto invalid_type;
1359
1360 value = cf_section_name2(subcs);
1361 if (!value) {
1362 cf_log_err(ci, "Definition is not in 'tlv name { ... }' format");
1363 return -1;
1364 }
1365
1366 type = FR_TYPE_TLV;
1367 goto check_for_dup;
1368 }
1369
1370 if (!cf_item_is_pair(ci)) continue;
1371
1372 cp = cf_item_to_pair(ci);
1373 fr_assert(cp != NULL);
1374
1375 /*
1376 * =* is a hack by the cf parser to say "no operator"
1377 */
1378 if ((cf_pair_operator(cp) != T_OP_CMP_TRUE) ||
1381 cf_log_err(ci, "Definition is not in 'type name' format");
1382 return -1;
1383 }
1384
1385 attr = cf_pair_attr(cp);
1386 value = cf_pair_value(cp);
1387
1389 if (type == FR_TYPE_NULL) {
1391 cf_log_err(ci, "Invalid data type '%s'", attr);
1392 return -1;
1393 }
1394
1395 /*
1396 * Leaf and group are OK. TLV, Vendor, Struct, VSA, etc. are not as variable definitions.
1397 */
1398 if (!(fr_type_is_leaf(type) || (type == FR_TYPE_GROUP))) goto invalid_type;
1399
1400 /*
1401 * No duplicates are allowed.
1402 */
1403 check_for_dup:
1404 if (root && (fr_dict_attr_by_name(NULL, root, value) != NULL)) {
1405 cf_log_err(ci, "Local variable '%s' duplicates a dictionary attribute.", value);
1406 return -1;
1407 }
1408
1409 if (fr_dict_attr_by_name(NULL, parent, value) != NULL) {
1410 cf_log_err(ci, "Local variable '%s' duplicates a previous local attribute.", value);
1411 return -1;
1412 }
1413
1414 if (fr_dict_attr_add_name_only(dict, parent, value, type, &flags) < 0) {
1415 cf_log_err(ci, "Failed adding local variable '%s' - %s", value, fr_strerror());
1416 return -1;
1417 }
1418
1419 if (type == FR_TYPE_TLV) {
1420 fr_dict_attr_t const *da;
1421
1422 if (!subcs) return -1; /* shouldn't happen, but shut up compiler */
1423
1424 da = fr_dict_attr_by_name(NULL, parent, value);
1425 fr_assert(da != NULL);
1426
1427 if (define_server_attrs(subcs, dict, UNCONST(fr_dict_attr_t *, da), NULL) < 0) return -1;
1428 }
1429 }
1430
1431 return 0;
1432}
1433
1434static fr_dict_t const *virtual_server_local_dict(CONF_SECTION *server_cs, fr_dict_t const *dict_def)
1435{
1436 fr_dict_t *dict;
1437 CONF_SECTION *cs;
1438
1439 cs = cf_section_find(server_cs, "dictionary", NULL);
1440 if (!cs) return dict_def;
1441
1442 dict = fr_dict_protocol_alloc(dict_def);
1443 if (!dict) {
1444 cf_log_err(cs, "Failed allocating local dictionary");
1445 return NULL;
1446 }
1447
1448 if (define_server_attrs(cs, dict, UNCONST(fr_dict_attr_t *, fr_dict_root(dict)), fr_dict_root(dict_def)) < 0) return NULL;
1449
1450 /*
1451 * Replace the original dictionary with the new one.
1452 */
1453 cf_data_remove(server_cs, fr_dict_t, "dict");
1454 cf_data_add(server_cs, dict, "dict", false);
1455
1456 return dict;
1457}
1458
1459
1460/** Open all the listen sockets
1461 *
1462 * @param[in] sc Scheduler to add I/O paths to.
1463 * @return
1464 * - 0 on success.
1465 * - -1 on failure.
1466 */
1468{
1469 size_t i, server_cnt = virtual_servers ? talloc_array_length(virtual_servers) : 0;
1470
1472
1473 DEBUG2("#### Opening listener interfaces ####");
1475
1476 for (i = 0; i < server_cnt; i++) {
1477 fr_virtual_listen_t **listeners;
1478 size_t j, listener_cnt;
1479
1480 listeners = virtual_servers[i]->listeners;
1481 listener_cnt = talloc_array_length(listeners);
1482
1483 for (j = 0; j < listener_cnt; j++) {
1484 fr_virtual_listen_t *listener = listeners[j];
1485
1486 fr_assert(listener != NULL);
1487 fr_assert(listener->proto_mi != NULL);
1488 fr_assert(listener->proto_module != NULL);
1489
1490 /*
1491 * The socket is opened with app_instance,
1492 * but all subsequent calls (network.c, etc.) use app_io_instance.
1493 *
1494 * The reason is that we call (for example) proto_radius to
1495 * open the socket, and proto_radius is responsible for setting up
1496 * proto_radius_udp, and then calling proto_radius_udp->open.
1497 *
1498 * Even then, proto_radius usually calls fr_master_io_listen() in order
1499 * to create the fr_listen_t structure.
1500 */
1501 if (listener->proto_module->open) {
1502 int ret;
1503
1504 /*
1505 * Sometimes the open function needs to modify instance
1506 * data, so we need to temporarily remove the protection.
1507 */
1509 ret = listener->proto_module->open(listener->proto_mi->data, sc,
1510 listener->proto_mi->conf);
1512 if (unlikely(ret < 0)) {
1513 cf_log_err(listener->proto_mi->conf,
1514 "Opening %s I/O interface failed",
1515 listener->proto_module->common.name);
1516
1517 return -1;
1518 }
1519
1520 }
1521
1522 /*
1523 * Socket information is printed out by
1524 * the socket handlers. e.g. proto_radius_udp
1525 */
1526 DEBUG3("Opened listener for %s", listener->proto_module->common.name);
1527 }
1528 }
1529
1530 return 0;
1531}
1532
1533/** Free thread-specific data for all process modules and listeners
1534 *
1535 */
1541
1542/** Perform thread instantiation for all process modules and listeners
1543 *
1544 */
1546{
1547 if (modules_thread_instantiate(ctx, process_modules, el) < 0) return -1;
1550 return -1;
1551 }
1552 return 0;
1553}
1554
1555/** Instantiate all the virtual servers
1556 *
1557 * @return
1558 * - 0 on success.
1559 * - -1 on failure.
1560 */
1562{
1563 size_t i, server_cnt;
1564
1565 /*
1566 * User didn't specify any "server" sections
1567 */
1568 if (unlikely(!virtual_servers)) {
1569 ERROR("No virtual servers configured");
1570 return -1;
1571 }
1572
1573 server_cnt = talloc_array_length(virtual_servers);
1574
1575 DEBUG2("#### Instantiating listeners ####");
1576
1578 PERROR("Failed registering radmin commands for virtual servers");
1579 return -1;
1580 }
1581
1582 for (i = 0; i < server_cnt; i++) {
1583 CONF_ITEM *ci = NULL;
1584 CONF_SECTION *server_cs = virtual_servers[i]->server_cs;
1585 fr_dict_t const *dict;
1587 fr_process_module_t const *process = (fr_process_module_t const *)
1588 vs->process_mi->module->exported;
1589
1590 /*
1591 * Set up logging before doing anything else.
1592 */
1593 if (vs->log_name) {
1594 vs->log = log_dst_by_name(vs->log_name);
1595 if (!vs->log) {
1596 CONF_PAIR *cp = cf_pair_find(server_cs, "log");
1597
1598 if (cp) {
1599 cf_log_err(cp, "Unknown log destination '%s'", vs->log_name);
1600 } else {
1601 cf_log_err(server_cs, "Unknown log destination '%s'", vs->log_name);
1602 }
1603
1604 return -1;
1605 }
1606 }
1607
1608 dict = virtual_server_local_dict(server_cs, *(process)->dict);
1609 if (!dict) return -1;
1610
1611 DEBUG("Compiling policies in server %s { ... }", cf_section_name2(server_cs));
1612
1613 fr_assert(virtual_servers[i]->process_mi);
1614
1615 /*
1616 * Compile the processing sections indicated by
1617 * the process module. This must be done before
1618 * module_instantiate is called, as the instance
1619 * data is protected after this call.
1620 */
1621 if (process->compile_list) {
1622 tmpl_rules_t parse_rules = {
1623 .attr = {
1624 .dict_def = dict,
1625 .list_def = request_attr_request,
1626 },
1627 };
1628
1629 fr_assert(parse_rules.attr.dict_def != NULL);
1630
1631 if (virtual_server_compile_sections(virtual_servers[i], &parse_rules) < 0) {
1632 return -1;
1633 }
1634 }
1635
1636 /*
1637 * Print out warnings for unused "recv" and
1638 * "send" sections.
1639 *
1640 * @todo - check against the "compile_list"
1641 * registered for this virtual server, instead of hard-coding stuff.
1642 */
1643 while ((ci = cf_item_next(server_cs, ci))) {
1644 char const *name;
1645 CONF_SECTION *subcs;
1646
1647 if (!cf_item_is_section(ci)) continue;
1648
1649 subcs = cf_item_to_section(ci);
1650 name = cf_section_name1(subcs);
1651
1652 /*
1653 * Skip known "other" sections
1654 */
1655 if ((strcmp(name, "listen") == 0) || (strcmp(name, "client") == 0)) continue;
1656
1657 /*
1658 * For every other section, warn if it hasn't
1659 * been compiled.
1660 */
1661 if (!cf_data_find(subcs, unlang_group_t, NULL)) {
1662 char const *name2;
1663
1664 name2 = cf_section_name2(subcs);
1665 if (!name2) name2 = "";
1666
1667 cf_log_warn(subcs, "%s %s { ... } section is unused", name, name2);
1668 }
1669 }
1670 }
1671
1673 PERROR("Failed instantiating process modules");
1674 return -1;
1675 }
1677 PERROR("Failed instantiating protocol modules");
1678 return -1;
1679 }
1680
1681 return 0;
1682}
1683
1684/** Load protocol modules and call their bootstrap methods
1685 *
1686 * @param[in] config section containing the virtual servers to bootstrap.
1687 * @return
1688 * - 0 on success.
1689 * - -1 on failure.
1690 */
1692{
1694
1695 /*
1696 * Ensure any libraries the modules depend on are instantiated
1697 */
1699
1701 PERROR("Failed instantiating process modules");
1702 return -1;
1703 }
1705 PERROR("Failed instantiating protocol modules");
1706 return -1;
1707 }
1708
1709 return 0;
1710}
1711
1713{
1714 if (talloc_free(listen_addr_root) < 0) return -1;
1715 listen_addr_root = NULL;
1716 if (talloc_free(process_modules) < 0) return -1;
1717 process_modules = NULL;
1718 if (talloc_free(proto_modules) < 0) return -1;
1719 proto_modules = NULL;
1721
1722 return 0;
1723}
1724
1725static int _virtual_servers_atexit(UNUSED void *uctx)
1726{
1727 return virtual_servers_free();
1728}
1729
1730/** Performs global initialisation for the virtual server code
1731 *
1732 * This has to be done separately and explicitly, because the above code makes
1733 * use of "onread" callbacks.
1734 *
1735 * Will automatically free module lists on exit, but all modules should have
1736 * been removed from this list by the point that happens.
1737 */
1739{
1741 PERROR("%s", __FUNCTION__);
1742 return -1;
1743 }
1745 PERROR("%s", __FUNCTION__);
1747 return -1;
1748 }
1749
1751
1752 /*
1753 * FIXME - We should be able to turn on write protection,
1754 * but there are too many proto modules that hang things
1755 * off of their instance data.
1756 */
1757 MEM(proto_modules = module_list_alloc(NULL, &module_list_type_global, "protocol", false));
1758 MEM(listen_addr_root = fr_rb_inline_alloc(NULL, fr_listen_t, virtual_server_node, listen_addr_cmp, NULL));
1759
1760 /*
1761 * Create a list to hold all the proto_* modules
1762 * that get loaded during startup.
1763 */
1765
1766 return 0;
1767}
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_PUSHED_CHILD
unlang_t pushed a new child onto the stack, execute it instead of continuing.
Definition action.h:39
@ UNLANG_ACTION_FAIL
Encountered an unexpected error.
Definition action.h:36
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:37
module_t common
Common fields provided by all modules.
Definition application.h:72
fr_app_open_t open
Callback to allow the fr_app_t to build an fr_listen_t and register it with the scheduler so we can r...
Definition application.h:76
Describes a new application (protocol)
Definition application.h:71
#define fr_atexit_global(_func, _uctx)
Add a free function to the global free list.
Definition atexit.h:59
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
Definition build.h:167
#define RCSID(id)
Definition build.h:483
#define CMP_RETURN(_a, _b, _field)
Return if the comparison is not 0 (is unequal)
Definition build.h:121
#define unlikely(_x)
Definition build.h:381
#define UNUSED
Definition build.h:315
static int invalid_type(fr_type_t type)
Definition calc.c:698
bool check_config
Definition cf_file.c:67
int cf_section_parse(TALLOC_CTX *ctx, void *base, CONF_SECTION *cs)
Parse a configuration section into user-supplied variables.
Definition cf_parse.c:1151
int cf_null_on_read(UNUSED TALLOC_CTX *ctx, UNUSED void *out, UNUSED void *parent, UNUSED CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
NULL callback for sections.
Definition cf_parse.c:1691
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:658
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:612
void const * uctx
User data accessible by the cf_parse_t func.
Definition cf_parse.h:618
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:284
char const * name2
Second identifier for CONF_SECTION.
Definition cf_parse.h:597
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
Definition cf_parse.h:339
cf_parse_t on_read
Function to call as the item is being read, just after it has been allocated and initialized.
Definition cf_parse.h:615
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition cf_parse.h:434
@ CONF_FLAG_MULTI
CONF_PAIR can have multiple copies.
Definition cf_parse.h:448
@ CONF_FLAG_OK_MISSING
OK if it's missing.
Definition cf_parse.h:456
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:428
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:241
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:595
Internal data that is associated with a configuration section.
Definition cf_priv.h:124
Common header for all CONF_* types.
Definition cf_priv.h:49
Configuration AVP similar to a fr_pair_t.
Definition cf_priv.h:70
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
bool cf_item_is_pair(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_PAIR.
Definition cf_util.c:632
fr_token_t cf_pair_attr_quote(CONF_PAIR const *pair)
Return the value (lhs) quoting of a pair.
Definition cf_util.c:1623
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1185
void * cf_data_value(CONF_DATA const *cd)
Return the user assigned value of CONF_DATA.
Definition cf_util.c:1763
CONF_SECTION * cf_section_next(CONF_SECTION const *cs, CONF_SECTION const *curr)
Return the next child that's a CONF_SECTION.
Definition cf_util.c:997
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1171
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
Definition cf_util.c:1028
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:684
CONF_PAIR * cf_pair_find(CONF_SECTION const *cs, char const *attr)
Search for a CONF_PAIR with a specific name.
Definition cf_util.c:1439
fr_token_t cf_pair_operator(CONF_PAIR const *pair)
Return the operator of a pair.
Definition cf_util.c:1608
fr_token_t cf_pair_value_quote(CONF_PAIR const *pair)
Return the value (rhs) quoting of a pair.
Definition cf_util.c:1638
bool cf_item_is_section(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_SECTION.
Definition cf_util.c:618
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition cf_util.c:664
CONF_SECTION * cf_section_find_next(CONF_SECTION const *cs, CONF_SECTION const *prev, char const *name1, char const *name2)
Return the next matching section.
Definition cf_util.c:1049
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition cf_util.c:1594
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
Definition cf_util.c:1578
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:289
#define cf_data_add(_cf, _data, _name, _free)
Definition cf_util.h:255
#define cf_data_find(_cf, _type, _name)
Definition cf_util.h:244
#define cf_data_remove(_cf, _type, _name)
Remove an item from a parent by type and name.
Definition cf_util.h:267
#define cf_parent(_cf)
Definition cf_util.h:101
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:296
#define cf_section_find_parent(_cf, _name1, _name2)
Definition cf_util.h:175
#define cf_section_alloc(_ctx, _parent, _name1, _name2)
Definition cf_util.h:140
#define cf_data_find_in_parent(_cf, _type, _name)
Definition cf_util.h:250
#define cf_log_warn(_cf, _fmt,...)
Definition cf_util.h:290
#define cf_log_debug(_cf, _fmt,...)
Definition cf_util.h:292
#define cf_item_next(_ci, _curr)
Definition cf_util.h:92
#define CF_IDENT_ANY
Definition cf_util.h:78
fr_command_register_hook_t fr_command_register_hook
Definition command.c:42
char const * parent
e.g. "show module"
Definition command.h:52
#define CMD_TABLE_END
Definition command.h:62
int unlang_compile(virtual_server_t const *vs, CONF_SECTION *cs, unlang_mod_actions_t const *actions, tmpl_rules_t const *rules, void **instruction)
Compile an unlang section for a virtual server.
Definition compile.c:5038
#define fr_cond_assert_msg(_x, _fmt,...)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:156
#define MEM(x)
Definition debug.h:36
#define ERROR(fmt,...)
Definition dhcpclient.c:41
#define DEBUG(fmt,...)
Definition dhcpclient.c:39
int fr_dict_enum_add_name(fr_dict_attr_t *da, char const *name, fr_value_box_t const *value, bool coerce, bool replace)
Add a value name.
Definition dict_util.c:1945
int fr_dict_attr_add_name_only(fr_dict_t *dict, fr_dict_attr_t const *parent, char const *name, fr_type_t type, fr_dict_attr_flags_t const *flags))
Add an attribute to the dictionary.
Definition dict_util.c:1742
#define fr_dict_autofree(_to_free)
Definition dict.h:852
fr_dict_attr_t const * fr_dict_attr_by_name(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *attr))
Locate a fr_dict_attr_t by its name.
Definition dict_util.c:3267
fr_dict_attr_t * fr_dict_attr_unconst(fr_dict_attr_t const *da)
Coerce to non-const.
Definition dict_util.c:4601
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2404
unsigned int internal
Internal attribute, should not be received in protocol packets, should not be encoded.
Definition dict.h:87
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:268
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:281
fr_dict_enum_value_t * fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len)
Definition dict_util.c:3399
int fr_dict_enum_add_name_next(fr_dict_attr_t *da, char const *name)
Add an name to an integer attribute hashing the name for the integer value.
Definition dict_util.c:1957
int fr_dict_attr_autoload(fr_dict_attr_autoload_t const *to_load)
Process a dict_attr_autoload element to load/verify a dictionary attribute.
Definition dict_util.c:4094
#define fr_dict_autoload(_to_load)
Definition dict.h:849
fr_dict_t * fr_dict_protocol_alloc(fr_dict_t const *parent)
Allocate a new local dictionary.
Definition dict_util.c:3965
Specifies an attribute which must be present for the module to function.
Definition dict.h:267
Values of the encryption flags.
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:280
Value of an enumerated attribute.
Definition dict.h:227
Test enumeration values.
Definition dict_test.h:92
@ DL_MODULE_TYPE_PROTO
Protocol module.
Definition dl_module.h:67
@ DL_MODULE_TYPE_PROCESS
protocol processor.
Definition dl_module.h:68
#define unlang_function_push(_request, _func, _repeat, _signal, _sigmask, _top_frame, _uctx)
Push a generic function onto the unlang stack.
Definition function.h:111
int global_lib_instantiate(void)
Walk the tree of libraries and instantiate any which are pending.
Definition global_lib.c:218
int8_t fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b)
Compare two ip addresses.
Definition inet.c:1346
void fr_ipaddr_mask(fr_ipaddr_t *addr, uint8_t prefix)
Zeroes out the host portion of an fr_ipaddr_t.
Definition inet.c:217
IPv4/6 prefix.
int unlang_interpret_stack_depth(request_t *request)
Return the depth of the request's stack.
Definition interpret.c:1279
#define UNLANG_SUB_FRAME
Definition interpret.h:36
fr_socket_t * app_io_addr
for tracking duplicate sockets
Definition listen.h:35
fr_log_t * log_dst_by_name(char const *name)
Get a logging destination by name.
Definition log.c:1074
#define PERROR(_fmt,...)
Definition log.h:228
#define DEBUG3(_fmt,...)
Definition log.h:266
#define DEBUG_ENABLED4
True if global debug level 1-3 messages are enabled.
Definition log.h:260
#define DEBUG_ENABLED
True if global debug level 1 messages are enabled.
Definition log.h:257
talloc_free(reap)
Stores all information relating to an event list.
Definition event.c:411
int fr_debug_lvl
Definition log.c:43
@ L_DBG_LVL_DISABLE
Don't print messages.
Definition log.h:68
static char const * mod_name(fr_listen_t *li)
Definition master.c:2750
fr_type_t
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_VOID
User data.
@ FR_TYPE_GROUP
A grouping of other attributes.
long int ssize_t
unsigned char uint8_t
static const virtual_server_compile_t compile_list[]
Definition base.c:205
static const conf_parser_t config[]
Definition base.c:183
fr_dict_t const ** dict
pointer to local fr_dict_t *
Definition process.h:59
module_method_t process
Process packets.
Definition process.h:57
virtual_server_compile_t const * compile_list
list of processing sections
Definition process.h:58
Common public symbol definition for all process modules.
Definition process.h:54
#define fr_assert(_expr)
Definition rad_assert.h:38
#define DEBUG2(fmt,...)
Definition radclient.h:43
void * fr_rb_find(fr_rb_tree_t const *tree, void const *data)
Find an element in the tree, returning the data, not the node.
Definition rb.c:577
bool fr_rb_insert(fr_rb_tree_t *tree, void const *data)
Insert data into a tree.
Definition rb.c:626
#define fr_rb_alloc(_ctx, _data_cmp, _data_free)
Allocs a red black tree.
Definition rb.h:223
#define fr_rb_inline_alloc(_ctx, _type, _field, _data_cmp, _data_free)
Allocs a red black tree.
Definition rb.h:271
The main red black tree structure.
Definition rb.h:73
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
fr_dict_attr_t const * request_attr_request
Definition request.c:45
void request_log_prepend(request_t *request, fr_log_t *log_dst, fr_log_lvl_t lvl)
Prepend another logging destination to the list.
Definition request.c:100
static char const * name
The scheduler.
Definition schedule.c:125
int8_t section_name_cmp(void const *one, void const *two)
Compare two sections.
Definition section.c:48
char const * name2
Second section name. Usually a packet type like 'access-request', 'access-accept',...
Definition section.h:46
char const * name1
First section name. Usually a verb like 'recv', 'send', etc...
Definition section.h:45
Section name identifier.
Definition section.h:44
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:329
void * data
Module's instance data.
Definition module.h:271
module_t * exported
Public module structure.
Definition module.h:276
Module instance data.
Definition module.h:265
A list of modules.
Definition module.h:385
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition tmpl.h:350
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:347
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
@ FR_SIGNAL_CANCEL
Request has been cancelled.
Definition signal.h:40
static const uchar sc[16]
Definition smbdes.c:115
int module_instance_data_protect(module_instance_t const *mi)
Mark module data as read only.
Definition module.c:701
void module_list_debug(module_list_t const *ml)
Print the contents of a module list.
Definition module.c:623
module_instance_t * module_instance_alloc(module_list_t *ml, module_instance_t const *parent, dl_module_type_t type, char const *mod_name, char const *inst_name, module_instance_state_t init_state)
Allocate a new module and add it to a module list for later bootstrap/instantiation.
Definition module.c:1653
fr_slen_t module_instance_name_from_conf(char const **name, CONF_SECTION *conf)
Avoid boilerplate when setting the module instance name.
Definition module.c:737
void modules_thread_detach(module_list_t *ml)
Remove thread-specific data for a given module list.
Definition module.c:1011
int modules_thread_instantiate(TALLOC_CTX *ctx, module_list_t const *ml, fr_event_list_t *el)
Creates per-thread instance data for modules which need it.
Definition module.c:1162
module_instance_t * module_instance_by_data(module_list_t const *ml, void const *data)
Find an existing module instance by its private instance data.
Definition module.c:959
int modules_instantiate(module_list_t const *ml)
Completes instantiation of modules.
Definition module.c:1283
module_list_t * module_list_alloc(TALLOC_CTX *ctx, module_list_type_t const *type, char const *name, bool write_protect)
Allocate a new module list.
Definition module.c:1859
fr_slen_t module_instance_name_valid(char const *inst_name)
Check to see if a module instance name is valid.
Definition module.c:1593
int module_instance_data_unprotect(module_instance_t const *mi)
Mark module data as read/write.
Definition module.c:713
module_list_type_t const module_list_type_global
Callbacks for a global module list.
Definition module.c:536
int modules_bootstrap(module_list_t const *ml)
Bootstrap any modules which have not been bootstrapped already.
Definition module.c:1374
int module_submodule_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic callback for conf_parser_t to load a submodule.
Definition module.c:849
int module_instance_conf_parse(module_instance_t *mi, CONF_SECTION *conf)
Covert a CONF_SECTION into parsed module instance data.
Definition module.c:766
int unlang_module_push(rlm_rcode_t *p_result, request_t *request, module_instance_t *mi, module_method_t method, bool top_frame)
Push a module or submodule onto the stack for evaluation.
Definition module.c:53
fr_aka_sim_id_type_t type
Definition log.h:96
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Definition tmpl.h:287
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
Definition table.h:653
@ T_OP_CMP_TRUE
Definition token.h:104
@ T_BARE_WORD
Definition token.h:120
@ T_OP_EQ
Definition token.h:83
static fr_event_list_t * el
Generic representation of a grouping.
static fr_slen_t parent
Definition pair.h:851
int af
AF_INET, AF_INET6, or AF_UNIX.
Definition socket.h:78
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:554
void fr_strerror_clear(void)
Clears all pending messages from the talloc pools.
Definition strerror.c:577
#define fr_strerror_const(_msg)
Definition strerror.h:223
fr_table_num_ordered_t const fr_type_table[]
Map data types to names representing those types.
Definition types.c:31
#define fr_type_is_structural(_x)
Definition types.h:371
#define fr_type_is_leaf(_x)
Definition types.h:372
ssize_t fr_value_box_from_str(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_type_t dst_type, fr_dict_attr_t const *dst_enumv, char const *in, size_t inlen, fr_sbuff_unescape_rules_t const *erules, bool tainted)
Definition value.c:5361
void fr_value_box_clear(fr_value_box_t *data)
Clear/free any existing value and metadata.
Definition value.c:3723
static fr_slen_t data
Definition value.h:1265
#define fr_value_box_init_null(_vb)
Initialise an empty/null box that will be filled later.
Definition value.h:593
static size_t char ** out
Definition value.h:997
fr_dict_autoload_t virtual_server_dict_autoload[]
static const conf_parser_t server_on_read_config[]
bool listen_record(fr_listen_t *li)
Record that we're listening on a particular IP / port.
int virtual_server_section_register(virtual_server_t *vs, virtual_server_compile_t const *entry)
Register name1 / name2 as allowed processing sections.
fr_process_module_t const * process_module
Public interface to the process_mi.
int virtual_servers_bootstrap(CONF_SECTION *config)
Load protocol modules and call their bootstrap methods.
module_instance_t * process_mi
The process_* module for a virtual server.
const conf_parser_t virtual_servers_on_read_config[]
fr_dict_t const * virtual_server_dict_by_name(char const *virtual_server)
Return the namespace for the named virtual server.
static int server_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
CONF_SECTION * server_cs
The server section.
module_instance_t * virtual_server_listener_by_data(void const *data)
Resolve proto data to a module instance.
fr_rb_tree_t * sections
List of sections that need to be compiled.
static int namespace_on_read(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
section_name_t const ** virtual_server_section_methods(virtual_server_t const *vs, section_name_t const *section)
Find the component for a section.
fr_dict_attr_autoload_t virtual_server_dict_attr_autoload[]
int virtual_servers_open(fr_schedule_t *sc)
Open all the listen sockets.
int virtual_server_cf_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
Wrapper for the config parser to allow pass1 resolution of virtual servers.
static module_list_t * process_modules
List of process modules we've loaded.
int virtual_server_has_namespace(CONF_SECTION **out, char const *virtual_server, fr_dict_t const *namespace, CONF_ITEM *ci)
Verify that a given virtual_server exists and is of a particular namespace.
static fr_dict_t const * dict_freeradius
int virtual_server_listen_transport_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic conf_parser_t func for loading drivers.
const conf_parser_t virtual_servers_config[]
static CONF_SECTION * virtual_server_root
CONF_SECTION holding all the virtual servers.
static const conf_parser_t server_config[]
virtual_server_t const * virtual_server_find(char const *name)
Return virtual server matching the specified name.
static fr_dict_t const * virtual_server_local_dict(CONF_SECTION *server_cs, fr_dict_t const *dict_def)
fr_dict_t const * virtual_server_dict_by_child_ci(CONF_ITEM const *ci)
Return the namespace for a given virtual server specified by a CONF_ITEM within the virtual server.
fr_virtual_listen_t ** listeners
Listeners in this virtual server.
static int8_t virtual_server_compile_name_cmp(void const *a, void const *b)
fr_listen_t * listen_find_any(fr_listen_t *li)
See if another global listener is using a particular IP / port.
static virtual_server_t ** virtual_servers
Top level structure holding all virtual servers.
static fr_dict_attr_t const * attr_auth_type
int virtual_server_section_attribute_define(CONF_SECTION *server_cs, char const *subcs_name, fr_dict_attr_t const *da)
Define a values for Auth-Type attributes by the sections present in a virtual-server.
unlang_action_t virtual_server_push(request_t *request, CONF_SECTION *server_cs, bool top_frame)
Set the request processing function.
void virtual_servers_thread_detach(void)
Free thread-specific data for all process modules and listeners.
static fr_cmd_table_t cmd_table[]
void virtual_server_process_debug(void)
Print all the loaded process module instances.
CONF_SECTION * virtual_server_cs(virtual_server_t const *vs)
Return the configuration section for a virtual server.
fr_dict_t const * virtual_server_dict_by_cs(CONF_SECTION const *server_cs)
Return the namespace for the virtual server specified by a config section.
int virtual_servers_init(void)
Performs global initialisation for the virtual server code.
static fr_rb_tree_t * listen_addr_root
void virtual_server_listen_debug(void)
Print all the loaded listener instances.
fr_log_t * log
log destination
static int define_server_attrs(CONF_SECTION *cs, fr_dict_t *dict, fr_dict_attr_t *parent, fr_dict_attr_t const *root)
static int8_t listen_addr_cmp(void const *one, void const *two)
Compare listeners by app_io_addr.
int virtual_server_compile_sections(virtual_server_t const *vs, tmpl_rules_t const *rules)
Compile sections for a virtual server.
static module_list_t * proto_modules
List of proto modules we've loaded.
static int _virtual_servers_atexit(UNUSED void *uctx)
static int listen_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
int virtual_servers_instantiate(void)
Instantiate all the virtual servers.
static void server_signal_remove_log_destination(request_t *request, UNUSED fr_signal_t action, void *uctx)
virtual_server_t const * virtual_server_by_child(CONF_ITEM const *ci)
Find a virtual server using one of its sections.
int virtual_servers_free(void)
static int namespace_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static int add_compile_list(virtual_server_t *vs, CONF_SECTION *cs, virtual_server_compile_t const *compile_list, char const *name)
static unlang_action_t server_remove_log_destination(UNUSED rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx)
module_instance_t * proto_mi
The proto_* module for a listen section.
int virtual_servers_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el)
Perform thread instantiation for all process modules and listeners.
static int cmd_show_server_list(FILE *fp, UNUSED FILE *fp_err, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info)
static int define_server_values(CONF_SECTION *cs, fr_dict_attr_t *parent)
fr_app_t const * proto_module
Public interface to the proto_mi.
char const * log_name
name of log destination
struct virtual_server_s virtual_server_t
section_name_t const * section
Identifier for the section.
size_t offset
where the CONF_SECTION pointer is written
section_name_t const ** methods
list of auxilliary module methods which are allowed in if the main name doesn't match.
Processing sections which are allowed in this virtual server.