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: 1b7c3405ddd65fa4ad95e6c8fafb51dcd3747911 $
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: 1b7c3405ddd65fa4ad95e6c8fafb51dcd3747911 $")
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(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 *cp;
389 char const *protocol, *transport, *name2;
390 char *inst_name;
391
393
395 "virtual_servers_init MUST be called before reading virtual server config");
396
397 if (!namespace) {
398 cf_log_err(server_cs, "No 'namespace' set for virtual server");
399 cf_log_err(server_cs, "Please add 'namespace = <protocol>' inside of the 'server %s { ... }' section",
400 cf_section_name2(server_cs));
401 return -1;
402 }
403
404 /*
405 * Module name comes from the 'proto' pair if the
406 * listen section has one else it comes from the
407 * namespace of the virtual server.
408 *
409 * The following results in proto_radius being loaded:
410 *
411 * server foo {
412 * namespace = radius
413 * listen {
414 *
415 * }
416 * }
417 *
418 * The following results in proto_load being loaded:
419 *
420 * server foo {
421 * namespace = radius
422 * listen {
423 * proto = load
424 *
425 * }
426 * }
427 *
428 * In this way the server behaves reasonably out
429 * of the box, but allows foreign or generic listeners
430 * to be included in the server.
431 *
432 */
433 cp = cf_pair_find(listener_cs, "proto");
434 if (cp) {
435 protocol = cf_pair_value(cp);
436 if (!protocol) {
437 cf_log_err(cp, "Missing value");
438 return -1;
439 }
440 } else {
441 protocol = cf_pair_value(namespace);
442 }
443
444 name2 = cf_section_name2(listener_cs);
445
446 /*
447 * As with almost everything else, the listeners are
448 * modules. Create a unique name for them.
449 */
450 cp = cf_pair_find(listener_cs, "transport");
451 if (cp && cf_pair_value(cp)) {
452 transport = cf_pair_value(cp);
453 } else {
454 transport = "generic";
455 }
456
457 /*
458 * Instance names are default.radius.udp.foo, or default.radius.udp
459 */
460 if (name2) {
461 MEM(inst_name = talloc_asprintf(ctx, "%s.%s.%s.%s", cf_section_name2(server_cs),
462 protocol, transport, name2));
463 } else {
464 MEM(inst_name = talloc_asprintf(ctx, "%s.%s.%s", cf_section_name2(server_cs),
465 protocol, transport));
466 }
467
468 if (module_instance_name_valid(inst_name) < 0) {
469 error:
470 cf_log_err(listener_cs, "Failed loading listen section.");
471 return -1;
472 }
473 mi = module_instance_alloc(proto_modules, NULL, DL_MODULE_TYPE_PROTO, protocol, inst_name, 0);
474 talloc_free(inst_name);
475 if (!mi) goto error;
476
477 if (unlikely(module_instance_conf_parse(mi, listener_cs) < 0)) goto error;
478
479 listener->proto_mi = mi;
480 listener->proto_module = (fr_app_t const *)listener->proto_mi->module->exported;
481 cf_data_add(listener_cs, mi, "proto_module", false);
482
483 return 0;
484}
485
486static int8_t virtual_server_compile_name_cmp(void const *a, void const *b)
487{
488 virtual_server_compile_t const *sa = a;
489 virtual_server_compile_t const *sb = b;
490
491 return section_name_cmp(sa->section, sb->section);
492}
493
494/** Callback to validate the server section
495 *
496 * @param[in] ctx to allocate data in.
497 * @param[out] out Where to our listen configuration. Is a #virtual_server_t structure.
498 * @param[in] parent Base structure address.
499 * @param[in] ci #CONF_SECTION containing the listen section.
500 * @param[in] rule unused.
501 * @return
502 * - 0 on success.
503 * - -1 on failure.
504 */
505static int server_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
506 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
507{
508 virtual_server_t *server = talloc_get_type_abort(out, virtual_server_t);
509 CONF_SECTION *server_cs = cf_item_to_section(ci);
510 CONF_PAIR *namespace;
511
512 namespace = cf_pair_find(server_cs, "namespace");
513 if (!namespace) {
514 cf_log_err(server_cs, "virtual server %s MUST contain a 'namespace' option",
515 cf_section_name2(server_cs));
516 return -1;
517 }
518
520 server->server_cs = server_cs;
521
522 /*
523 * Now parse the listeners
524 */
525 if (cf_section_parse(out, server, server_cs) < 0) return -1;
526
527 /*
528 * And cache this struct for later referencing.
529 */
530 cf_data_add(server_cs, server, NULL, false);
531
532 return 0;
533}
534
535/** Return the namespace for the named virtual server
536 *
537 * @param[in] virtual_server to look for namespace in.
538 * @return
539 * - NULL on error.
540 * - Namespace on success.
541 */
542fr_dict_t const *virtual_server_dict_by_name(char const *virtual_server)
543{
544 virtual_server_t const *vs;
545
546 vs = virtual_server_find(virtual_server);
547 if (!vs) return NULL;
548
550}
551
552/** Return the namespace for the virtual server specified by a config section
553 *
554 * @param[in] server_cs to look for namespace in.
555 * @return
556 * - NULL on error.
557 * - Namespace on success.
558 */
560{
561 CONF_DATA const *cd;
562 fr_dict_t *dict;
563
564 cd = cf_data_find(server_cs, fr_dict_t, "dict");
565 if (!cd) return NULL;
566
567 dict = cf_data_value(cd);
568 (void) talloc_get_type_abort(dict, fr_dict_t);
569
570 return dict;
571}
572
573/** Return the namespace for a given virtual server specified by a CONF_ITEM within the virtual server
574 *
575 * @param[in] ci to look for namespace in.
576 * @return
577 * - NULL on error.
578 * - Namespace on success.
579 */
581{
582 CONF_DATA const *cd;
583 fr_dict_t *dict;
584
585 cd = cf_data_find_in_parent(ci, fr_dict_t, "dict");
586 if (!cd) return NULL;
587
588 dict = cf_data_value(cd);
589 (void) talloc_get_type_abort(dict, fr_dict_t);
590
591 return dict;
592}
593
594/** Verify that a given virtual_server exists and is of a particular namespace
595 *
596 * Mostly used by modules to check virtual servers specified by their configs.
597 *
598 * @param[out] out we found. May be NULL if just checking for existence.
599 * @param[in] virtual_server to check.
600 * @param[in] namespace the virtual server must belong to.
601 * @param[in] ci to log errors against. May be NULL if caller
602 * doesn't want errors logged.
603 * @return
604 * - 0 on success.
605 * - -1 if no virtual server could be found.
606 * - -2 if virtual server is not of the correct namespace.
607 */
609 char const *virtual_server, fr_dict_t const *namespace, CONF_ITEM *ci)
610{
611 virtual_server_t const *vs;
612 CONF_SECTION *server_cs;
613 fr_dict_t const *dict;
614
615 if (out) *out = NULL;
616
617 vs = virtual_server_find(virtual_server);
618 if (!vs) {
619 if (ci) cf_log_err(ci, "Can't find virtual server \"%s\"", virtual_server);
620 return -1;
621 }
622 server_cs = virtual_server_cs(vs);
623
624 dict = virtual_server_dict_by_name(virtual_server);
625 if (!dict) {
626 /*
627 * Not sure this is even a valid state?
628 */
629 if (ci) cf_log_err(ci, "No namespace found in virtual server \"%s\"", virtual_server);
630 return -2;
631 }
632
633 if (dict != namespace) {
634 if (ci) {
635 cf_log_err(ci,
636 "Expected virtual server \"%s\" to be of namespace \"%s\", got namespace \"%s\"",
637 virtual_server, fr_dict_root(namespace)->name, fr_dict_root(dict)->name);
638 }
639 return -2;
640 }
641
642 if (out) *out = server_cs;
643
644 return 0;
645}
646
647/*
648 * If we pushed a log destination, we need to pop it/
649 */
651 request_t *request, void *uctx)
652{
653 virtual_server_t *server = uctx;
654
655 request_log_prepend(request, server->log, L_DBG_LVL_DISABLE);
656
658}
659
660static void server_signal_remove_log_destination(request_t *request, UNUSED fr_signal_t action, void *uctx)
661{
662 virtual_server_t *server = uctx;
663
664 request_log_prepend(request, server->log, L_DBG_LVL_DISABLE);
665}
666
667/** Set the request processing function.
668 *
669 * Short-term hack
670 */
671unlang_action_t virtual_server_push(request_t *request, CONF_SECTION *server_cs, bool top_frame)
672{
673 virtual_server_t *server;
674
675 server = cf_data_value(cf_data_find(server_cs, virtual_server_t, NULL));
676 if (!server) {
677 cf_log_err(server_cs, "server_cs does not contain virtual server data");
678 return UNLANG_ACTION_FAIL;
679 }
680
681 /*
682 * Add a log destination specific to this virtual server.
683 *
684 * If we add a log destination, make sure to remove it when we walk back up the stack.
685 * But ONLY if we're not at the top of the stack.
686 *
687 * When a brand new request comes in, it has a "call" frame pushed, and then this function is
688 * called. So if we're at the top of the stack, we don't need to pop any logging function,
689 * because the request will die immediately after the top "call" frame is popped.
690 *
691 * However, if we're being reached from a "call" frame in the middle of the stack, then
692 * we do have to pop the log destination when we return.
693 */
694 if (server->log) {
695 request_log_prepend(request, server->log, fr_debug_lvl);
696
697 if (unlang_interpret_stack_depth(request) > 1) {
698 unlang_action_t action;
699
700 action = unlang_function_push(request, NULL, /* don't call it immediately */
701 server_remove_log_destination, /* but when we pop the frame */
703 top_frame, server);
704 if (action != UNLANG_ACTION_PUSHED_CHILD) return action;
705
706 /*
707 * The pushed function may be a top frame, but the virtual server
708 * we're about to push is now definitely a sub frame.
709 */
710 top_frame = UNLANG_SUB_FRAME;
711 }
712 }
713
714 /*
715 * Bootstrap the stack with a module instance.
716 */
717 if (unlang_module_push(&request->rcode, request, server->process_mi,
718 server->process_module->process, top_frame) < 0) return UNLANG_ACTION_FAIL;
719
721}
722
723static int cmd_show_server_list(FILE *fp, UNUSED FILE *fp_err, UNUSED void *ctx, UNUSED fr_cmd_info_t const *info)
724{
725 size_t i, server_cnt = virtual_servers ? talloc_array_length(virtual_servers) : 0;
726
727 if (!server_cnt) return 0;
728
729 for (i = 0; i < server_cnt; i++) {
730 fprintf(fp, "%-30snamespace = %s\n", cf_section_name2(virtual_servers[i]->server_cs),
731 fr_dict_root(*(virtual_servers[i]->process_module->dict))->name);
732 }
733
734 return 0;
735}
736
738 {
739 .parent = "show",
740 .name = "server",
741 .help = "Show virtual server settings.",
742 .read_only = true,
743 },
744
745 {
746 .parent = "show server",
747 .name = "list",
748 .func = cmd_show_server_list,
749 .help = "Show the list of virtual servers loaded in the server.",
750 .read_only = true,
751 },
752
754
755};
756
757/** Compare listeners by app_io_addr
758 *
759 * Only works for IP addresses, and will blow up on file names
760 */
761static int8_t listen_addr_cmp(void const *one, void const *two)
762{
763 fr_listen_t const *a = one;
764 fr_listen_t const *b = two;
765 fr_ipaddr_t aip, bip;
766 int ret;
767
768 /*
769 * The caller must ensure that the address field is set.
770 */
771 if (!a->app_io_addr && !b->app_io_addr) return 0;
772 if (!a->app_io_addr && b->app_io_addr) return -1;
773 if (a->app_io_addr && !b->app_io_addr) return +1;
774
775 /*
776 * Address family
777 */
778 CMP_RETURN(a, b, app_io_addr->af);
779
780 fr_assert((a->app_io_addr->af == AF_INET) || ((a->app_io_addr->af == AF_INET6)));
781
782 /*
783 * UDP vs TCP
784 */
785 CMP_RETURN(a, b, app_io_addr->type);
786
787 /*
788 * Check ports.
789 */
790 CMP_RETURN(a, b, app_io_addr->inet.src_port);
791
792 /*
793 * Don't call fr_ipaddr_cmp(), as we need to do our own
794 * checks here. We have various wildcard checks which
795 * aren't globally applicable.
796 */
797
798 /*
799 * Different address families.
800 */
801 CMP_RETURN(a, b, app_io_addr->inet.src_ipaddr.af);
802
803 /*
804 * If both are bound to interfaces, AND the interfaces
805 * are different, then there is no conflict.
806 */
807 if (a->app_io_addr->inet.src_ipaddr.scope_id && b->app_io_addr->inet.src_ipaddr.scope_id) {
808 CMP_RETURN(a, b, app_io_addr->inet.src_ipaddr.scope_id);
809 }
810
811 ret = a->app_io_addr->inet.src_ipaddr.prefix - b->app_io_addr->inet.src_ipaddr.prefix;
812 aip = a->app_io_addr->inet.src_ipaddr;
813 bip = b->app_io_addr->inet.src_ipaddr;
814
815 /*
816 * Mask out the longer prefix to match the shorter
817 * prefix.
818 */
819 if (ret < 0) {
820 fr_ipaddr_mask(&bip, a->app_io_addr->inet.src_ipaddr.prefix);
821
822 } else if (ret > 0) {
823 fr_ipaddr_mask(&aip, b->app_io_addr->inet.src_ipaddr.prefix);
824
825 }
826
827 return fr_ipaddr_cmp(&aip, &bip);
828}
829
830/** See if another global listener is using a particular IP / port
831 *
832 */
834{
835 if (!listen_addr_root) return false;
836
837 return fr_rb_find(listen_addr_root, li);
838}
839
840
841/** Record that we're listening on a particular IP / port
842 *
843 */
845{
846 if (!listen_addr_root) return false;
847
848 if (!li->app_io_addr) return true;
849
850 if (listen_find_any(li) != NULL) return false;
851
852 return fr_rb_insert(listen_addr_root, li);
853}
854
855/** Return the configuration section for a virtual server
856 *
857 * @param[in] vs to return conf section for
858 * @return
859 * - The CONF_SECTION of the virtual server.
860 */
862{
863 return vs->server_cs;
864}
865
866/** Return virtual server matching the specified name
867 *
868 * @note May be called in bootstrap or instantiate as all servers should be present.
869 *
870 * @param[in] name of virtual server.
871 * @return
872 * - NULL if no virtual server was found.
873 * - The CONF_SECTION of the named virtual server.
874 */
876{
877 CONF_SECTION *server_cs = cf_section_find(virtual_server_root, "server", name);
878 CONF_DATA const *cd;
879
880 if (unlikely(server_cs == NULL)) return NULL;
881
882 cd = cf_data_find(server_cs, virtual_server_t, NULL);
883 if (unlikely(cd == NULL)) return NULL;
884
885 return cf_data_value(cd);
886}
887
888/** Find a virtual server using one of its sections
889 *
890 * @param[in] ci to find parent virtual server for.
891 * @return
892 * - The virtual server section on success.
893 * - NULL if the child isn't associated with any virtual server section.
894 */
896{
897 CONF_SECTION *cs;
898 CONF_DATA const *cd;
899
900 cs = cf_section_find_parent(ci, "server", CF_IDENT_ANY);
901 if (unlikely(!cs)) {
902 cf_log_err(ci, "Child section is not associated with a virtual server");
903 return NULL;
904 }
905
906 cd = cf_data_find(cs, virtual_server_t, NULL);
907 if (unlikely(!cd)) {
908 cf_log_err(ci, "Virtual server section missing virtual_server_t data");
909 return NULL;
910 }
911
912 return cf_data_value(cd);
913}
914
915/** Wrapper for the config parser to allow pass1 resolution of virtual servers
916 *
917 */
918int virtual_server_cf_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent,
919 CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
920{
921 virtual_server_t const *vs;
922
924 if (!vs) {
925 cf_log_err(ci, "virtual-server \"%s\" not found", cf_pair_value(cf_item_to_pair(ci)));
926 return -1;
927 }
928
929 *((CONF_SECTION **)out) = vs->server_cs;
930
931 return 0;
932}
933
934/** Compile sections for a virtual server.
935 *
936 * When the "proto_foo" module calls fr_app_process_instantiate(), it
937 * loads the compile list from the #fr_app_worker_t, and calls this
938 * function.
939 *
940 * This function walks down the registration table, compiling each
941 * named section.
942 *
943 * @param[in] vs to to compile sections for.
944 * @param[in] rules to apply for pass1.
945 */
947{
949 void *instance = vs->process_mi->data;
950 CONF_SECTION *server = vs->server_cs;
951 int i, found;
952 CONF_SECTION *subcs = NULL;
953
954 found = 0;
955
956 /*
957 * Complain about v3 things being used in v4.
958 *
959 * Don't complain when running in normal mode, because the server will just ignore the new
960 * sections. But the check_config stuff is generally run before the service starts, and we
961 * definitely want to tell people when running in debug mode.
962 */
964 bool fail = false;
965
966 while ((subcs = cf_section_next(server, subcs)) != NULL) {
967 char const *name;
968
969 if (cf_section_name2(subcs) != NULL) continue;
970
971 name = cf_section_name1(subcs);
972 if ((strcmp(name, "authorize") == 0) ||
973 (strcmp(name, "authenticate") == 0) ||
974 (strcmp(name, "post-auth") == 0) ||
975 (strcmp(name, "preacct") == 0) ||
976 (strcmp(name, "accounting") == 0) ||
977 (strcmp(name, "pre-proxy") == 0) ||
978 (strcmp(name, "post-proxy") == 0)) {
979 cf_log_err(subcs, "Version 3 processing section '%s' is not valid in version 4.",
980 name);
981 fail = true;
982 }
983 }
984
985 /*
986 * Complain about _all_ of the sections, and not just the first one.
987 */
988 if (fail) return -1;
989 }
990
991 /*
992 * The sections are in trees, so this isn't as bad as it
993 * looks. It's not O(n^2), but O(n logn). But it could
994 * still be improved.
995 */
996 for (i = 0; list[i].section; i++) {
997 int rcode;
998 CONF_SECTION *bad;
999
1000 /*
1001 * We are looking for a specific subsection.
1002 * Warn if it isn't found, or compile it if
1003 * found.
1004 */
1005 if (list[i].section->name2 != CF_IDENT_ANY) {
1006 void *instruction = NULL;
1007
1008 subcs = cf_section_find(server, list[i].section->name1, list[i].section->name2);
1009 if (!subcs) {
1010 DEBUG3("Warning: Skipping %s %s { ... } as it was not found.",
1011 list[i].section->name1, list[i].section->name2);
1012 /*
1013 * Initialise CONF_SECTION pointer for missing section
1014 */
1015 if ((instance) && !list[i].dont_cache) {
1016 *(CONF_SECTION **) (((uint8_t *) instance) + list[i].offset) = NULL;
1017 }
1018 continue;
1019 }
1020
1021 /*
1022 * Duplicate sections are forbidden.
1023 */
1024 bad = cf_section_find_next(server, subcs, list[i].section->name1, list[i].section->name2);
1025 if (bad) {
1026 forbidden:
1027 cf_log_err(bad, "Duplicate sections are forbidden.");
1028 cf_log_err(subcs, "Previous definition occurs here.");
1029 return -1;
1030 }
1031
1032 rcode = unlang_compile(vs, subcs, list[i].actions, rules, &instruction);
1033 if (rcode < 0) return -1;
1034
1035 /*
1036 * Cache the CONF_SECTION which was found.
1037 */
1038 if (instance) {
1039 if (!list[i].dont_cache) {
1040 *(CONF_SECTION **) (((uint8_t *) instance) + list[i].offset) = subcs;
1041 }
1042 if (list[i].instruction > 0) {
1043 *(void **) (((uint8_t *) instance) + list[i].instruction) = instruction;
1044 }
1045 }
1046
1047 found++;
1048 continue;
1049 }
1050
1051 /*
1052 * Reset this so that we start from the beginning
1053 * again, instead of starting from the last "send
1054 * foo" block.
1055 */
1056 subcs = NULL;
1057
1058 /*
1059 * Find all subsections with the given first name
1060 * and compile them.
1061 */
1062 while ((subcs = cf_section_find_next(server, subcs, list[i].section->name1, CF_IDENT_ANY))) {
1063 char const *name2;
1064
1065 name2 = cf_section_name2(subcs);
1066 if (!name2) {
1067 cf_log_err(subcs, "Invalid '%s { ... }' section, it must have a name", list[i].section->name1);
1068 return -1;
1069 }
1070
1071 /*
1072 * Duplicate sections are forbidden.
1073 */
1074 bad = cf_section_find_next(server, subcs, list[i].section->name1, name2);
1075 if (bad) goto forbidden;
1076
1077 rcode = unlang_compile(vs, subcs, list[i].actions, rules, NULL);
1078 if (rcode < 0) return -1;
1079
1080 /*
1081 * Note that we don't store the
1082 * CONF_SECTION here, as it's a wildcard.
1083 *
1084 * @todo - count number of subsections
1085 * and store them in an array?
1086 */
1087 found++;
1088 }
1089 }
1090
1091 return found;
1092}
1093
1094/** Register name1 / name2 as allowed processing sections
1095 *
1096 * This function is called from the virtual server bootstrap routine,
1097 * which happens before module_bootstrap();
1098 */
1100{
1102
1103 old = fr_rb_find(vs->sections, entry);
1104 if (old) return 0;
1105
1106#ifndef NDEBUG
1107 /*
1108 * Catch stupid programmers.
1109 *
1110 * Processing sections can't allow "*" for module
1111 * methods, because otherwise you would be allowed to run
1112 * DHCP things in a RADIUS accounting section. And that
1113 * would be bad.
1114 */
1115 if (entry->methods) {
1116 int i;
1117
1118 for (i = 0; entry->methods[i]; i++) {
1119 if (entry->methods[i]->name1 == CF_IDENT_ANY) {
1120 ERROR("Processing sections cannot allow \"*\"");
1121 return -1;
1122 }
1123
1124 if (entry->methods[i]->name2 == CF_IDENT_ANY) {
1125 ERROR("Processing sections cannot allow \"%s *\"",
1126 entry->methods[i]->name1);
1127 return -1;
1128 }
1129 }
1130 }
1131#endif
1132
1133 if (!fr_rb_insert(vs->sections, entry)) {
1134 fr_strerror_const("Failed inserting entry into internal tree");
1135 return -1;
1136 }
1137
1138 return 0;
1139}
1140
1141/** Find the component for a section
1142 *
1143 */
1145{
1147
1148 /*
1149 * Look up the specific name first. That way we can
1150 * define both "accounting on", and "accounting *".
1151 */
1152 if (section->name2 != CF_IDENT_ANY) {
1153 entry = fr_rb_find(vs->sections,
1155 .section = section
1156 });
1157 if (entry) return entry->methods;
1158 }
1159
1160 /*
1161 * Then look up the wildcard, if we didn't find any matching name2.
1162 */
1163 entry = fr_rb_find(vs->sections,
1165 .section = SECTION_NAME(section->name1, CF_IDENT_ANY)
1166 });
1167 if (!entry) return NULL;
1168
1169 return entry->methods;
1170}
1171
1172/** Define a values for Auth-Type attributes by the sections present in a virtual-server
1173 *
1174 * The.name2 value of any sections found will be converted into values of the specified da.
1175 *
1176 * @param[in] server_cs The virtual server containing the sections.
1177 * @param[in] subcs_name of the subsection to search for.
1178 * @param[in] da to add enumeration values for.
1179 * @return
1180 * - 0 all values added successfully.
1181 * - -1 an error occurred.
1182 */
1183int virtual_server_section_attribute_define(CONF_SECTION *server_cs, char const *subcs_name, fr_dict_attr_t const *da)
1184{
1185 int rcode = 0;
1186 CONF_SECTION *subcs = NULL;
1187
1188 fr_assert(strcmp(cf_section_name1(server_cs), "server") == 0);
1189
1190 while ((subcs = cf_section_find_next(server_cs, subcs, subcs_name, CF_IDENT_ANY))) {
1191 char const *name2;
1193
1194 name2 = cf_section_name2(subcs);
1195 if (!name2) {
1196 cf_log_err(subcs, "Invalid '%s { ... }' section, it must have a name", subcs_name);
1197 return -1;
1198 }
1199
1200 /*
1201 * If the value already exists, don't
1202 * create it again.
1203 */
1204 dv = fr_dict_enum_by_name(da, name2, -1);
1205 if (dv) continue;
1206
1207 cf_log_debug(subcs, "Creating %s = %s", da->name, name2);
1208
1209 /*
1210 * Create a new unique value with a meaningless
1211 * number. You can't look at it from outside of
1212 * this code, so it doesn't matter. The only
1213 * requirement is that it's unique.
1214 */
1216 PERROR("Failed adding section value");
1217 return -1;
1218 }
1219
1220 rcode = 1;
1221 }
1222
1223 return rcode;
1224}
1225
1227{
1228 char const *ref;
1229 fr_dict_attr_t const *da;
1230 CONF_ITEM *ci = NULL;
1231
1232 ref = cf_section_name2(cs);
1233 if (!ref) {
1234 cf_log_err(cs, "Expected 'values <name> { ... }'");
1235 return -1;
1236 }
1237
1238 da = fr_dict_attr_by_name(NULL, parent, ref);
1239 if (!da) {
1240 cf_log_err(cs, "No such attribute \"%s\"", ref);
1241 return -1;
1242 }
1243
1244 if (fr_type_is_structural(da->type)) {
1245 cf_log_err(cs, "Cannot define value for structural attribute \"%s\"", ref);
1246 return -1;
1247 }
1248
1249 /*
1250 * This both does not make any sense, and does not get
1251 * parsed correctly if the string contains backslashes.
1252 */
1253 if (da->type == FR_TYPE_STRING) {
1254 cf_log_err(cs, "Cannot define value for 'string' attribute \"%s\"", ref);
1255 return -1;
1256 }
1257
1258 while ((ci = cf_item_next(cs, ci))) {
1259 ssize_t slen, len;
1260 char const *attr, *value;
1261 CONF_PAIR *cp;
1263 fr_value_box_t box;
1264
1265 if (cf_item_is_section(ci)) {
1266 cf_log_err(ci, "Unexpected subsection");
1267 return -1;
1268 }
1269
1270 if (!cf_item_is_pair(ci)) continue;
1271
1272 cp = cf_item_to_pair(ci);
1273 fr_assert(cp != NULL);
1274
1275 /*
1276 * =* is a hack by the cf parser to say "no operator"
1277 */
1278 if ((cf_pair_operator(cp) != T_OP_EQ) ||
1280 cf_log_err(ci, "Definition is not in 'name = value' format");
1281 return -1;
1282 }
1283
1284 attr = cf_pair_attr(cp);
1285 value = cf_pair_value(cp);
1286
1287 dv = fr_dict_enum_by_name(parent, attr, talloc_array_length(attr) - 1);
1288 if (dv) {
1289 cf_log_err(cp, "Duplicate value name");
1290 return -1;
1291 }
1292
1294
1295 len = talloc_array_length(value) - 1;
1296
1297 /*
1298 * @todo - unescape for double quoted strings. Whoops.
1299 */
1300 slen = fr_value_box_from_str(NULL, &box, da->type, da, value, len, NULL);
1301 if (slen < 0) {
1302 cf_log_err(cp, "Failed parsing value - %s", fr_strerror());
1303 return -1;
1304 }
1305
1306 if (slen != len) {
1307 cf_log_err(cp, "Unexpected text after value");
1308 return -1;
1309 }
1310
1311 if (fr_dict_enum_add_name(UNCONST(fr_dict_attr_t *, da), attr, &box, false, false) < 0) {
1312 cf_log_err(cp, "Failed adding value - %s", fr_strerror());
1313 return -1;
1314 }
1315
1316 fr_value_box_clear(&box);
1317 }
1318
1319 return 0;
1320}
1321
1322
1324{
1325 CONF_ITEM *ci = NULL;
1326
1327 fr_dict_attr_flags_t flags = {
1328 .internal = true,
1329 .name_only = true,
1330 .local = true,
1331 };
1332
1333 fr_assert(dict != NULL);
1334 fr_assert(parent != NULL);
1335
1336 while ((ci = cf_item_next(cs, ci))) {
1338 char const *attr, *value;
1339 CONF_PAIR *cp;
1340 CONF_SECTION *subcs = NULL;
1341
1342 if (cf_item_is_section(ci)) {
1343 subcs = cf_item_to_section(ci);
1344 fr_assert(subcs != NULL);
1345
1346 attr = cf_section_name1(subcs);
1347
1348 if (strcmp(attr, "values") == 0) {
1349 if (define_server_values(subcs, parent) < 0) return -1;
1350 continue;
1351 }
1352
1353 if (strcmp(attr, "tlv") != 0) goto invalid_type;
1354
1355 value = cf_section_name2(subcs);
1356 if (!value) {
1357 cf_log_err(ci, "Definition is not in 'tlv name { ... }' format");
1358 return -1;
1359 }
1360
1361 type = FR_TYPE_TLV;
1362 goto check_for_dup;
1363 }
1364
1365 if (!cf_item_is_pair(ci)) continue;
1366
1367 cp = cf_item_to_pair(ci);
1368 fr_assert(cp != NULL);
1369
1370 /*
1371 * =* is a hack by the cf parser to say "no operator"
1372 */
1373 if ((cf_pair_operator(cp) != T_OP_CMP_TRUE) ||
1376 cf_log_err(ci, "Definition is not in 'type name' format");
1377 return -1;
1378 }
1379
1380 attr = cf_pair_attr(cp);
1381 value = cf_pair_value(cp);
1382
1384 if (type == FR_TYPE_NULL) {
1386 cf_log_err(ci, "Invalid data type '%s'", attr);
1387 return -1;
1388 }
1389
1390 /*
1391 * Leaf and group are OK. TLV, Vendor, Struct, VSA, etc. are not as variable definitions.
1392 */
1393 if (!(fr_type_is_leaf(type) || (type == FR_TYPE_GROUP))) goto invalid_type;
1394
1395 /*
1396 * No duplicates are allowed.
1397 */
1398 check_for_dup:
1399 if (root && (fr_dict_attr_by_name(NULL, root, value) != NULL)) {
1400 cf_log_err(ci, "Local variable '%s' duplicates a dictionary attribute.", value);
1401 return -1;
1402 }
1403
1404 if (fr_dict_attr_by_name(NULL, parent, value) != NULL) {
1405 cf_log_err(ci, "Local variable '%s' duplicates a previous local attribute.", value);
1406 return -1;
1407 }
1408
1409 if (fr_dict_attr_add_name_only(dict, parent, value, type, &flags) < 0) {
1410 cf_log_err(ci, "Failed adding local variable '%s' - %s", value, fr_strerror());
1411 return -1;
1412 }
1413
1414 if (type == FR_TYPE_TLV) {
1415 fr_dict_attr_t const *da;
1416
1417 if (!subcs) return -1; /* shouldn't happen, but shut up compiler */
1418
1419 da = fr_dict_attr_by_name(NULL, parent, value);
1420 fr_assert(da != NULL);
1421
1422 if (define_server_attrs(subcs, dict, UNCONST(fr_dict_attr_t *, da), NULL) < 0) return -1;
1423 }
1424 }
1425
1426 return 0;
1427}
1428
1429static fr_dict_t const *virtual_server_local_dict(CONF_SECTION *server_cs, fr_dict_t const *dict_def)
1430{
1431 fr_dict_t *dict;
1432 CONF_SECTION *cs;
1433
1434 cs = cf_section_find(server_cs, "dictionary", NULL);
1435 if (!cs) return dict_def;
1436
1437 dict = fr_dict_protocol_alloc(dict_def);
1438 if (!dict) {
1439 cf_log_err(cs, "Failed allocating local dictionary");
1440 return NULL;
1441 }
1442
1443 if (define_server_attrs(cs, dict, UNCONST(fr_dict_attr_t *, fr_dict_root(dict)), fr_dict_root(dict_def)) < 0) return NULL;
1444
1445 /*
1446 * Replace the original dictionary with the new one.
1447 */
1448 cf_data_remove(server_cs, fr_dict_t, "dict");
1449 cf_data_add(server_cs, dict, "dict", false);
1450
1451 return dict;
1452}
1453
1454
1455/** Open all the listen sockets
1456 *
1457 * @param[in] sc Scheduler to add I/O paths to.
1458 * @return
1459 * - 0 on success.
1460 * - -1 on failure.
1461 */
1463{
1464 size_t i, server_cnt = virtual_servers ? talloc_array_length(virtual_servers) : 0;
1465
1467
1468 DEBUG2("#### Opening listener interfaces ####");
1470
1471 for (i = 0; i < server_cnt; i++) {
1472 fr_virtual_listen_t **listeners;
1473 size_t j, listener_cnt;
1474
1475 listeners = virtual_servers[i]->listeners;
1476 listener_cnt = talloc_array_length(listeners);
1477
1478 for (j = 0; j < listener_cnt; j++) {
1479 fr_virtual_listen_t *listener = listeners[j];
1480
1481 fr_assert(listener != NULL);
1482 fr_assert(listener->proto_mi != NULL);
1483 fr_assert(listener->proto_module != NULL);
1484
1485 /*
1486 * The socket is opened with app_instance,
1487 * but all subsequent calls (network.c, etc.) use app_io_instance.
1488 *
1489 * The reason is that we call (for example) proto_radius to
1490 * open the socket, and proto_radius is responsible for setting up
1491 * proto_radius_udp, and then calling proto_radius_udp->open.
1492 *
1493 * Even then, proto_radius usually calls fr_master_io_listen() in order
1494 * to create the fr_listen_t structure.
1495 */
1496 if (listener->proto_module->open) {
1497 int ret;
1498
1499 /*
1500 * Sometimes the open function needs to modify instance
1501 * data, so we need to temporarily remove the protection.
1502 */
1504 ret = listener->proto_module->open(listener->proto_mi->data, sc,
1505 listener->proto_mi->conf);
1507 if (unlikely(ret < 0)) {
1508 cf_log_err(listener->proto_mi->conf,
1509 "Opening %s I/O interface failed",
1510 listener->proto_module->common.name);
1511
1512 return -1;
1513 }
1514
1515 }
1516
1517 /*
1518 * Socket information is printed out by
1519 * the socket handlers. e.g. proto_radius_udp
1520 */
1521 DEBUG3("Opened listener for %s", listener->proto_module->common.name);
1522 }
1523 }
1524
1525 return 0;
1526}
1527
1528/** Free thread-specific data for all process modules and listeners
1529 *
1530 */
1536
1537/** Perform thread instantiation for all process modules and listeners
1538 *
1539 */
1541{
1542 if (modules_thread_instantiate(ctx, process_modules, el) < 0) return -1;
1545 return -1;
1546 }
1547 return 0;
1548}
1549
1550/** Instantiate all the virtual servers
1551 *
1552 * @return
1553 * - 0 on success.
1554 * - -1 on failure.
1555 */
1557{
1558 size_t i, server_cnt;
1559
1560 /*
1561 * User didn't specify any "server" sections
1562 */
1563 if (unlikely(!virtual_servers)) {
1564 ERROR("No virtual servers configured");
1565 return -1;
1566 }
1567
1568 server_cnt = talloc_array_length(virtual_servers);
1569
1570 DEBUG2("#### Instantiating listeners ####");
1571
1573 PERROR("Failed registering radmin commands for virtual servers");
1574 return -1;
1575 }
1576
1577 for (i = 0; i < server_cnt; i++) {
1578 CONF_ITEM *ci = NULL;
1579 CONF_SECTION *server_cs = virtual_servers[i]->server_cs;
1580 fr_dict_t const *dict;
1582 fr_process_module_t const *process = (fr_process_module_t const *)
1583 vs->process_mi->module->exported;
1584
1585 /*
1586 * Set up logging before doing anything else.
1587 */
1588 if (vs->log_name) {
1589 vs->log = log_dst_by_name(vs->log_name);
1590 if (!vs->log) {
1591 CONF_PAIR *cp = cf_pair_find(server_cs, "log");
1592
1593 if (cp) {
1594 cf_log_err(cp, "Unknown log destination '%s'", vs->log_name);
1595 } else {
1596 cf_log_err(server_cs, "Unknown log destination '%s'", vs->log_name);
1597 }
1598
1599 return -1;
1600 }
1601 }
1602
1603 dict = virtual_server_local_dict(server_cs, *(process)->dict);
1604 if (!dict) return -1;
1605
1606 DEBUG("Compiling policies in server %s { ... }", cf_section_name2(server_cs));
1607
1608 fr_assert(virtual_servers[i]->process_mi);
1609
1610 /*
1611 * Compile the processing sections indicated by
1612 * the process module. This must be done before
1613 * module_instantiate is called, as the instance
1614 * data is protected after this call.
1615 */
1616 if (process->compile_list) {
1617 tmpl_rules_t parse_rules = {
1618 .attr = {
1619 .dict_def = dict,
1620 .list_def = request_attr_request,
1621 },
1622
1623 .literals_safe_for = FR_VALUE_BOX_SAFE_FOR_ANY,
1624 };
1625
1626 fr_assert(parse_rules.attr.dict_def != NULL);
1627
1628 if (virtual_server_compile_sections(virtual_servers[i], &parse_rules) < 0) {
1629 return -1;
1630 }
1631 }
1632
1633 /*
1634 * Print out warnings for unused "recv" and
1635 * "send" sections.
1636 *
1637 * @todo - check against the "compile_list"
1638 * registered for this virtual server, instead of hard-coding stuff.
1639 */
1640 while ((ci = cf_item_next(server_cs, ci))) {
1641 char const *name;
1642 CONF_SECTION *subcs;
1643
1644 if (!cf_item_is_section(ci)) continue;
1645
1646 subcs = cf_item_to_section(ci);
1647 name = cf_section_name1(subcs);
1648
1649 /*
1650 * Skip known "other" sections
1651 */
1652 if ((strcmp(name, "listen") == 0) || (strcmp(name, "client") == 0)) continue;
1653
1654 /*
1655 * For every other section, warn if it hasn't
1656 * been compiled.
1657 */
1658 if (!cf_data_find(subcs, unlang_group_t, NULL)) {
1659 char const *name2;
1660
1661 name2 = cf_section_name2(subcs);
1662 if (!name2) name2 = "";
1663
1664 cf_log_warn(subcs, "%s %s { ... } section is unused", name, name2);
1665 }
1666 }
1667 }
1668
1670 PERROR("Failed instantiating process modules");
1671 return -1;
1672 }
1674 PERROR("Failed instantiating protocol modules");
1675 return -1;
1676 }
1677
1678 return 0;
1679}
1680
1681/** Load protocol modules and call their bootstrap methods
1682 *
1683 * @param[in] config section containing the virtual servers to bootstrap.
1684 * @return
1685 * - 0 on success.
1686 * - -1 on failure.
1687 */
1689{
1691
1692 /*
1693 * Ensure any libraries the modules depend on are instantiated
1694 */
1696
1698 PERROR("Failed instantiating process modules");
1699 return -1;
1700 }
1702 PERROR("Failed instantiating protocol modules");
1703 return -1;
1704 }
1705
1706 return 0;
1707}
1708
1710{
1711 if (talloc_free(listen_addr_root) < 0) return -1;
1712 listen_addr_root = NULL;
1713 if (talloc_free(process_modules) < 0) return -1;
1714 process_modules = NULL;
1715 if (talloc_free(proto_modules) < 0) return -1;
1716 proto_modules = NULL;
1718
1719 return 0;
1720}
1721
1722static int _virtual_servers_atexit(UNUSED void *uctx)
1723{
1724 return virtual_servers_free();
1725}
1726
1727/** Performs global initialisation for the virtual server code
1728 *
1729 * This has to be done separately and explicitly, because the above code makes
1730 * use of "onread" callbacks.
1731 *
1732 * Will automatically free module lists on exit, but all modules should have
1733 * been removed from this list by the point that happens.
1734 */
1736{
1738 PERROR("%s", __FUNCTION__);
1739 return -1;
1740 }
1742 PERROR("%s", __FUNCTION__);
1744 return -1;
1745 }
1746
1748
1749 /*
1750 * FIXME - We should be able to turn on write protection,
1751 * but there are too many proto modules that hang things
1752 * off of their instance data.
1753 */
1754 MEM(proto_modules = module_list_alloc(NULL, &module_list_type_global, "protocol", false));
1755 MEM(listen_addr_root = fr_rb_inline_alloc(NULL, fr_listen_t, virtual_server_node, listen_addr_cmp, NULL));
1756
1757 /*
1758 * Create a list to hold all the proto_* modules
1759 * that get loaded during startup.
1760 */
1762
1763 return 0;
1764}
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:485
#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:383
#define UNUSED
Definition build.h:317
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:1155
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:1708
#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:4976
#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:1948
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:1745
#define fr_dict_autofree(_to_free)
Definition dict.h:860
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:3270
fr_dict_attr_t * fr_dict_attr_unconst(fr_dict_attr_t const *da)
Coerce to non-const.
Definition dict_util.c:4604
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
Definition dict_util.c:2407
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:272
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:285
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:3402
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:1960
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:4097
#define fr_dict_autoload(_to_load)
Definition dict.h:857
fr_dict_t * fr_dict_protocol_alloc(fr_dict_t const *parent)
Allocate a new local dictionary.
Definition dict_util.c:3968
Specifies an attribute which must be present for the module to function.
Definition dict.h:271
Values of the encryption flags.
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:284
Value of an enumerated attribute.
Definition dict.h:231
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:1290
#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:1072
#define PERROR(_fmt,...)
Definition log.h:228
#define DEBUG3(_fmt,...)
Definition log.h:266
#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:380
int fr_debug_lvl
Definition log.c:43
@ L_DBG_LVL_DISABLE
Don't print messages.
Definition log.h:68
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:340
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:337
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:278
#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:845
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)
Definition value.c:5246
void fr_value_box_clear(fr_value_box_t *data)
Clear/free any existing value and metadata.
Definition value.c:3742
static fr_slen_t data
Definition value.h:1274
#define fr_value_box_init_null(_vb)
Initialise an empty/null box that will be filled later.
Definition value.h:604
static size_t char ** out
Definition value.h:1012
#define FR_VALUE_BOX_SAFE_FOR_ANY
Definition value.h:166
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.