Skip to content

Commit f173c76

Browse files
committed
Define a common section name struct, and use pointers to those structs
Will allow slightly faster comparisons in some cases, and allow common module method names to be defined
1 parent 81b2aeb commit f173c76

File tree

77 files changed

+601
-797
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+601
-797
lines changed

src/lib/server/module.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern "C" {
3232

3333
typedef struct module_s module_t;
3434
typedef struct module_state_func_table_s module_state_func_table_t;
35-
typedef struct module_method_name_s module_method_name_t;
35+
typedef struct module_method_binding_s module_method_binding_t;
3636
typedef struct module_instance_s module_instance_t;
3737
typedef struct module_thread_instance_s module_thread_instance_t;
3838
typedef struct module_list_type_s module_list_type_t;
@@ -129,6 +129,7 @@ typedef int (*module_thread_detach_t)(module_thread_inst_ctx_t const *mctx);
129129
#include <freeradius-devel/server/exfile.h>
130130
#include <freeradius-devel/server/pool.h>
131131
#include <freeradius-devel/server/request.h>
132+
#include <freeradius-devel/server/section.h>
132133

133134
#include <freeradius-devel/unlang/action.h>
134135
#include <freeradius-devel/unlang/call_env.h>
@@ -144,18 +145,21 @@ extern "C" {
144145
*/
145146
#define MODULE_INSTANCE_LEN_MAX 256
146147

148+
/** Terminate a module binding list
149+
*/
150+
#define MODULE_BINDING_TERMINATOR { .section = NULL }
151+
147152
/** Named methods exported by a module
148153
*
149154
*/
150-
struct module_method_name_s {
151-
char const *name1; //!< i.e. "recv", "send", "process"
152-
char const *name2; //!< The packet type i.e Access-Request, Access-Reject.
155+
struct module_method_binding_s {
156+
fr_dict_t const **proto; //!< Only allow this method to be called in this namespace.
153157

154-
module_method_t method; //!< Module method to call
155-
call_env_method_t const * const method_env; //!< Call specific conf parsing.
156-
};
158+
section_name_t const *section; //!< Identifier for a section.
157159

158-
#define MODULE_NAME_TERMINATOR { NULL }
160+
module_method_t method; //!< Module method to call
161+
call_env_method_t const * const method_env; //!< Call specific conf parsing.
162+
};
159163

160164
/** Struct exported by a rlm_* module
161165
*

src/lib/server/module_method.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* $Id$
1919
*
2020
* @file src/lib/server/module_method.c
21-
* @brief Central module_method_name_t definitions
21+
* @brief Central module_method_binding_t definitions
2222
*
2323
* This file contains common module_method_t structures which may be
2424
* referenced within a #virtual_server_compile_t and a #module_t.
@@ -33,33 +33,24 @@
3333
*
3434
* @copyright 2022 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
3535
*/
36-
typedef struct {
37-
fr_dict_t const **proto; //!< If none-null, restrict matches to this protocol.
38-
///< i.e. if both the virtual server module_method_name
39-
///< and the module method have non-null proto pointers
40-
///< then *proto must be equal for the method name to
41-
///< match.
36+
#include <freeradius-devel/server/module_method.h>
4237

43-
char const *name1; //!< module method name1 which is allowed in this section
44-
char const *name2; //!< module method name2 which is allowed in this section
45-
} module_method_name_t;
46-
47-
module_method_name_t module_method_ippool_allocate = {
38+
section_name_t module_method_ippool_allocate = {
4839
.name1 = "ippool",
4940
.name2 = "allocate"
5041
};
5142

52-
module_method_name_t module_method_ippool_extend = {
43+
section_name_t module_method_ippool_extend = {
5344
.name1 = "ippool",
5445
.name2 = "extend"
5546
};
5647

57-
module_method_name_t module_method_ippool_mark = {
48+
section_name_t module_method_ippool_mark = {
5849
.name1 = "ippool",
5950
.name2 = "mark"
6051
};
6152

62-
module_method_name_t module_method_ippool_release = {
53+
section_name_t module_method_ippool_release = {
6354
.name1 = "ippool",
6455
.name2 = "release"
6556
};

src/lib/server/module_method.h

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,15 @@ RCSIDH(module_method_h, "$Id$")
2929
extern "C" {
3030
#endif
3131

32-
#include <freeradius-devel/util/dict.h>
32+
#include <freeradius-devel/server/virtual_servers.h>
3333

34-
/** Specifies a module method identifier
35-
*
36-
* These are used in module definitions and by virtual servers to find mutually
37-
* acceptable module methods to call between a virtual server section and the
38-
* module that's calling it.
39-
*
40-
* For example, a `send Access-Accept` compilation structure may also have a
41-
* `ippool alloc` method associated with it, to instruct any ippool modules to
42-
* allocate an IP address.
43-
*/
44-
typedef struct {
45-
fr_dict_t const **proto; //!< If none-null, restrict matches to this protocol.
46-
///< i.e. if both the virtual server module_method_name
47-
///< and the module method have non-null proto pointers
48-
///< then *proto must be equal for the method name to
49-
///< match.
50-
51-
char const *name1; //!< module method name1 which is allowed in this section
52-
char const *name2; //!< module method name2 which is allowed in this section
53-
} module_method_name_t;
54-
55-
extern module_method_name_t module_method_ippool_allocate;
34+
extern section_name_t module_method_ippool_allocate;
5635

57-
extern module_method_name_t module_method_ippool_extend;
36+
extern section_name_t module_method_ippool_extend;
5837

59-
extern module_method_name_t module_method_ippool_mark;
38+
extern section_name_t module_method_ippool_mark;
6039

61-
extern module_method_name_t module_method_ippool_release;
40+
extern section_name_t module_method_ippool_release;
6241

6342
#ifdef __cplusplus
6443
}

src/lib/server/module_rlm.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ module_instance_t *module_rlm_by_name_and_method(module_method_t *method, call_e
448448
size_t len;
449449
int j;
450450
module_instance_t *mi;
451-
module_method_name_t const *methods;
451+
module_method_binding_t const *methods;
452452
char const *method_name1, *method_name2;
453453
module_rlm_t const *mrlm;
454454

@@ -470,7 +470,7 @@ module_instance_t *module_rlm_by_name_and_method(module_method_t *method, call_e
470470
*/
471471
mi = module_rlm_static_by_name(NULL, name);
472472
if (mi) {
473-
virtual_server_method_t const *allowed_list;
473+
section_name_t const **allowed_list;
474474

475475
if (!method) return mi;
476476

@@ -481,20 +481,20 @@ module_instance_t *module_rlm_by_name_and_method(module_method_t *method, call_e
481481
* module has no named methods. Try to return a
482482
* method based on the component.
483483
*/
484-
if (!method_name1 || !mrlm->method_names) goto return_component;
484+
if (!method_name1 || !mrlm->bindings) goto return_component;
485485

486486
/*
487487
* Walk through the module, finding a matching
488488
* method.
489489
*/
490-
for (j = 0; mrlm->method_names[j].name1 != NULL; j++) {
491-
methods = &mrlm->method_names[j];
490+
for (j = 0; mrlm->bindings[j].section; j++) {
491+
methods = &mrlm->bindings[j];
492492

493493
/*
494494
* Wildcard match name1, we're
495495
* done.
496496
*/
497-
if (methods->name1 == CF_IDENT_ANY) {
497+
if (methods->section->name1 == CF_IDENT_ANY) {
498498
found:
499499
*method = methods->method;
500500
if (method_env) *method_env = methods->method_env;
@@ -506,26 +506,26 @@ module_instance_t *module_rlm_by_name_and_method(module_method_t *method, call_e
506506
/*
507507
* If name1 doesn't match, skip it.
508508
*/
509-
if (strcasecmp(methods->name1, method_name1) != 0) continue;
509+
if (strcasecmp(methods->section->name1, method_name1) != 0) continue;
510510

511511
/*
512512
* The module can declare a
513513
* wildcard for name2, in which
514514
* case it's a match.
515515
*/
516-
if (methods->name2 == CF_IDENT_ANY) goto found;
516+
if (methods->section->name2 == CF_IDENT_ANY) goto found;
517517

518518
/*
519519
* No name2 is also a match to no name2.
520520
*/
521-
if (!methods->name2 && !method_name2) goto found;
521+
if (!methods->section->name2 && !method_name2) goto found;
522522

523523
/*
524524
* Don't do strcmp on NULLs
525525
*/
526-
if (!methods->name2 || !method_name2) continue;
526+
if (!methods->section->name2 || !method_name2) continue;
527527

528-
if (strcasecmp(methods->name2, method_name2) == 0) goto found;
528+
if (strcasecmp(methods->section->name2, method_name2) == 0) goto found;
529529
}
530530

531531
if (!vs) goto skip_section_method;
@@ -558,22 +558,22 @@ module_instance_t *module_rlm_by_name_and_method(module_method_t *method, call_e
558558
* then any module method would match, which is
559559
* bad.
560560
*/
561-
for (j = 0; allowed_list[j].name1 != NULL; j++) {
561+
for (j = 0; allowed_list[j]; j++) {
562562
int k;
563-
virtual_server_method_t const *allowed = &allowed_list[j];
563+
section_name_t const *allowed = allowed_list[j];
564564

565-
for (k = 0; mrlm->method_names[k].name1 != NULL; k++) {
566-
methods = &mrlm->method_names[k];
565+
for (k = 0; mrlm->bindings[k].section; k++) {
566+
methods = &mrlm->bindings[k];
567567

568-
fr_assert(methods->name1 != CF_IDENT_ANY); /* should have been caught above */
568+
fr_assert(methods->section->name1 != CF_IDENT_ANY); /* should have been caught above */
569569

570-
if (strcasecmp(methods->name1, allowed->name1) != 0) continue;
570+
if (strcasecmp(methods->section->name1, allowed->name1) != 0) continue;
571571

572572
/*
573573
* The module matches "recv *",
574574
* call this method.
575575
*/
576-
if (methods->name2 == CF_IDENT_ANY) {
576+
if (methods->section->name2 == CF_IDENT_ANY) {
577577
found_allowed:
578578
*method = methods->method;
579579
return mi;
@@ -582,14 +582,14 @@ module_instance_t *module_rlm_by_name_and_method(module_method_t *method, call_e
582582
/*
583583
* No name2 is also a match to no name2.
584584
*/
585-
if (!methods->name2 && !allowed->name2) goto found_allowed;
585+
if (!methods->section->name2 && !allowed->name2) goto found_allowed;
586586

587587
/*
588588
* Don't do strcasecmp on NULLs
589589
*/
590-
if (!methods->name2 || !allowed->name2) continue;
590+
if (!methods->section->name2 || !allowed->name2) continue;
591591

592-
if (strcasecmp(methods->name2, allowed->name2) == 0) goto found_allowed;
592+
if (strcasecmp(methods->section->name2, allowed->name2) == 0) goto found_allowed;
593593
}
594594
}
595595

@@ -663,7 +663,7 @@ module_instance_t *module_rlm_by_name_and_method(module_method_t *method, call_e
663663
/*
664664
* We've found the module, but it has no named methods.
665665
*/
666-
if (!mrlm->method_names) {
666+
if (!mrlm->bindings) {
667667
*name1 = name + (p - inst_name);
668668
*name2 = NULL;
669669
goto finish;
@@ -675,24 +675,24 @@ module_instance_t *module_rlm_by_name_and_method(module_method_t *method, call_e
675675
* matches anything else.
676676
*/
677677
if (!q) {
678-
for (j = 0; mrlm->method_names[j].name1 != NULL; j++) {
679-
methods = &mrlm->method_names[j];
678+
for (j = 0; mrlm->bindings[j].section; j++) {
679+
methods = &mrlm->bindings[j];
680680

681681
/*
682682
* If we do not have the second $method, then ignore it!
683683
*/
684-
if (methods->name2 && (methods->name2 != CF_IDENT_ANY)) continue;
684+
if (methods->section->name2 && (methods->section->name2 != CF_IDENT_ANY)) continue;
685685

686686
/*
687687
* Wildcard match name1, we're
688688
* done.
689689
*/
690-
if (!methods->name1 || (methods->name1 == CF_IDENT_ANY)) goto found_name1;
690+
if (!methods->section->name1 || (methods->section->name1 == CF_IDENT_ANY)) goto found_name1;
691691

692692
/*
693693
* If name1 doesn't match, skip it.
694694
*/
695-
if (strcasecmp(methods->name1, p) != 0) continue;
695+
if (strcasecmp(methods->section->name1, p) != 0) continue;
696696

697697
found_name1:
698698
/*
@@ -729,41 +729,41 @@ module_instance_t *module_rlm_by_name_and_method(module_method_t *method, call_e
729729
*
730730
* Loop over the method names, seeing if we have a match.
731731
*/
732-
for (j = 0; mrlm->method_names[j].name1 != NULL; j++) {
733-
methods = &mrlm->method_names[j];
732+
for (j = 0; mrlm->bindings[j].section; j++) {
733+
methods = &mrlm->bindings[j];
734734

735735
/*
736736
* If name1 doesn't match, skip it.
737737
*/
738-
if (strncasecmp(methods->name1, p, len) != 0) continue;
738+
if (strncasecmp(methods->section->name1, p, len) != 0) continue;
739739

740740
/*
741741
* It may have been a partial match, like "rec",
742742
* instead of "recv". In which case check if it
743743
* was a FULL match.
744744
*/
745-
if (strlen(methods->name1) != len) continue;
745+
if (strlen(methods->section->name1) != len) continue;
746746

747747
/*
748748
* The module can declare a
749749
* wildcard for name2, in which
750750
* case it's a match.
751751
*/
752-
if (!methods->name2 || (methods->name2 == CF_IDENT_ANY)) goto found_name2;
752+
if (!methods->section->name2 || (methods->section->name2 == CF_IDENT_ANY)) goto found_name2;
753753

754754
/*
755755
* Don't do strcmp on NULLs
756756
*/
757-
if (!methods->name2) continue;
757+
if (!methods->section->name2) continue;
758758

759-
if (strcasecmp(methods->name2, q) != 0) continue;
759+
if (strcasecmp(methods->section->name2, q) != 0) continue;
760760

761761
found_name2:
762762
/*
763763
* Update name1/name2 with the methods
764764
* that were found.
765765
*/
766-
*name1 = methods->name1;
766+
*name1 = methods->section->name1;
767767
*name2 = name + (q - inst_name);
768768
*method = methods->method;
769769
if (method_env) *method_env = methods->method_env;

src/lib/server/module_rlm.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ extern "C" {
3434

3535
typedef struct {
3636
module_t common; //!< Common fields presented by all modules.
37-
module_method_name_t const *method_names; //!< named methods
38-
fr_dict_t const **dict; //!< pointer to local fr_dict_t*
37+
module_method_binding_t const *bindings; //!< named methods
3938
} module_rlm_t;
4039

4140
/** Cast a module_t to a module_rlm_t

src/lib/server/process.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,20 +467,17 @@ static inline unlang_action_t new_client(rlm_rcode_t *p_result, module_ctx_t con
467467

468468
#define DYNAMIC_CLIENT_SECTIONS \
469469
{ \
470-
.name1 = "new", \
471-
.name2 = "client", \
470+
.section = SECTION_NAME("new", "client"), \
472471
.actions = &mod_actions_authorize, \
473472
.offset = PROCESS_CONF_OFFSET(new_client), \
474473
}, \
475474
{ \
476-
.name1 = "add", \
477-
.name2 = "client", \
475+
.section = SECTION_NAME("add", "client"), \
478476
.actions = &mod_actions_authorize, \
479477
.offset = PROCESS_CONF_OFFSET(add_client), \
480478
}, \
481479
{ \
482-
.name1 = "deny", \
483-
.name2 = "client", \
480+
.section = SECTION_NAME("deny", "client"), \
484481
.actions = &mod_actions_authorize, \
485482
.offset = PROCESS_CONF_OFFSET(deny_client), \
486483
}

0 commit comments

Comments
 (0)