From: Alan T. DeKok Date: Tue, 23 Feb 2021 13:17:14 +0000 (-0500) Subject: rework arp to use process_foo methods X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47d26de6543abb95a91b26e5a6ed82a2c1ecdd66;p=thirdparty%2Ffreeradius-server.git rework arp to use process_foo methods it still uses the entry_point_set() method until such time as all of the other protocols are cleaned up --- diff --git a/src/listen/arp/proto_arp.c b/src/listen/arp/proto_arp.c index eef22934afe..3abfae904db 100644 --- a/src/listen/arp/proto_arp.c +++ b/src/listen/arp/proto_arp.c @@ -143,30 +143,14 @@ static ssize_t mod_encode(void const *instance, request_t *request, uint8_t *buf return slen; } -static void mod_entry_point_set(void const *instance, request_t *request) +static void mod_entry_point_set(UNUSED void const *instance, request_t *request) { - proto_arp_t const *inst = talloc_get_type_abort_const(instance, proto_arp_t); - fr_app_worker_t const *app_process; + fr_assert(request->server_cs != NULL); - /* - * Only one "process" function: proto_arp_process. - */ - app_process = (fr_app_worker_t const *) inst->app_process->module->common; - - request->server_cs = inst->server_cs; - request->async->process = app_process->entry_point; - request->async->process_inst = inst->process_instance; + return virtual_server_entry_point_set(request); } -/* - * @todo - do actual priority setting - */ -static int mod_priority_set(UNUSED void const *instance, UNUSED uint8_t const *buffer, UNUSED size_t buflen) -{ - return PRIORITY_NORMAL; -} - /** Open listen sockets/connect to external event source * * @param[in] instance Ctx data for this application. @@ -244,7 +228,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_arp_t *inst = talloc_get_type_abort(instance, proto_arp_t); - fr_app_worker_t const *app_process; /* * Instantiate the I/O module. But DON'T instantiate the @@ -262,30 +245,6 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) FR_INTEGER_BOUND_CHECK("num_messages", inst->num_messages, >=, 32); FR_INTEGER_BOUND_CHECK("num_messages", inst->num_messages, <=, 65535); - /* - * Instantiate the ARP processor - */ - app_process = (fr_app_worker_t const *)inst->app_process->module->common; - if (app_process->instantiate && (app_process->instantiate(inst->app_process->data, - inst->app_process->conf) < 0)) { - cf_log_err(conf, "Instantiation failed for \"%s\"", app_process->name); - return -1; - } - - /* - * Compile the processing sections. - */ - if (app_process->compile_list) { - tmpl_rules_t parse_rules; - - memset(&parse_rules, 0, sizeof(parse_rules)); - parse_rules.dict_def = dict_arp; - - if (virtual_server_compile_sections(inst->server_cs, app_process->compile_list, &parse_rules, inst->app_process->data) < 0) { - return -1; - } - } - return 0; } @@ -304,7 +263,6 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) { proto_arp_t *inst = talloc_get_type_abort(instance, proto_arp_t); dl_module_inst_t *parent_inst; - fr_app_worker_t const *app_process; /* * Ensure that the server CONF_SECTION is always set. @@ -321,33 +279,6 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) return -1; } - /* - * Load proto_arp_process. We don't have "type = ...", - * because there's only one allowed type. As a result, - * we can't call fr_app_process_type_parse(), unless we - * butcher that function to almost meaninglessness. - */ - if (dl_module_instance(inst->cs, &inst->app_process, inst->cs, - parent_inst, "process", DL_MODULE_TYPE_SUBMODULE) < 0) { - cf_log_perr(inst->cs, "Failed to load proto_arp_process"); - return -1; - } - - /* - * Check for "recv", and add the app_process library to - * the virtual server. These re the only two steps done - * by fr_app_process_type_parse(), which we need. - * - * If at some point proto_arp_process takes instance data, - * we will need to go add that, too - */ - if (!cf_section_find(inst->server_cs, "recv", "Request")) { - cf_log_err(inst->server_cs, "Failed finding 'recv Request {...} section of virtual server %s", - cf_section_name2(inst->server_cs)); - return -1; - } - cf_data_add_static(inst->server_cs, inst->app_process, "app_process", false); - /* * Bootstrap the I/O module */ @@ -361,39 +292,6 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) return -1; } - /* - * Bootstrap the ARP processor - */ - app_process = (fr_app_worker_t const *)(inst->app_process->module->common); - if (app_process->bootstrap && (app_process->bootstrap(inst->app_process->data, - inst->app_process->conf) < 0)) { - cf_log_err(conf, "Bootstrap failed for \"%s\"", app_process->name); - return -1; - } - - /* - * Register the processing sections with the - * module manager. - * - * We have to do this ourselves because we don't call - * fr_app_process_bootstrap(). That function requires a - * "type = ..." configuration, which isn't used for ARP. - */ - if (app_process->compile_list) { - int j; - virtual_server_compile_t const *list = app_process->compile_list; - - for (j = 0; list[j].name != NULL; j++) { - if (list[j].name == CF_IDENT_ANY) continue; - - if (virtual_server_section_register(&list[j]) < 0) { - cf_log_err(conf, "Failed registering section name for %s", - app_process->name); - return -1; - } - } - } - return 0; } @@ -426,5 +324,4 @@ fr_app_t proto_arp = { .decode = mod_decode, .encode = mod_encode, .entry_point_set = mod_entry_point_set, - .priority = mod_priority_set }; diff --git a/src/process/arp/base.c b/src/process/arp/base.c index 88cc957e8fc..869eee94605 100644 --- a/src/process/arp/base.c +++ b/src/process/arp/base.c @@ -58,7 +58,6 @@ static unlang_action_t mod_process(rlm_rcode_t *p_result, UNUSED module_ctx_t co rlm_rcode_t rcode; CONF_SECTION *unlang; fr_dict_enum_t const *dv; - fr_dict_attr_t const *da = NULL; fr_pair_t *vp; static int reply_ok[FR_ARP_MAX_PACKET_CODE] = { @@ -88,7 +87,7 @@ static unlang_action_t mod_process(rlm_rcode_t *p_result, UNUSED module_ctx_t co request->component = "arp"; - dv = fr_dict_enum_by_value(attr_packet_type, fr_box_uint16(request->packet->code)); + dv = fr_dict_enum_by_value(attr_packet_type, fr_box_uint32(request->packet->code)); if (!dv) { REDEBUG("Failed to find value for &request.Packet-Type"); RETURN_MODULE_FAIL; @@ -151,7 +150,7 @@ static unlang_action_t mod_process(rlm_rcode_t *p_result, UNUSED module_ctx_t co RETURN_MODULE_HANDLED; } - dv = fr_dict_enum_by_value(da, fr_box_uint8(request->reply->code)); + dv = fr_dict_enum_by_value(attr_packet_type, fr_box_uint32(request->reply->code)); unlang = NULL; if (dv) unlang = cf_section_find(request->server_cs, "send", dv->name); @@ -195,7 +194,7 @@ static unlang_action_t mod_process(rlm_rcode_t *p_result, UNUSED module_ctx_t co request->reply->code = FR_ARP_CODE_DO_NOT_RESPOND; - dv = fr_dict_enum_by_value(da, fr_box_uint16(request->reply->code)); + dv = fr_dict_enum_by_value(attr_packet_type, fr_box_uint32(request->reply->code)); unlang = NULL; if (!dv) goto send_reply;