static int mod_instantiate(void *instance, CONF_SECTION *conf)
{
proto_vmps_t *inst = talloc_get_type_abort(instance, proto_vmps_t);
- size_t i;
-
- CONF_ITEM *ci;
- CONF_SECTION *server = cf_item_to_section(cf_parent(conf));
- vp_tmpl_rules_t parse_rules;
-
- memset(&parse_rules, 0, sizeof(parse_rules));
- parse_rules.dict_def = dict_vmps;
-
- /*
- * Compile each "send/recv + VMPS packet type" section.
- * This is so that the submodules don't need to do this.
- */
- i = 0;
- for (ci = cf_item_next(server, NULL);
- ci != NULL;
- ci = cf_item_next(server, ci)) {
- fr_dict_enum_t const *dv;
- char const *name, *packet_type;
- CONF_SECTION *subcs;
- rlm_components_t component = MOD_AUTHORIZE;
-
- if (!cf_item_is_section(ci)) continue;
-
- subcs = cf_item_to_section(ci);
- name = cf_section_name1(subcs);
-
- /*
- * We only process recv/send sections.
- * proto_vmps_auth will handle the
- * "authenticate" sections.
- */
- if ((strcmp(name, "recv") != 0) &&
- (strcmp(name, "send") != 0)) {
- continue;
- }
-
- /*
- * One more "recv" or "send" section has been
- * found.
- */
- i++;
-
- /*
- * Skip a section if it was already compiled.
- */
- if (cf_data_find(subcs, unlang_group_t, NULL) != NULL) continue;
-
- /*
- * Check that the packet type is known.
- */
- packet_type = cf_section_name2(subcs);
- dv = fr_dict_enum_by_alias(attr_packet_type, packet_type, -1);
- if (!dv ||
- ((dv->value->vb_uint32 != FR_PACKET_TYPE_VALUE_JOIN_REQUEST) &&
- (dv->value->vb_uint32 != FR_PACKET_TYPE_VALUE_JOIN_RESPONSE) &&
- (dv->value->vb_uint32 != FR_PACKET_TYPE_VALUE_RECONFIRM_REQUEST) &&
- (dv->value->vb_uint32 != FR_PACKET_TYPE_VALUE_RECONFIRM_RESPONSE) &&
- (dv->value->vb_uint32 != FR_PACKET_TYPE_VALUE_DO_NOT_RESPOND))) {
- cf_log_err(subcs, "Invalid VMPS packet type in '%s %s {...}'",
- name, packet_type);
- return -1;
- }
-
- /*
- * Try to compile it, and fail if it doesn't work.
- */
- cf_log_debug(subcs, "compiling - %s %s {...}", name, packet_type);
-
- if (strcmp(name, "send") == 0) component = MOD_POST_AUTH;
-
- if (unlang_compile(subcs, component, &parse_rules) < 0) {
- cf_log_err(subcs, "Failed compiling '%s %s { ... }' section", name, packet_type);
- return -1;
- }
- }
-
- /*
- * No 'recv' or 'send' sections. That's an error.
- */
- if (!i) {
- cf_log_err(server, "Virtual servers cannot be empty.");
- return -1;
- }
/*
* Instantiate the process modules
}
+static virtual_server_compile_t compile_list[] = {
+ { "recv", "Join-Request", MOD_AUTHORIZE },
+ { "send", "Join-Response", MOD_POST_AUTH },
+ { "recv", "Reconfirm-Request", MOD_AUTHORIZE },
+ { "send", "Reconfirm-Response", MOD_POST_AUTH },
+ { "send", "Do-Not-Respond", MOD_POST_AUTH },
+
+ COMPILE_TERMINATOR
+};
+
+static int mod_instantiate(UNUSED void *instance, CONF_SECTION *process_app_cs)
+{
+ CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(process_app_cs));
+ CONF_SECTION *server_cs;
+ vp_tmpl_rules_t parse_rules;
+
+ memset(&parse_rules, 0, sizeof(parse_rules));
+ parse_rules.dict_def = dict_vmps;
+
+ rad_assert(listen_cs);
+
+ server_cs = cf_item_to_section(cf_parent(listen_cs));
+ rad_assert(strcmp(cf_section_name1(server_cs), "server") == 0);
+
+ return virtual_server_compile_sections(server_cs, compile_list, &parse_rules);
+}
+
extern fr_app_worker_t proto_vmps_all;
fr_app_worker_t proto_vmps_all = {
.magic = RLM_MODULE_INIT,
.name = "vmps_all",
+ .instantiate = mod_instantiate,
.entry_point = mod_process,
};
#include <freeradius-devel/vqp/vqp.h>
static fr_dict_t *dict_freeradius;
+static fr_dict_t *dict_vmps;
extern fr_dict_autoload_t proto_vmps_dynamic_client_dict[];
fr_dict_autoload_t proto_vmps_dynamic_client_dict[] = {
{ .out = &dict_freeradius, .proto = "freeradius" },
+ { .out = &dict_vmps, .proto = "vmps" },
{ NULL }
};
}
-/*
- * Ensure that the unlang sections are compiled.
- */
-static int mod_instantiate(UNUSED void *instance, CONF_SECTION *listen_cs)
+static virtual_server_compile_t compile_list[] = {
+ { "new", "client", MOD_AUTHORIZE },
+ { "add", "client", MOD_POST_AUTH },
+ { "deny", "client", MOD_POST_AUTH },
+
+ COMPILE_TERMINATOR
+};
+
+static int mod_instantiate(UNUSED void *instance, CONF_SECTION *process_app_cs)
{
- int rcode;
- CONF_SECTION *server_cs;
+ CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(process_app_cs));
+ CONF_SECTION *server_cs;
vp_tmpl_rules_t parse_rules;
memset(&parse_rules, 0, sizeof(parse_rules));
- parse_rules.dict_def = dict_freeradius;
+ parse_rules.dict_def = dict_vmps;
rad_assert(listen_cs);
server_cs = cf_item_to_section(cf_parent(listen_cs));
rad_assert(strcmp(cf_section_name1(server_cs), "server") == 0);
- rcode = unlang_compile_subsection(server_cs, "new", "client", MOD_AUTHORIZE, &parse_rules);
- if (rcode < 0) return rcode;
- if (rcode == 0) {
- cf_log_err(server_cs, "Failed finding 'new client { ... }' section of virtual server %s",
- cf_section_name2(server_cs));
- return -1;
- }
-
- rcode = unlang_compile_subsection(server_cs, "add", "client", MOD_POST_AUTH, &parse_rules);
- if (rcode < 0) return rcode;
-
- rcode = unlang_compile_subsection(server_cs, "deny", "client", MOD_POST_AUTH, &parse_rules);
- if (rcode < 0) return rcode;
-
- return 0;
+ return virtual_server_compile_sections(server_cs, compile_list, &parse_rules);
}
+
extern fr_app_worker_t proto_vmps_dynamic_client;
fr_app_worker_t proto_vmps_dynamic_client = {
.magic = RLM_MODULE_INIT,