Commit 4cafc0ad authored by Daniel Salzman's avatar Daniel Salzman

query_module: simplify module interface

parent 75068cff
......@@ -426,7 +426,8 @@ void conf_activate_modules(
}
// Open the module.
struct query_module *mod = query_module_open(conf, mod_id, conf->mm);
struct query_module *mod = query_module_open(conf, mod_id, *query_plan,
zone_name, conf->mm);
if (mod == NULL) {
ret = KNOT_ENOMEM;
goto activate_error;
......@@ -451,7 +452,7 @@ void conf_activate_modules(
}
// Load the module.
ret = mod->load(*query_plan, mod, zone_name);
ret = mod->load(mod);
if (ret != KNOT_EOK) {
if (zone_name != NULL) {
log_zone_error(zone_name,
......
......@@ -101,8 +101,7 @@ static int dnsproxy_fwd(int state, knot_pkt_t *pkt, struct query_data *qdata, vo
return KNOT_STATE_DONE;
}
int dnsproxy_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone)
int dnsproxy_load(struct query_module *self)
{
assert(self);
......@@ -122,7 +121,7 @@ int dnsproxy_load(struct query_plan *plan, struct query_module *self,
self->ctx = proxy;
return query_plan_step(plan, QPLAN_END, dnsproxy_fwd, self->ctx);
return query_module_step(self, QPLAN_END, dnsproxy_fwd);
}
void dnsproxy_unload(struct query_module *self)
......
......@@ -29,6 +29,5 @@ extern const yp_item_t scheme_mod_dnsproxy[];
int check_mod_dnsproxy(conf_check_t *args);
/*! \brief Module interface. */
int dnsproxy_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone);
int dnsproxy_load(struct query_module *self);
void dnsproxy_unload(struct query_module *self);
......@@ -215,8 +215,7 @@ static struct fstrm_writer* dnstap_writer(const char *path)
return dnstap_file_writer(path);
}
int dnstap_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone)
int dnstap_load(struct query_module *self)
{
assert(self);
......@@ -282,10 +281,10 @@ int dnstap_load(struct query_plan *plan, struct query_module *self,
/* Hook to the query plan. */
if (log_queries) {
query_plan_step(plan, QPLAN_BEGIN, dnstap_message_log_query, self->ctx);
query_module_step(self, QPLAN_BEGIN, dnstap_message_log_query);
}
if (log_responses) {
query_plan_step(plan, QPLAN_END, dnstap_message_log_response, self->ctx);
query_module_step(self, QPLAN_END, dnstap_message_log_response);
}
return KNOT_EOK;
......
......@@ -24,6 +24,5 @@ extern const yp_item_t scheme_mod_dnstap[];
int check_mod_dnstap(conf_check_t *args);
/*! \brief Module interface. */
int dnstap_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone);
int dnstap_load(struct query_module *self);
void dnstap_unload(struct query_module *self);
......@@ -38,10 +38,9 @@ int noudp_begin(int state, knot_pkt_t *pkt, struct query_data *qdata, void *ctx)
return state;
}
int noudp_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone)
int noudp_load(struct query_module *self)
{
query_plan_step(plan, QPLAN_BEGIN, noudp_begin, NULL);
query_module_step(self, QPLAN_BEGIN, noudp_begin);
return KNOT_EOK;
}
......
......@@ -22,7 +22,5 @@
extern const yp_item_t scheme_mod_noudp[];
int noudp_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone);
int noudp_load(struct query_module *self);
void noudp_unload(struct query_module *self);
......@@ -551,42 +551,41 @@ static char *conf_kasp_path(const knot_dname_t *zone)
return kasp_db;
}
int online_sign_load(struct query_plan *plan, struct query_module *module,
const knot_dname_t *zone)
int online_sign_load(struct query_module *module)
{
assert(module);
assert(zone);
assert(module->zone);
conf_val_t val = conf_zone_get(conf(), C_DNSSEC_SIGNING, zone);
conf_val_t val = conf_zone_get(conf(), C_DNSSEC_SIGNING, module->zone);
if (conf_bool(&val)) {
module_zone_error(zone, "incompatible with automatic signing");
module_zone_error(module->zone, "incompatible with automatic signing");
return KNOT_ENOTSUP;
}
char *kasp_path = conf_kasp_path(zone);
char *kasp_path = conf_kasp_path(module->zone);
if (!kasp_path) {
module_zone_error(zone, "KASP database is not configured");
module_zone_error(module->zone, "KASP database is not configured");
return KNOT_ERROR;
}
online_sign_ctx_t *ctx = NULL;
int r = online_sign_ctx_new(&ctx, zone, kasp_path);
int r = online_sign_ctx_new(&ctx, module->zone, kasp_path);
free(kasp_path);
if (r != KNOT_EOK) {
module_zone_error(zone, "failed to initialize signing key (%s)",
module_zone_error(module->zone, "failed to initialize signing key (%s)",
dnssec_strerror(r));
return KNOT_ERROR;
}
query_plan_step(plan, QPLAN_ANSWER, synth_answer, ctx);
query_plan_step(plan, QPLAN_ANSWER, sign_section, ctx);
module->ctx = ctx;
query_plan_step(plan, QPLAN_AUTHORITY, synth_authority, ctx);
query_plan_step(plan, QPLAN_AUTHORITY, sign_section, ctx);
query_module_step(module, QPLAN_ANSWER, synth_answer);
query_module_step(module, QPLAN_ANSWER, sign_section);
query_plan_step(plan, QPLAN_ADDITIONAL, sign_section, ctx);
query_module_step(module, QPLAN_AUTHORITY, synth_authority);
query_module_step(module, QPLAN_AUTHORITY, sign_section);
module->ctx = ctx;
query_module_step(module, QPLAN_ADDITIONAL, sign_section);
return KNOT_EOK;
}
......
......@@ -21,6 +21,5 @@
#define C_MOD_ONLINE_SIGN "\x0f""mod-online-sign"
extern const yp_item_t scheme_mod_online_sign[];
int online_sign_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone);
int online_sign_load(struct query_module *self);
void online_sign_unload(struct query_module *self);
......@@ -609,8 +609,7 @@ static int rosedb_query(int state, knot_pkt_t *pkt, struct query_data *qdata,
return KNOT_STATE_DONE;
}
int rosedb_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone)
int rosedb_load(struct query_module *self)
{
assert(self);
......@@ -623,7 +622,7 @@ int rosedb_load(struct query_plan *plan, struct query_module *self,
self->ctx = cache;
return query_plan_step(plan, QPLAN_BEGIN, rosedb_query, self->ctx);
return query_module_step(self, QPLAN_BEGIN, rosedb_query);
}
void rosedb_unload(struct query_module *self)
......
......@@ -28,6 +28,5 @@ extern const yp_item_t scheme_mod_rosedb[];
int check_mod_rosedb(conf_check_t *args);
/*! \brief Module interface. */
int rosedb_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone);
int rosedb_load(struct query_module *self);
void rosedb_unload(struct query_module *self);
......@@ -100,8 +100,7 @@ static int ratelimit_apply(int state, knot_pkt_t *pkt, struct query_data *qdata,
}
}
int rrl_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone)
int rrl_load(struct query_module *self)
{
assert(self);
......@@ -159,7 +158,7 @@ int rrl_load(struct query_plan *plan, struct query_module *self,
ctx->counters = self->stats;
self->ctx = ctx;
return query_plan_step(plan, QPLAN_END, ratelimit_apply, self->ctx);
return query_module_step(self, QPLAN_END, ratelimit_apply);
}
void rrl_unload(struct query_module *self)
......
......@@ -24,6 +24,5 @@ extern const yp_item_t scheme_mod_rrl[];
int check_mod_rrl(conf_check_t *args);
/*! \brief Module interface. */
int rrl_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone);
int rrl_load(struct query_module *self);
void rrl_unload(struct query_module *self);
......@@ -526,8 +526,7 @@ static int update_counters(int state, knot_pkt_t *pkt, struct query_data *qdata,
return state;
}
int stats_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone)
int stats_load(struct query_module *self)
{
assert(self);
......@@ -553,7 +552,7 @@ int stats_load(struct query_plan *plan, struct query_module *self,
stats->counters = self->stats;
self->ctx = stats;
return query_plan_step(plan, QPLAN_END, update_counters, self->ctx);
return query_module_step(self, QPLAN_END, update_counters);
}
void stats_unload(struct query_module *self)
......
......@@ -23,6 +23,5 @@
extern const yp_item_t scheme_mod_stats[];
/*! \brief Module interface. */
int stats_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone);
int stats_load(struct query_module *self);
void stats_unload(struct query_module *self);
......@@ -399,8 +399,7 @@ static int solve_synth_record(int state, knot_pkt_t *pkt, struct query_data *qda
return template_match(state, (synth_template_t *)ctx, pkt, qdata);
}
int synth_record_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone)
int synth_record_load(struct query_module *self)
{
assert(self);
......@@ -441,7 +440,7 @@ int synth_record_load(struct query_plan *plan, struct query_module *self,
self->ctx = tpl;
return query_plan_step(plan, QPLAN_ANSWER, solve_synth_record, self->ctx);
return query_module_step(self, QPLAN_ANSWER, solve_synth_record);
}
void synth_record_unload(struct query_module *self)
......
......@@ -28,6 +28,5 @@ extern const yp_item_t scheme_mod_synth_record[];
int check_mod_synth_record(conf_check_t *args);
/*! \brief Module interface. */
int synth_record_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone);
int synth_record_load(struct query_module *self);
void synth_record_unload(struct query_module *self);
......@@ -122,11 +122,12 @@ static int whoami_query(int state, knot_pkt_t *pkt, struct query_data *qdata, vo
return HIT;
}
int whoami_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone)
int whoami_load(struct query_module *self)
{
assert(self);
/* Hook to the query plan. */
query_plan_step(plan, QPLAN_ANSWER, whoami_query, NULL);
query_module_step(self, QPLAN_ANSWER, whoami_query);
return KNOT_EOK;
}
......
......@@ -23,6 +23,5 @@
extern const yp_item_t scheme_mod_whoami[];
/*! \brief Module interface. */
int whoami_load(struct query_plan *plan, struct query_module *self,
const knot_dname_t *zone);
int whoami_load(struct query_module *self);
void whoami_unload(struct query_module *self);
......@@ -110,6 +110,11 @@ int query_plan_step(struct query_plan *plan, int stage, qmodule_process_t proces
return KNOT_EOK;
}
int query_module_step(struct query_module *module, int stage, qmodule_process_t process)
{
return query_plan_step(module->plan, stage, process, module->ctx);
}
int mod_stats_add(struct query_module *module, const char *name, uint32_t count,
mod_idx_to_str_f idx)
{
......@@ -187,9 +192,10 @@ static_module_t *find_module(const yp_name_t *name)
}
struct query_module *query_module_open(conf_t *config, conf_mod_id_t *mod_id,
struct query_plan *plan, const knot_dname_t *zone,
knot_mm_t *mm)
{
if (config == NULL || mod_id == NULL) {
if (config == NULL || mod_id == NULL || plan == NULL) {
return NULL;
}
......@@ -206,8 +212,10 @@ struct query_module *query_module_open(conf_t *config, conf_mod_id_t *mod_id,
}
memset(module, 0, sizeof(struct query_module));
module->plan = plan;
module->mm = mm;
module->config = config;
module->zone = zone;
module->id = mod_id;
module->load = found->load;
module->unload = found->unload;
......
......@@ -77,7 +77,7 @@ struct query_module;
struct query_plan;
/* Module callback required API. */
typedef int (*qmodule_load_t)(struct query_plan *plan, struct query_module *self, const knot_dname_t *zone);
typedef int (*qmodule_load_t)(struct query_module *self);
typedef void (*qmodule_unload_t)(struct query_module *self);
typedef int (*qmodule_process_t)(int state, knot_pkt_t *pkt, struct query_data *qdata, void *ctx);
......@@ -110,9 +110,11 @@ typedef struct {
*/
struct query_module {
node_t node;
struct query_plan *plan;
knot_mm_t *mm;
void *ctx;
conf_t *config;
const knot_dname_t *zone;
conf_mod_id_t *id;
qmodule_load_t load;
qmodule_unload_t unload;
......@@ -196,8 +198,11 @@ void query_plan_free(struct query_plan *plan);
int query_plan_step(struct query_plan *plan, int stage, qmodule_process_t process,
void *ctx);
int query_module_step(struct query_module *module, int stage, qmodule_process_t process);
/*! \brief Open query module identified by name. */
struct query_module *query_module_open(conf_t *config, conf_mod_id_t *mod_id,
struct query_plan *plan, const knot_dname_t *zone,
knot_mm_t *mm);
/*! \brief Close query module. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment