Skip to content
Permalink
Browse files

use new API for compiling processing sections

  • Loading branch information...
alandekok committed Apr 18, 2019
1 parent b09a8bf commit 40205cb2482ab1ba13731bc4556e8b4a7f2f6e70
Showing with 39 additions and 75 deletions.
  1. +0 −75 src/modules/proto_dhcpv4/proto_dhcpv4.c
  2. +39 −0 src/modules/proto_dhcpv4/proto_dhcpv4_base.c
@@ -504,81 +504,6 @@ static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf
static int mod_instantiate(void *instance, CONF_SECTION *conf)
{
proto_dhcpv4_t *inst = talloc_get_type_abort(instance, proto_dhcpv4_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_dhcpv4;

/*
* Compile each "send/recv + DHCPV4 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;

if (!cf_item_is_section(ci)) continue;

subcs = cf_item_to_section(ci);
name = cf_section_name1(subcs);

/*
* We only process recv/send 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_message_type, packet_type, -1);
if (!dv || ((dv->value->vb_uint32 > FR_DHCP_MAX) &&
(dv->value->vb_uint32 == FR_DHCP_MESSAGE_TYPE_VALUE_DHCP_DO_NOT_RESPOND))) {
cf_log_err(subcs, "Invalid DHCPV4 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 (unlang_compile(subcs, MOD_POST_AUTH, &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
@@ -281,9 +281,48 @@ static fr_io_final_t mod_process(UNUSED void const *instance, REQUEST *request,
}


static virtual_server_compile_t compile_list[] = {
{ "recv", "DHCP-Discover", MOD_POST_AUTH },
{ "send", "DHCP-Offer", MOD_POST_AUTH },
{ "recv", "DHCP-Request", MOD_POST_AUTH },

{ "send", "DHCP-Ack", MOD_POST_AUTH },
{ "send", "DHCP-NAK", MOD_POST_AUTH },
{ "send", "DHCP-Decline", MOD_POST_AUTH },

{ "recv", "DHCP-Release", MOD_POST_AUTH },
{ "recv", "DHCP-Inform", MOD_POST_AUTH },
{ "send", "Do-Not-Respond", MOD_POST_AUTH },

{ "recv", "DHCP-Lease-Query", MOD_POST_AUTH },
{ "send", "DHCP-Lease-Unassigned", MOD_POST_AUTH },
{ "send", "DHCP-Lease-Unknown", MOD_POST_AUTH },
{ "send", "DHCP-Lease-Active", 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_dhcpv4;

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_dhcpv4_base;
fr_app_worker_t proto_dhcpv4_base = {
.magic = RLM_MODULE_INIT,
.name = "dhcpv4_base",
.instantiate = mod_instantiate,
.entry_point = mod_process,
};

0 comments on commit 40205cb

Please sign in to comment.
You can’t perform that action at this time.