From 57a4d1cc71d35072a3f98fa6d81b9644f461155d Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Mon, 6 May 2024 22:17:32 -0600 Subject: [PATCH] Use transport parsing callback --- src/lib/io/master.c | 12 ++--- src/lib/io/master.h | 4 +- src/listen/arp/proto_arp.c | 12 ++--- src/listen/arp/proto_arp.h | 4 +- src/listen/bfd/proto_bfd.c | 55 +---------------------- src/listen/control/proto_control.c | 53 +--------------------- src/listen/cron/proto_cron.c | 45 +------------------ src/listen/detail/proto_detail.c | 61 ++++---------------------- src/listen/detail/proto_detail.h | 2 +- src/listen/dhcpv4/proto_dhcpv4.c | 54 +---------------------- src/listen/dhcpv6/proto_dhcpv6.c | 54 +---------------------- src/listen/dns/proto_dns.c | 53 +--------------------- src/listen/ldap_sync/proto_ldap_sync.c | 55 +++-------------------- src/listen/ldap_sync/proto_ldap_sync.h | 2 +- src/listen/load/proto_load.c | 45 +------------------ src/listen/radius/proto_radius.c | 55 +---------------------- src/listen/tacacs/proto_tacacs.c | 55 +---------------------- src/listen/vmps/proto_vmps.c | 54 +---------------------- 18 files changed, 43 insertions(+), 632 deletions(-) diff --git a/src/lib/io/master.c b/src/lib/io/master.c index df78db39dc..08e9fba44e 100644 --- a/src/lib/io/master.c +++ b/src/lib/io/master.c @@ -2499,7 +2499,7 @@ static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, fr_time_t request_ti */ if (radclient->use_connected && !inst->app_io->connection_set) { DEBUG("proto_%s - cannot use connected sockets as underlying 'transport = %s' does not support it.", - inst->app_io->common.name, inst->transport); + inst->app_io->common.name, inst->submodule->dl_inst->module->common->name); goto error; } @@ -2633,10 +2633,10 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) /* * Find and bootstrap the application IO handler. */ - inst->app_io = (fr_app_io_t const *) inst->submodule->module->common; + inst->app_io = (fr_app_io_t const *) inst->submodule->dl_inst->module->common; - inst->app_io_conf = inst->submodule->conf; - inst->app_io_instance = inst->submodule->data; + inst->app_io_conf = inst->submodule->dl_inst->conf; + inst->app_io_instance = inst->submodule->dl_inst->data; /* * If we're not tracking duplicates then we don't need a @@ -2656,7 +2656,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) } } - if (inst->app_io->common.bootstrap && (inst->app_io->common.bootstrap(MODULE_INST_CTX(inst->submodule)) < 0)) { + if (inst->app_io->common.bootstrap && (inst->app_io->common.bootstrap(MODULE_INST_CTX(inst->submodule->dl_inst)) < 0)) { cf_log_err(inst->app_io_conf, "Bootstrap failed for proto_%s", inst->app_io->common.name); return -1; } @@ -2723,7 +2723,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) fr_assert(inst->app_io != NULL); if (inst->app_io->common.instantiate && - (inst->app_io->common.instantiate(MODULE_INST_CTX(inst->submodule)) < 0)) { + (inst->app_io->common.instantiate(MODULE_INST_CTX(inst->submodule->dl_inst)) < 0)) { cf_log_err(conf, "Instantiation failed for \"proto_%s\"", inst->app_io->common.name); return -1; } diff --git a/src/lib/io/master.h b/src/lib/io/master.h index 43a83604ab..ad0cd325d3 100644 --- a/src/lib/io/master.h +++ b/src/lib/io/master.h @@ -85,7 +85,7 @@ typedef struct { CONF_SECTION *server_cs; //!< server CS for this listener - dl_module_inst_t *submodule; //!< As provided by the transport_parse + module_instance_t *submodule; //!< As provided by the transport_parse ///< callback. Broken out into the ///< app_io_* fields below for convenience. fr_app_t *app; //!< main protocol handler @@ -96,8 +96,6 @@ typedef struct { CONF_SECTION *app_io_conf; //!< Easy access to the app_io's config section. int ipproto; //!< IP proto by number - char const *transport; //!< transport, typically name of IP proto - fr_trie_t const *networks; //!< trie of allowed networks } fr_io_instance_t; diff --git a/src/listen/arp/proto_arp.c b/src/listen/arp/proto_arp.c index 12a7b9fad6..eafd71b6d7 100644 --- a/src/listen/arp/proto_arp.c +++ b/src/listen/arp/proto_arp.c @@ -230,7 +230,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) * work submodule. We leave that until later. */ if (inst->app_io->common.instantiate && - (inst->app_io->common.instantiate(MODULE_INST_CTX(inst->io_submodule)) < 0)) { + (inst->app_io->common.instantiate(MODULE_INST_CTX(inst->io_submodule->dl_inst)) < 0)) { cf_log_err(conf, "Instantiation failed for \"%s\"", inst->app_io->common.name); return -1; } @@ -267,14 +267,14 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) parent_inst = cf_data_value(cf_data_find(inst->cs, dl_module_inst_t, "proto_arp")); fr_assert(parent_inst); - if (dl_module_instance(inst->cs, &inst->io_submodule, + if (dl_module_instance(inst->cs, &inst->io_submodule->dl_inst, parent_inst, DL_MODULE_TYPE_SUBMODULE, "ethernet", dl_module_inst_name_from_conf(inst->cs)) < 0) { cf_log_perr(inst->cs, "Failed to load proto_arp_ethernet"); return -1; } - if (dl_module_conf_parse(inst->io_submodule, inst->cs) < 0) { + if (dl_module_conf_parse(inst->io_submodule->dl_inst, inst->cs) < 0) { TALLOC_FREE(inst->io_submodule); return -1; } @@ -282,11 +282,11 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) /* * Bootstrap the I/O module */ - inst->app_io = (fr_app_io_t const *) inst->io_submodule->module->common; - inst->app_io_instance = inst->io_submodule->data; + inst->app_io = (fr_app_io_t const *) inst->io_submodule->dl_inst->module->common; + inst->app_io_instance = inst->io_submodule->dl_inst->data; inst->app_io_conf = conf; - if (inst->app_io->common.bootstrap && (inst->app_io->common.bootstrap(MODULE_INST_CTX(inst->io_submodule)) < 0)) { + if (inst->app_io->common.bootstrap && (inst->app_io->common.bootstrap(MODULE_INST_CTX(inst->io_submodule->dl_inst)) < 0)) { cf_log_err(inst->app_io_conf, "Bootstrap failed for \"%s\"", inst->app_io->common.name); return -1; } diff --git a/src/listen/arp/proto_arp.h b/src/listen/arp/proto_arp.h index 77017c0101..9d84fadc6a 100644 --- a/src/listen/arp/proto_arp.h +++ b/src/listen/arp/proto_arp.h @@ -30,7 +30,7 @@ typedef struct { CONF_SECTION *server_cs; //!< server CS for this listener CONF_SECTION *cs; //!< my configuration - dl_module_inst_t *io_submodule; //!< As provided by the transport_parse + module_instance_t *io_submodule; //!< As provided by the transport_parse ///< callback. Broken out into the ///< app_io_* fields below for convenience. @@ -52,5 +52,3 @@ typedef struct { fr_listen_t *listen; //!< The listener structure which describes //!< the I/O path. } proto_arp_t; - - diff --git a/src/listen/bfd/proto_bfd.c b/src/listen/bfd/proto_bfd.c index 4c394e4251..c3983cc776 100644 --- a/src/listen/bfd/proto_bfd.c +++ b/src/listen/bfd/proto_bfd.c @@ -30,7 +30,6 @@ extern fr_app_t proto_bfd; -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); static int auth_type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); /** How to parse a BFD listen section @@ -38,7 +37,7 @@ static int auth_type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF */ static conf_parser_t const proto_bfd_config[] = { { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_bfd_t, io.submodule), - .func = transport_parse }, + .func = virtual_sever_listen_transport_parse }, CONF_PARSER_TERMINATOR }; @@ -94,58 +93,6 @@ static int8_t client_cmp(void const *one, void const *two) return fr_ipaddr_cmp(&a->ipaddr, &b->ipaddr); } -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_bfd). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - proto_bfd_t *inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_bfd")); - fr_assert(parent_inst); - - /* - * Set the allowed codes so that we can compile them as - * necessary. - */ - inst = talloc_get_type_abort(parent_inst->data, proto_bfd_t); - inst->io.transport = name; - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) { - transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - inst->io.app_io_conf = transport_cs; - } - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, - DL_MODULE_TYPE_SUBMODULE, name, dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - - return 0; -} - /** Parse auth_type * * @param[in] ctx to allocate data in (instance of proto_bfd). diff --git a/src/listen/control/proto_control.c b/src/listen/control/proto_control.c index 42644eff2d..f53ad59e69 100644 --- a/src/listen/control/proto_control.c +++ b/src/listen/control/proto_control.c @@ -27,7 +27,6 @@ #include "proto_control.h" extern fr_app_t proto_control; -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); static conf_parser_t const limit_config[] = { { FR_CONF_OFFSET("idle_timeout", proto_control_t, io.idle_timeout), .dflt = "30.0" } , @@ -51,7 +50,7 @@ static conf_parser_t const limit_config[] = { */ static conf_parser_t const proto_control_config[] = { { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_control_t, io.submodule), - .func = transport_parse }, + .func = virtual_sever_listen_transport_parse }, { FR_CONF_POINTER("limit", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) limit_config }, CONF_PARSER_TERMINATOR @@ -65,56 +64,6 @@ fr_dict_autoload_t proto_control_dict[] = { { NULL } }; -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_control). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - proto_control_t *inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_control")); - fr_assert(parent_inst); - - /* - * Set the allowed codes so that we can compile them as - * necessary. - */ - inst = talloc_get_type_abort(parent_inst->data, proto_control_t); - inst->io.transport = name; - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, - DL_MODULE_TYPE_SUBMODULE, name, dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - - return 0; -} - - /** Open listen sockets/connect to external event source * * @param[in] instance Ctx data for this application. diff --git a/src/listen/cron/proto_cron.c b/src/listen/cron/proto_cron.c index 5e6dc7d741..c0cc546f34 100644 --- a/src/listen/cron/proto_cron.c +++ b/src/listen/cron/proto_cron.c @@ -31,7 +31,6 @@ extern fr_app_t proto_cron; static int type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); /** How to parse a Load listen section * @@ -40,7 +39,7 @@ static conf_parser_t const proto_cron_config[] = { { FR_CONF_OFFSET_TYPE_FLAGS("type", FR_TYPE_VOID, CONF_FLAG_NOT_EMPTY | CONF_FLAG_REQUIRED, proto_cron_t, type), .func = type_parse }, { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_cron_t, io.submodule), - .func = transport_parse, .dflt = "crontab" }, + .func = virtual_sever_listen_transport_parse, .dflt = "crontab" }, /* * Add this as a synonym so normal humans can understand it. @@ -105,48 +104,6 @@ static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM return 0; } -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_cron). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, - CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_cron")); - fr_assert(parent_inst); - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, - DL_MODULE_TYPE_SUBMODULE, name, dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - - return 0; -} - /** Decode the packet, and set the request->process function * */ diff --git a/src/listen/detail/proto_detail.c b/src/listen/detail/proto_detail.c index 3560092579..1d4d040d75 100644 --- a/src/listen/detail/proto_detail.c +++ b/src/listen/detail/proto_detail.c @@ -32,7 +32,6 @@ extern fr_app_t proto_detail; static int type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); #if 0 /* @@ -51,7 +50,7 @@ static conf_parser_t const proto_detail_config[] = { { FR_CONF_OFFSET_TYPE_FLAGS("type", FR_TYPE_VOID, CONF_FLAG_NOT_EMPTY | CONF_FLAG_REQUIRED, proto_detail_t, type), .func = type_parse }, { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_detail_t, io_submodule), - .func = transport_parse, .dflt = "file" }, + .func = virtual_sever_listen_transport_parse, .dflt = "file" }, /* * Add this as a synonym so normal humans can understand it. @@ -146,48 +145,6 @@ static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM return 0; } -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_detail). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, - CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_detail")); - fr_assert(parent_inst); - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, - DL_MODULE_TYPE_SUBMODULE, name, dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - - return 0; -} - /** Decode the packet, and set the request->process function * */ @@ -450,7 +407,7 @@ static int mod_open(void *instance, fr_schedule_t *sc, CONF_SECTION *conf) * Testing: allow it to read a "detail.work" file * directly. */ - if (strcmp(inst->io_submodule->module->dl->name, "proto_detail_work") == 0) { + if (strcmp(inst->io_submodule->dl_inst->module->dl->name, "proto_detail_work") == 0) { if (!fr_schedule_listen_add(sc, li)) { talloc_free(li); return -1; @@ -506,7 +463,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) * work submodule. We leave that until later. */ if (inst->app_io->common.instantiate && - (inst->app_io->common.instantiate(MODULE_INST_CTX(inst->io_submodule)) < 0)) { + (inst->app_io->common.instantiate(MODULE_INST_CTX(inst->io_submodule->dl_inst)) < 0)) { cf_log_err(conf, "Instantiation failed for \"%s\"", inst->app_io->common.name); return -1; } @@ -530,7 +487,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) /* * If the IO is "file" and not the worker, instantiate the worker now. */ - if (strcmp(inst->io_submodule->module->dl->name, "proto_detail_work") != 0) { + if (strcmp(inst->io_submodule->dl_inst->module->dl->name, "proto_detail_work") != 0) { if (inst->work_io->common.instantiate && (inst->work_io->common.instantiate(MODULE_INST_CTX(inst->work_submodule)) < 0)) { cf_log_err(inst->work_io_conf, "Instantiation failed for \"%s\"", inst->work_io->common.name); @@ -573,11 +530,11 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) /* * Bootstrap the I/O module */ - inst->app_io = (fr_app_io_t const *) inst->io_submodule->module->common; - inst->app_io_instance = inst->io_submodule->data; - inst->app_io_conf = inst->io_submodule->conf; + inst->app_io = (fr_app_io_t const *) inst->io_submodule->dl_inst->module->common; + inst->app_io_instance = inst->io_submodule->dl_inst->data; + inst->app_io_conf = inst->io_submodule->dl_inst->conf; - if (inst->app_io->common.bootstrap && (inst->app_io->common.bootstrap(MODULE_INST_CTX(inst->io_submodule)) < 0)) { + if (inst->app_io->common.bootstrap && (inst->app_io->common.bootstrap(MODULE_INST_CTX(inst->io_submodule->dl_inst)) < 0)) { cf_log_err(inst->app_io_conf, "Bootstrap failed for \"%s\"", inst->app_io->common.name); return -1; } @@ -585,7 +542,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) /* * If we're not loading the work submodule directly, then try to load it here. */ - if (strcmp(inst->io_submodule->module->dl->name, "proto_detail_work") != 0) { + if (strcmp(inst->io_submodule->dl_inst->module->dl->name, "proto_detail_work") != 0) { CONF_SECTION *transport_cs; dl_module_inst_t *parent_inst; diff --git a/src/listen/detail/proto_detail.h b/src/listen/detail/proto_detail.h index 45fe0214b2..795e1f8de7 100644 --- a/src/listen/detail/proto_detail.h +++ b/src/listen/detail/proto_detail.h @@ -40,7 +40,7 @@ typedef struct { fr_app_t *self; //!< child / parent linking issues char const *type; //!< packet type name - dl_module_inst_t *io_submodule; //!< As provided by the transport_parse + module_instance_t *io_submodule; //!< As provided by the transport_parse ///< callback. Broken out into the ///< app_io_* fields below for convenience. diff --git a/src/listen/dhcpv4/proto_dhcpv4.c b/src/listen/dhcpv4/proto_dhcpv4.c index 2190d978b1..0d5f5af813 100644 --- a/src/listen/dhcpv4/proto_dhcpv4.c +++ b/src/listen/dhcpv4/proto_dhcpv4.c @@ -31,7 +31,6 @@ extern fr_app_t proto_dhcpv4; static int type_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule); -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); static const conf_parser_t priority_config[] = { { FR_CONF_OFFSET("Discover", proto_dhcpv4_t, priorities[FR_DHCP_DISCOVER]), @@ -75,7 +74,8 @@ static conf_parser_t const limit_config[] = { */ static conf_parser_t const proto_dhcpv4_config[] = { { FR_CONF_OFFSET_FLAGS("type", CONF_FLAG_NOT_EMPTY, proto_dhcpv4_t, allowed_types), .func = type_parse }, - { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_dhcpv4_t, io.submodule), .func = transport_parse }, + { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_dhcpv4_t, io.submodule), + .func = virtual_sever_listen_transport_parse }, { FR_CONF_POINTER("limit", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) limit_config }, @@ -135,56 +135,6 @@ static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, return 0; } -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_dhcpv4). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, - CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - proto_dhcpv4_t *inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_dhcpv4")); - fr_assert(parent_inst); - - /* - * Set the allowed codes so that we can compile them as - * necessary. - */ - inst = talloc_get_type_abort(parent_inst->data, proto_dhcpv4_t); - inst->io.transport = name; - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, - DL_MODULE_TYPE_SUBMODULE, name, dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - - return 0; -} - /** Decode the packet * */ diff --git a/src/listen/dhcpv6/proto_dhcpv6.c b/src/listen/dhcpv6/proto_dhcpv6.c index f3a36783f1..701c9e2889 100644 --- a/src/listen/dhcpv6/proto_dhcpv6.c +++ b/src/listen/dhcpv6/proto_dhcpv6.c @@ -30,7 +30,6 @@ extern fr_app_t proto_dhcpv6; static int type_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule); -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); static const conf_parser_t priority_config[] = { { FR_CONF_OFFSET("Solicit", proto_dhcpv6_t, priorities[FR_DHCPV6_SOLICIT]), @@ -76,7 +75,8 @@ static conf_parser_t const limit_config[] = { */ static conf_parser_t const proto_dhcpv6_config[] = { { FR_CONF_OFFSET_FLAGS("type", CONF_FLAG_NOT_EMPTY, proto_dhcpv6_t, allowed_types), .func = type_parse }, - { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_dhcpv6_t, io.submodule), .func = transport_parse }, + { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_dhcpv6_t, io.submodule), + .func = virtual_sever_listen_transport_parse }, { FR_CONF_POINTER("limit", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) limit_config }, @@ -135,56 +135,6 @@ static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, return 0; } -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_dhcpv6). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, - CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - proto_dhcpv6_t *inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_dhcpv6")); - fr_assert(parent_inst); - - /* - * Set the allowed codes so that we can compile them as - * necessary. - */ - inst = talloc_get_type_abort(parent_inst->data, proto_dhcpv6_t); - inst->io.transport = name; - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, - DL_MODULE_TYPE_SUBMODULE, name, dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - - return 0; -} - /** Decode the packet * */ diff --git a/src/listen/dns/proto_dns.c b/src/listen/dns/proto_dns.c index 3dacf56f5a..cc232fbd31 100644 --- a/src/listen/dns/proto_dns.c +++ b/src/listen/dns/proto_dns.c @@ -30,7 +30,6 @@ extern fr_app_t proto_dns; static int type_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule); -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); static const conf_parser_t priority_config[] = { { FR_CONF_OFFSET_TYPE_FLAGS("query", FR_TYPE_VOID, 0, proto_dns_t, priorities[FR_DNS_QUERY]), @@ -60,7 +59,7 @@ static conf_parser_t const limit_config[] = { static conf_parser_t const proto_dns_config[] = { { FR_CONF_OFFSET_FLAGS("type", CONF_FLAG_NOT_EMPTY, proto_dns_t, allowed_types), .func = type_parse }, { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_dns_t, io.submodule), - .func = transport_parse }, + .func = virtual_sever_listen_transport_parse }, { FR_CONF_POINTER("limit", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) limit_config }, @@ -117,56 +116,6 @@ static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, return 0; } -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_dns). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, - CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - proto_dns_t *inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_dns")); - fr_assert(parent_inst); - - /* - * Set the allowed codes so that we can compile them as - * necessary. - */ - inst = talloc_get_type_abort(parent_inst->data, proto_dns_t); - inst->io.transport = name; - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, - DL_MODULE_TYPE_SUBMODULE, name, dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - - return 0; -} - /** Decode the packet * */ diff --git a/src/listen/ldap_sync/proto_ldap_sync.c b/src/listen/ldap_sync/proto_ldap_sync.c index 809c26d376..f55987cb5b 100644 --- a/src/listen/ldap_sync/proto_ldap_sync.c +++ b/src/listen/ldap_sync/proto_ldap_sync.c @@ -35,8 +35,6 @@ static fr_internal_encode_ctx_t encode_ctx = { .allow_name_only = true }; extern fr_app_t proto_ldap_sync; -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); - static conf_parser_t const ldap_sync_search_config[] = { { FR_CONF_OFFSET("base_dn", sync_config_t, base_dn), .dflt = "", .quote = T_SINGLE_QUOTED_STRING }, @@ -51,7 +49,7 @@ static conf_parser_t const ldap_sync_search_config[] = { static conf_parser_t const proto_ldap_sync_config[] = { { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_ldap_sync_t, io_submodule), - .func = transport_parse }, + .func = virtual_sever_listen_transport_parse }, { FR_CONF_OFFSET("max_packet_size", proto_ldap_sync_t, max_packet_size) }, { FR_CONF_OFFSET("num_messages", proto_ldap_sync_t, num_messages) }, @@ -95,47 +93,6 @@ fr_dict_attr_autoload_t proto_ldap_sync_dict_attr[] = { { NULL } }; -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_dns). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, - CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_ldap_sync")); - fr_assert(parent_inst); - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, DL_MODULE_TYPE_SUBMODULE, name, - dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - return 0; -} - /** Check if an attribute is in the config list and add if not present * * @param[in,out] config to check for attribute. @@ -300,7 +257,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) * Instantiate the I/O module. */ if (inst->app_io->common.instantiate && - (inst->app_io->common.instantiate(MODULE_INST_CTX(inst->io_submodule)) < 0)) { + (inst->app_io->common.instantiate(MODULE_INST_CTX(inst->io_submodule->dl_inst)) < 0)) { cf_log_err(conf, "Instantiation failed for \"%s\"", inst->app_io->common.name); return -1; } @@ -425,12 +382,12 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) /* * Bootstrap the I/O module */ - inst->app_io = (fr_app_io_t const *) inst->io_submodule->module->common; - inst->app_io_instance = inst->io_submodule->data; - inst->app_io_conf = inst->io_submodule->conf; + inst->app_io = (fr_app_io_t const *) inst->io_submodule->dl_inst->module->common; + inst->app_io_instance = inst->io_submodule->dl_inst->data; + inst->app_io_conf = inst->io_submodule->dl_inst->conf; if (inst->app_io->common.bootstrap && - (inst->app_io->common.bootstrap(MODULE_INST_CTX(inst->io_submodule)) < 0)) { + (inst->app_io->common.bootstrap(MODULE_INST_CTX(inst->io_submodule->dl_inst)) < 0)) { cf_log_err(inst->app_io_conf, "Bootstrap failed for \"%s\"", inst->app_io->common.name); return -1; } diff --git a/src/listen/ldap_sync/proto_ldap_sync.h b/src/listen/ldap_sync/proto_ldap_sync.h index 97d2b5f0ab..ce7baf701f 100644 --- a/src/listen/ldap_sync/proto_ldap_sync.h +++ b/src/listen/ldap_sync/proto_ldap_sync.h @@ -40,7 +40,7 @@ typedef struct { fr_app_t *self; //!< child / parent linking issues - dl_module_inst_t *io_submodule; //!< As provided by the transport_parse + module_instance_t *io_submodule; //!< As provided by the transport_parse //!< callback. Broken out into the //!< app_io_* fields below for convenience. diff --git a/src/listen/load/proto_load.c b/src/listen/load/proto_load.c index 7577be3941..6147687c05 100644 --- a/src/listen/load/proto_load.c +++ b/src/listen/load/proto_load.c @@ -31,7 +31,6 @@ extern fr_app_t proto_load; static int type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); /** How to parse a Load listen section * @@ -40,7 +39,7 @@ static conf_parser_t const proto_load_config[] = { { FR_CONF_OFFSET_TYPE_FLAGS("type", FR_TYPE_VOID, CONF_FLAG_NOT_EMPTY | CONF_FLAG_REQUIRED, proto_load_t, type), .func = type_parse }, { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_load_t, io.submodule), - .func = transport_parse, .dflt = "step" }, + .func = virtual_sever_listen_transport_parse, .dflt = "step" }, /* * Add this as a synonym so normal humans can understand it. @@ -105,48 +104,6 @@ static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM return 0; } -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_load). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, - CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_load")); - fr_assert(parent_inst); - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, - DL_MODULE_TYPE_SUBMODULE, name, dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - - return 0; -} - /** Decode the packet, and set the request->process function * */ diff --git a/src/listen/radius/proto_radius.c b/src/listen/radius/proto_radius.c index 11f39a3f5f..623d9a1af3 100644 --- a/src/listen/radius/proto_radius.c +++ b/src/listen/radius/proto_radius.c @@ -31,7 +31,6 @@ extern fr_app_t proto_radius; static int type_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); static conf_parser_t const limit_config[] = { { FR_CONF_OFFSET("cleanup_delay", proto_radius_t, io.cleanup_delay), .dflt = "5.0" } , @@ -72,7 +71,7 @@ static const conf_parser_t priority_config[] = { static conf_parser_t const proto_radius_config[] = { { FR_CONF_OFFSET_FLAGS("type", CONF_FLAG_NOT_EMPTY, proto_radius_t, allowed_types), .func = type_parse }, { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_radius_t, io.submodule), - .func = transport_parse }, + .func = virtual_sever_listen_transport_parse }, /* * Check whether or not the *trailing* bits of a @@ -142,58 +141,6 @@ static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM return 0; } -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_radius). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - proto_radius_t *inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_radius")); - fr_assert(parent_inst); - - /* - * Set the allowed codes so that we can compile them as - * necessary. - */ - inst = talloc_get_type_abort(parent_inst->data, proto_radius_t); - inst->io.transport = name; - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) { - transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - inst->io.app_io_conf = transport_cs; - } - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, - DL_MODULE_TYPE_SUBMODULE, name, dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - - return 0; -} - /** Decode the packet * */ diff --git a/src/listen/tacacs/proto_tacacs.c b/src/listen/tacacs/proto_tacacs.c index dc789dcfeb..ee67b111b4 100644 --- a/src/listen/tacacs/proto_tacacs.c +++ b/src/listen/tacacs/proto_tacacs.c @@ -34,7 +34,6 @@ extern fr_app_t proto_tacacs; static int type_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule); -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule); static conf_parser_t const limit_config[] = { { FR_CONF_OFFSET("idle_timeout", proto_tacacs_t, io.idle_timeout), .dflt = "30.0" } , @@ -65,7 +64,7 @@ static const conf_parser_t priority_config[] = { static const conf_parser_t proto_tacacs_config[] = { { FR_CONF_OFFSET_FLAGS("type", CONF_FLAG_NOT_EMPTY, proto_tacacs_t, allowed_types), .func = type_parse }, - { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_tacacs_t, io.submodule), .func = transport_parse }, + { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_tacacs_t, io.submodule), .func = virtual_sever_listen_transport_parse }, { FR_CONF_POINTER("limit", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) limit_config }, { FR_CONF_POINTER("priority", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) priority_config }, @@ -128,58 +127,6 @@ static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM return 0; } -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_tacacs). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - proto_tacacs_t *inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_tacacs")); - fr_assert(parent_inst); - - /* - * Set the allowed codes so that we can compile them as - * necessary. - */ - inst = talloc_get_type_abort(parent_inst->data, proto_tacacs_t); - inst->io.transport = name; - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) { - transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - inst->io.app_io_conf = transport_cs; - } - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, - DL_MODULE_TYPE_SUBMODULE, name, dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - - return 0; -} - /** Decode the packet * */ diff --git a/src/listen/vmps/proto_vmps.c b/src/listen/vmps/proto_vmps.c index 4aefa021d3..b4a865d46f 100644 --- a/src/listen/vmps/proto_vmps.c +++ b/src/listen/vmps/proto_vmps.c @@ -32,8 +32,6 @@ extern fr_app_t proto_vmps; static int type_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule); -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, - CONF_ITEM *ci, conf_parser_t const *rule); static const conf_parser_t priority_config[] = { { FR_CONF_OFFSET("Join-Request", proto_vmps_t, priorities[FR_PACKET_TYPE_VALUE_JOIN_REQUEST]), @@ -66,7 +64,7 @@ static conf_parser_t const limit_config[] = { */ static conf_parser_t const proto_vmps_config[] = { { FR_CONF_OFFSET_FLAGS("type", CONF_FLAG_NOT_EMPTY, proto_vmps_t, allowed_types), .func = type_parse }, - { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_vmps_t, io.submodule), .func = transport_parse }, + { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_vmps_t, io.submodule), .func = virtual_sever_listen_transport_parse }, { FR_CONF_POINTER("limit", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) limit_config }, { FR_CONF_POINTER("priority", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) priority_config }, @@ -123,56 +121,6 @@ static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent, return 0; } -/** Wrapper around dl_instance - * - * @param[in] ctx to allocate data in (instance of proto_vmps). - * @param[out] out Where to write a dl_module_inst_t containing the module handle and instance. - * @param[in] parent Base structure address. - * @param[in] ci #CONF_PAIR specifying the name of the type module. - * @param[in] rule unused. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, - CONF_ITEM *ci, UNUSED conf_parser_t const *rule) -{ - char const *name = cf_pair_value(cf_item_to_pair(ci)); - dl_module_inst_t *parent_inst; - proto_vmps_t *inst; - CONF_SECTION *listen_cs = cf_item_to_section(cf_parent(ci)); - CONF_SECTION *transport_cs; - dl_module_inst_t *dl_mod_inst; - - transport_cs = cf_section_find(listen_cs, name, NULL); - - /* - * Allocate an empty section if one doesn't exist - * this is so defaults get parsed. - */ - if (!transport_cs) transport_cs = cf_section_alloc(listen_cs, listen_cs, name, NULL); - - parent_inst = cf_data_value(cf_data_find(listen_cs, dl_module_inst_t, "proto_vmps")); - fr_assert(parent_inst); - - /* - * Set the allowed codes so that we can compile them as - * necessary. - */ - inst = talloc_get_type_abort(parent_inst->data, proto_vmps_t); - inst->io.transport = name; - - if (dl_module_instance(ctx, &dl_mod_inst, parent_inst, - DL_MODULE_TYPE_SUBMODULE, name, dl_module_inst_name_from_conf(transport_cs)) < 0) return -1; - if (dl_module_conf_parse(dl_mod_inst, transport_cs) < 0) { - talloc_free(dl_mod_inst); - return -1; - } - *((dl_module_inst_t **)out) = dl_mod_inst; - - return 0; -} - /** Decode the packet * */ -- 2.47.3