Commit 80b6103e authored by Jan Včelák's avatar Jan Včelák 🚀

knot: merge zone_t and zone_data_t

also includes removal of knot_ prefixes from private API

close #205
parent ab91055d
......@@ -674,8 +674,7 @@ static int cmd_checkzone(int argc, char *argv[], unsigned flags)
/* Create zone loader context. */
zloader_t *l = NULL;
int ret = knot_zload_open(&l, zone->file, zone->name,
zone->enable_checks);
int ret = knot_zload_open(&l, zone);
if (ret != KNOT_EOK) {
log_zone_error("Could not open zone %s (%s).\n",
zone->name, knot_strerror(ret));
......@@ -684,7 +683,7 @@ static int cmd_checkzone(int argc, char *argv[], unsigned flags)
continue;
}
knot_zone_t *z = knot_zload_load(l);
zone_t *z = knot_zload_load(l);
if (z == NULL) {
log_zone_error("Loading of zone %s failed.\n",
zone->name);
......@@ -693,7 +692,7 @@ static int cmd_checkzone(int argc, char *argv[], unsigned flags)
continue;
}
knot_zone_deep_free(&z);
zone_deep_free(&z);
knot_zload_close(l);
log_zone_info("Zone %s OK.\n", zone->name);
}
......
......@@ -51,7 +51,7 @@ typedef struct remote_cmdargs_t {
typedef int (*remote_cmdf_t)(server_t*, remote_cmdargs_t*);
/*! \brief Callback prototype for per-zone operations. */
typedef int (remote_zonef_t)(server_t*, const knot_zone_t *);
typedef int (remote_zonef_t)(server_t*, const zone_t *);
/*! \brief Remote command table item. */
typedef struct remote_cmd_t {
......@@ -90,7 +90,7 @@ static int remote_rdata_apply(server_t *s, remote_cmdargs_t* a, remote_zonef_t *
}
knot_nameserver_t *ns = s->nameserver;
knot_zone_t *zone = NULL;
zone_t *zone = NULL;
int ret = KNOT_EOK;
/* Refresh specific zones. */
......@@ -117,56 +117,48 @@ static int remote_rdata_apply(server_t *s, remote_cmdargs_t* a, remote_zonef_t *
return ret;
}
/*! \brief Zone refresh callback. */
static int remote_zone_refresh(server_t *s, const knot_zone_t *z)
static void reschedule(server_t *server, event_t *timer, uint32_t time)
{
if (!s || !z) {
return KNOT_EINVAL;
}
assert(server);
assert(timer);
knot_nameserver_t *ns = s->nameserver;
evsched_t *sch = ((server_t *)knot_ns_get_data(ns))->sched;
zonedata_t *zd = (zonedata_t *)knot_zone_data(z);
if (!sch || !zd) {
knot_nameserver_t *nameserver = server->nameserver;
evsched_t *scheduler = ((server_t *)knot_ns_get_data(nameserver))->sched;
evsched_cancel(scheduler, timer);
evsched_schedule(scheduler, timer, time);
}
/*! \brief Zone refresh callback. */
static int remote_zone_refresh(server_t *server, const zone_t *zone)
{
if (!server || !zone) {
return KNOT_EINVAL;
}
/* Expire REFRESH timer. */
if (zd->xfr_in.timer) {
evsched_cancel(sch, zd->xfr_in.timer);
evsched_schedule(sch, zd->xfr_in.timer,
knot_random_uint32_t() % 1000);
if (zone->xfr_in.timer) {
reschedule(server, zone->xfr_in.timer, knot_random_uint32_t() % 1000);
}
return KNOT_EOK;
}
/*! \brief Zone flush callback. */
static int remote_zone_flush(server_t *s, const knot_zone_t *z)
static int remote_zone_flush(server_t *server, const zone_t *zone)
{
if (!s || !z) {
return KNOT_EINVAL;
}
knot_nameserver_t *ns = s->nameserver;
evsched_t *sch = ((server_t *)knot_ns_get_data(ns))->sched;
zonedata_t *zd = (zonedata_t *)knot_zone_data(z);
if (!sch || !zd) {
if (!server || !zone) {
return KNOT_EINVAL;
}
/* Expire IXFR sync timer. */
if (zd->ixfr_dbsync) {
evsched_cancel(sch, zd->ixfr_dbsync);
evsched_schedule(sch, zd->ixfr_dbsync,
knot_random_uint32_t() % 1000);
if (zone->ixfr_dbsync) {
reschedule(server, zone->ixfr_dbsync, knot_random_uint32_t() % 1000);
}
return KNOT_EOK;
}
/*! \brief Sign zone callback. */
static int remote_zone_sign(server_t *server, const knot_zone_t *zone)
static int remote_zone_sign(server_t *server, const zone_t *zone)
{
if (!server || !zone) {
return KNOT_EINVAL;
......@@ -177,9 +169,11 @@ static int remote_zone_sign(server_t *server, const knot_zone_t *zone)
free(zone_name);
uint32_t refresh_at = 0;
zones_cancel_dnssec((knot_zone_t *)zone);
zones_dnssec_sign((knot_zone_t *)zone, true, &refresh_at);
zones_schedule_dnssec((knot_zone_t *)zone, refresh_at);
zone_t *wzone = (zone_t *)zone;
zones_cancel_dnssec(wzone);
zones_dnssec_sign(wzone, true, &refresh_at);
zones_schedule_dnssec(wzone, refresh_at);
return KNOT_EOK;
}
......@@ -224,12 +218,12 @@ static int remote_c_status(server_t *s, remote_cmdargs_t* a)
return KNOT_EOK;
}
static char *dnssec_info(const zonedata_t *zd, char *buf, size_t buf_size)
static char *dnssec_info(const zone_t *zone, char *buf, size_t buf_size)
{
assert(zd && zd->dnssec_timer);
assert(zone && zone->dnssec_timer);
assert(buf);
time_t diff_time = zd->dnssec_timer->tv.tv_sec;
time_t diff_time = zone->dnssec_timer->tv.tv_sec;
struct tm *t = localtime(&diff_time);
size_t written = strftime(buf, buf_size, "%c", t);
......@@ -258,15 +252,13 @@ static int remote_c_zonestatus(server_t *s, remote_cmdargs_t* a)
knot_zonedb_iter_t it;
knot_zonedb_iter_begin(ns->zone_db, &it);
while(!knot_zonedb_iter_finished(&it)) {
const knot_zone_t *zone = knot_zonedb_iter_val(&it);
zonedata_t *zd = (zonedata_t *)zone->data;
const zone_t *zone = knot_zonedb_iter_val(&it);
/* Fetch latest serial. */
const knot_rrset_t *soa_rrs = 0;
uint32_t serial = 0;
knot_zone_contents_t *contents = knot_zone_get_contents(zone);
if (contents) {
soa_rrs = knot_node_rrset(knot_zone_contents_apex(contents),
if (zone->contents) {
soa_rrs = knot_node_rrset(zone->contents->apex,
KNOT_RRTYPE_SOA);
assert(soa_rrs != NULL);
serial = knot_rdata_soa_serial(soa_rrs);
......@@ -276,18 +268,18 @@ static int remote_c_zonestatus(server_t *s, remote_cmdargs_t* a)
const char *state = NULL;
if (serial == 0) {
state = "bootstrap";
} else if (zd->xfr_in.has_master) {
} else if (zone->xfr_in.has_master) {
state = "xfer";
}
/* Evaluate zone state. */
char *when = NULL;
if (zd->xfr_in.state == XFR_PENDING) {
if (zone->xfr_in.state == XFR_PENDING) {
when = strdup("pending");
} else if (zd->xfr_in.timer && zd->xfr_in.timer->tv.tv_sec != 0) {
} else if (zone->xfr_in.timer && zone->xfr_in.timer->tv.tv_sec != 0) {
struct timeval now, dif;
gettimeofday(&now, 0);
timersub(&zd->xfr_in.timer->tv, &now, &dif);
timersub(&zone->xfr_in.timer->tv, &now, &dif);
when = malloc(64);
if (when == NULL) {
ret = KNOT_ENOMEM;
......@@ -315,13 +307,13 @@ static int remote_c_zonestatus(server_t *s, remote_cmdargs_t* a)
char dnssec_buf[128] = { '\0' };
int n = snprintf(buf, sizeof(buf),
"%s\ttype=%s | serial=%u | %s %s | %s %s\n",
zd->conf->name,
zd->xfr_in.has_master ? "slave" : "master",
zone->conf->name,
zone->xfr_in.has_master ? "slave" : "master",
serial,
state ? state : "",
when ? when : "",
zd->conf->dnssec_enable ? "automatic DNSSEC, resigning at:" : "",
zd->conf->dnssec_enable ? dnssec_info(zd, dnssec_buf, sizeof(dnssec_buf)) : "");
zone->conf->dnssec_enable ? "automatic DNSSEC, resigning at:" : "",
zone->conf->dnssec_enable ? dnssec_info(zone, dnssec_buf, sizeof(dnssec_buf)) : "");
free(when);
if (n < 0 || (size_t)n > rb) {
*dst = '\0';
......@@ -762,7 +754,6 @@ int remote_query_append(knot_pkt_t *qry, knot_rrset_t *data)
return KNOT_EOK;
}
int remote_query_sign(uint8_t *wire, size_t *size, size_t maxlen,
const knot_tsig_key_t *key)
{
......
......@@ -27,7 +27,7 @@
#include "libknot/util/debug.h"
#include "knot/zone/zone.h"
static int init_dnssec_structs(const knot_zone_t *zone,
static int init_dnssec_structs(const zone_t *zone,
knot_zone_keys_t *zone_keys,
knot_dnssec_policy_t *policy,
knot_update_serial_t soa_up, bool force)
......@@ -36,10 +36,7 @@ static int init_dnssec_structs(const knot_zone_t *zone,
assert(zone_keys);
assert(policy);
zonedata_t *zone_data = zone->data;
assert(zone_data);
conf_zone_t *config = zone_data->conf;
conf_zone_t *config = zone->conf;
assert(config);
// Read zone keys from disk
......@@ -69,7 +66,7 @@ static int init_dnssec_structs(const knot_zone_t *zone,
return KNOT_EOK;
}
static int zone_sign(knot_zone_t *zone, knot_changeset_t *out_ch, bool force,
static int zone_sign(zone_t *zone, knot_changeset_t *out_ch, bool force,
knot_update_serial_t soa_up, uint32_t *refresh_at,
uint32_t new_serial)
{
......@@ -87,8 +84,7 @@ static int zone_sign(knot_zone_t *zone, knot_changeset_t *out_ch, bool force,
dbg_dnssec_verb("Changeset empty before generating NSEC chain: %d\n",
knot_changeset_is_empty(out_ch));
conf_zone_t *zone_config = ((zonedata_t *)knot_zone_data(zone))->conf;
if (!zone_config->dnssec_enable) {
if (!zone->conf->dnssec_enable) {
log_zone_warning("%s DNSSEC not enabled.\n", msgpref);
free(msgpref);
return KNOT_EOK;
......@@ -163,7 +159,7 @@ static int zone_sign(knot_zone_t *zone, knot_changeset_t *out_ch, bool force,
return KNOT_EOK;
}
int knot_dnssec_zone_sign(knot_zone_t *zone, knot_changeset_t *out_ch,
int knot_dnssec_zone_sign(zone_t *zone, knot_changeset_t *out_ch,
knot_update_serial_t soa_up, uint32_t *refresh_at,
uint32_t new_serial)
{
......@@ -174,7 +170,7 @@ int knot_dnssec_zone_sign(knot_zone_t *zone, knot_changeset_t *out_ch,
return zone_sign(zone, out_ch, false, soa_up, refresh_at, new_serial);
}
int knot_dnssec_zone_sign_force(knot_zone_t *zone,
int knot_dnssec_zone_sign_force(zone_t *zone,
knot_changeset_t *out_ch, uint32_t *refresh_at,
uint32_t new_serial)
{
......@@ -186,7 +182,7 @@ int knot_dnssec_zone_sign_force(knot_zone_t *zone,
new_serial);
}
int knot_dnssec_sign_changeset(const knot_zone_t *zone,
int knot_dnssec_sign_changeset(const zone_t *zone,
const knot_changeset_t *in_ch,
knot_changeset_t *out_ch,
knot_update_serial_t soa_up,
......@@ -215,7 +211,7 @@ int knot_dnssec_sign_changeset(const knot_zone_t *zone,
return ret;
}
char *zname = knot_dname_to_str(knot_zone_name(zone));
char *zname = knot_dname_to_str(zone->name);
char *msgpref = sprintf_alloc("DNSSEC: Zone %s -", zname);
free(zname);
if (msgpref == NULL) {
......
......@@ -42,7 +42,7 @@
*
* \return Error code, KNOT_EOK if successful.
*/
int knot_dnssec_zone_sign(knot_zone_t *zone, knot_changeset_t *out_ch,
int knot_dnssec_zone_sign(zone_t *zone, knot_changeset_t *out_ch,
knot_update_serial_t soa_up, uint32_t *refresh_at,
uint32_t new_serial);
......@@ -56,7 +56,7 @@ int knot_dnssec_zone_sign(knot_zone_t *zone, knot_changeset_t *out_ch,
*
* \return Error code, KNOT_EOK if successful.
*/
int knot_dnssec_zone_sign_force(knot_zone_t *zone, knot_changeset_t *out_ch,
int knot_dnssec_zone_sign_force(zone_t *zone, knot_changeset_t *out_ch,
uint32_t *refresh_at, uint32_t new_serial);
/*!
......@@ -72,13 +72,12 @@ int knot_dnssec_zone_sign_force(knot_zone_t *zone, knot_changeset_t *out_ch,
*
* \return Error code, KNOT_EOK if successful.
*/
int knot_dnssec_sign_changeset(const knot_zone_t *zone,
int knot_dnssec_sign_changeset(const zone_t *zone,
const knot_changeset_t *in_ch,
knot_changeset_t *out_ch,
knot_update_serial_t soa_up,
uint32_t *refresh_at, uint32_t new_serial,
hattrie_t **sorted_changes);
#endif // _KNOT_DNSSEC_ZONE_EVENTS_H_
/*! @} */
......@@ -1302,7 +1302,7 @@ int knot_zone_sign_update_soa(const knot_rrset_t *soa,
/*!
* \brief Sign changeset created by DDNS or zone-diff.
*/
int knot_zone_sign_changeset(const knot_zone_t *zone,
int knot_zone_sign_changeset(const zone_t *zone,
const knot_changeset_t *in_ch,
knot_changeset_t *out_ch,
hattrie_t **sorted_changes,
......
......@@ -105,7 +105,7 @@ bool knot_zone_sign_soa_expired(const knot_zone_contents_t *zone,
*
* \return Error code, KNOT_EOK if successful.
*/
int knot_zone_sign_changeset(const knot_zone_t *zone,
int knot_zone_sign_changeset(const zone_t *zone,
const knot_changeset_t *in_ch,
knot_changeset_t *out_ch,
hattrie_t **sorted_changes,
......
......@@ -54,7 +54,7 @@ static void check_integrity(server_t *server) {
knot_zonedb_iter_t it;
knot_zonedb_iter_begin(zonedb, &it);
while(!knot_zonedb_iter_finished(&it)) {
knot_zone_t *zone = knot_zonedb_iter_val(&it);
zone_t *zone = knot_zonedb_iter_val(&it);
char *zname = knot_dname_to_str(zone->name);
log_server_info("Integrity check for zone %s\n", zname);
......@@ -258,7 +258,6 @@ int main(int argc, char **argv)
if (capng_have_capability(CAPNG_EFFECTIVE, CAP_SETPCAP)) {
capng_clear(CAPNG_SELECT_BOTH);
/* Retain ability to set capabilities and FS access. */
capng_type_t tp = CAPNG_EFFECTIVE|CAPNG_PERMITTED;
capng_update(CAPNG_ADD, tp, CAP_SETPCAP);
......
......@@ -201,8 +201,7 @@ int axfr_answer(knot_pkt_t *pkt, knot_nameserver_t *ns, struct query_data *qdata
NS_NEED_VALID_ZONE(qdata, KNOT_RCODE_NOTAUTH);
/* Need valid transaction security. */
zonedata_t *zone_data = (zonedata_t *)knot_zone_data(qdata->zone);
NS_NEED_AUTH(zone_data->xfr_out, qdata);
NS_NEED_AUTH(qdata->zone->xfr_out, qdata);
ret = axfr_answer_init(qdata);
if (ret != KNOT_EOK) {
......
......@@ -474,9 +474,9 @@ static int solve_name(int state, knot_pkt_t *pkt, struct query_data *qdata)
&qdata->previous);
switch(ret) {
case KNOT_ZONE_NAME_FOUND:
case ZONE_NAME_FOUND:
return name_found(pkt, qdata);
case KNOT_ZONE_NAME_NOT_FOUND:
case ZONE_NAME_NOT_FOUND:
return name_not_found(pkt, qdata);
case KNOT_EOUTOFZONE:
assert(state == FOLLOW); /* CNAME/DNAME chain only. */
......@@ -660,8 +660,7 @@ int internet_answer(knot_pkt_t *response, struct query_data *qdata)
/* No applicable ACL, refuse transaction security. */
if (knot_pkt_have_tsig(qdata->query)) {
/* We have been challenged... */
zonedata_t *zone_data = (zonedata_t *)knot_zone_data(qdata->zone);
NS_NEED_AUTH(zone_data->xfr_out, qdata);
NS_NEED_AUTH(qdata->zone->xfr_out, qdata);
}
/* Get answer to QNAME. */
......
......@@ -55,7 +55,7 @@ int internet_answer(knot_pkt_t *resp, struct query_data *qdata);
/*! \brief Require valid zone or return error code. */
#define NS_NEED_VALID_ZONE(qdata, error_rcode) \
switch(knot_zone_state((qdata)->zone)) { \
switch(zone_state((qdata)->zone)) { \
case KNOT_EOK: \
break; \
case KNOT_ENOENT: \
......
......@@ -123,7 +123,7 @@ static int ixfr_process_changeset(knot_pkt_t *pkt, const void *item, struct xfr_
#undef IXFR_SAFE_PUT
static int ixfr_load_chsets(knot_changesets_t **chgsets, const knot_zone_t *zone,
static int ixfr_load_chsets(knot_changesets_t **chgsets, const zone_t *zone,
const knot_rrset_t *their_soa)
{
assert(chgsets);
......@@ -170,8 +170,7 @@ static int ixfr_query_check(struct query_data *qdata)
NS_NEED_QNAME(qdata, their_soa->owner, KNOT_RCODE_FORMERR);
/* Need valid transaction security. */
zonedata_t *zone_data = (zonedata_t *)knot_zone_data(qdata->zone);
NS_NEED_AUTH(zone_data->xfr_out, qdata);
NS_NEED_AUTH(qdata->zone->xfr_out, qdata);
return NS_PROC_DONE;
}
......
......@@ -172,7 +172,7 @@ int knot_ns_process_axfrin(knot_nameserver_t *nameserver, knot_ns_xfr_t *xfr)
knot_zone_contents_t *zone = constr_zone->contents;
assert(zone != NULL);
log_zone_info("%s Serial %u -> %u\n", xfr->msg,
knot_zone_serial(knot_zone_contents(xfr->zone)),
knot_zone_serial(xfr->zone->contents),
knot_zone_serial(zone));
dbg_ns_verb("ns_process_axfrin: adjusting zone.\n");
......@@ -220,7 +220,7 @@ int knot_ns_switch_zone(knot_nameserver_t *nameserver,
/* Zone must not be looked-up from server, as it may be a different zone if
* a reload occurs when transfer is pending. */
knot_zone_t *z = xfr->zone;
zone_t *z = xfr->zone;
if (z == NULL) {
char *name = knot_dname_to_str(knot_node_owner(
knot_zone_contents_apex(zone)));
......@@ -276,7 +276,7 @@ int knot_ns_process_ixfrin(knot_nameserver_t *nameserver,
// find zone associated with the changesets
/* Must not search for the zone in zonedb as it may fetch a
* different zone than the one the transfer started on. */
knot_zone_t *zone = xfr->zone;
zone_t *zone = xfr->zone;
if (zone == NULL) {
dbg_ns("No zone found for incoming IXFR!\n");
knot_changesets_free(
......@@ -290,8 +290,7 @@ int knot_ns_process_ixfrin(knot_nameserver_t *nameserver,
case XFRIN_RES_SOA_ONLY: {
// compare the SERIAL from the changeset with the zone's
// serial
const knot_node_t *apex = knot_zone_contents_apex(
knot_zone_contents(zone));
const knot_node_t *apex = zone->contents->apex;
if (apex == NULL) {
return KNOT_ERROR;
}
......
......@@ -109,7 +109,7 @@ typedef struct knot_ns_xfr {
size_t wire_size;
size_t wire_maxlen;
void *data;
knot_zone_t *zone;
zone_t *zone;
char* zname;
knot_zone_contents_t *new_contents;
char *msg;
......
......@@ -108,7 +108,7 @@ static int ns_put_covering_nsec3(const knot_zone_contents_t *zone,
return KNOT_EOK;
}
if (match == KNOT_ZONE_NAME_FOUND || prev == NULL){
if (match == ZONE_NAME_FOUND || prev == NULL){
// if run-time collision => SERVFAIL
return KNOT_EOK;
}
......
......@@ -22,7 +22,7 @@
#include "knot/conf/conf.h"
/* Forward decls. */
static const knot_zone_t *answer_zone_find(const knot_pkt_t *query, knot_zonedb_t *zonedb);
static const zone_t *answer_zone_find(const knot_pkt_t *query, knot_zonedb_t *zonedb);
static int prepare_answer(const knot_pkt_t *query, knot_pkt_t *resp, knot_process_t *ctx);
static int query_internet(knot_pkt_t *pkt, knot_process_t *ctx);
static int query_chaos(knot_pkt_t *pkt, knot_process_t *ctx);
......@@ -452,12 +452,12 @@ static int query_chaos(knot_pkt_t *pkt, knot_process_t *ctx)
}
/*! \brief Find zone for given question. */
static const knot_zone_t *answer_zone_find(const knot_pkt_t *query, knot_zonedb_t *zonedb)
static const zone_t *answer_zone_find(const knot_pkt_t *query, knot_zonedb_t *zonedb)
{
uint16_t qtype = knot_pkt_qtype(query);
uint16_t qclass = knot_pkt_qclass(query);
const knot_dname_t *qname = knot_pkt_qname(query);
const knot_zone_t *zone = NULL;
const zone_t *zone = NULL;
// search for zone only for IN and ANY classes
if (qclass != KNOT_CLASS_IN && qclass != KNOT_CLASS_ANY) {
......
......@@ -74,12 +74,12 @@ struct process_query_param {
/*! \brief Query processing intermediate data. */
struct query_data {
uint16_t rcode; /*!< Resulting RCODE. */
uint16_t rcode_tsig; /*!< Resulting TSIG RCODE. */
uint16_t packet_type; /*!< Resolved packet type. */
knot_pkt_t *query; /*!< Query to be solved. */
const knot_zone_t *zone; /*!< Zone from which is answered. */
list_t wildcards; /*!< Visited wildcards. */
uint16_t rcode; /*!< Resulting RCODE. */
uint16_t rcode_tsig; /*!< Resulting TSIG RCODE. */
uint16_t packet_type; /*!< Resolved packet type. */
knot_pkt_t *query; /*!< Query to be solved. */
const zone_t *zone; /*!< Zone from which is answered. */
list_t wildcards; /*!< Visited wildcards. */
/* Current processed name and nodes. */
const knot_node_t *node, *encloser, *previous;
......
......@@ -15,7 +15,7 @@ static int update_forward(struct query_data *qdata)
/*! \todo This will be implemented when RESPONSE and REQUEST processors
* are written. */
#if 0
const knot_zone_t* zone = qdata->zone;
const zone_t* zone = qdata->zone;
knot_pkt_t *query = qdata->pkt;
const sockaddr_t *from = &qdata->param->query_source;
......@@ -66,7 +66,7 @@ static int update_process(knot_pkt_t *resp, struct query_data *qdata)
{
/*! \todo Reusing the API for compatibility reasons. */
knot_rcode_t rcode = qdata->rcode;
int ret = zones_process_update_auth((knot_zone_t *)qdata->zone, qdata->query,
int ret = zones_process_update_auth((zone_t *)qdata->zone, qdata->query,
&rcode,
&qdata->param->query_source,
qdata->sign.tsig_key);
......@@ -77,7 +77,7 @@ static int update_process(knot_pkt_t *resp, struct query_data *qdata)
static int update_prereq_check(struct query_data *qdata)
{
knot_pkt_t *query = qdata->query;
const knot_zone_contents_t *contents = knot_zone_contents(qdata->zone);
const knot_zone_contents_t *contents = qdata->zone->contents;
/*
* 2) DDNS Prerequisities Section processing (RFC2136, Section 3.2).
......@@ -106,23 +106,24 @@ int update_answer(knot_pkt_t *pkt, knot_nameserver_t *ns, struct query_data *qda
* Most servers use NOTAUTH from RFC2136. */
NS_NEED_VALID_ZONE(qdata, KNOT_RCODE_NOTAUTH);
zone_t *zone = (zone_t *)qdata->zone;
/* Allow pass-through of an unknown TSIG in DDNS forwarding (must have zone). */
zonedata_t *zone_data = (zonedata_t *)knot_zone_data(qdata->zone);
if (zone_data->xfr_in.has_master) {
if (zone->xfr_in.has_master) {
return update_forward(qdata);
}
/* Need valid transaction security. */
NS_NEED_AUTH(zone_data->update_in, qdata);
NS_NEED_AUTH(zone->update_in, qdata);
/*
* Check if UPDATE not running already.
*/
if (pthread_mutex_trylock(&zone_data->ddns_lock) != 0) {
if (pthread_mutex_trylock(&zone->ddns_lock) != 0) {
qdata->rcode = KNOT_RCODE_SERVFAIL;
log_zone_error("Failed to process UPDATE for "
"zone %s: Another UPDATE in progress.\n",
zone_data->conf->name);
zone->conf->name);
return NS_PROC_FAIL;
}
......@@ -131,16 +132,16 @@ int update_answer(knot_pkt_t *pkt, knot_nameserver_t *ns, struct query_data *qda
/* Check prerequisites. */
if (update_prereq_check(qdata) != KNOT_EOK) {
pthread_mutex_unlock(&zone_data->ddns_lock);
pthread_mutex_unlock(&zone->ddns_lock);
return NS_PROC_FAIL;
}
/* Process UPDATE. */
if (update_process(pkt, qdata) != KNOT_EOK) {
pthread_mutex_unlock(&zone_data->ddns_lock);
pthread_mutex_unlock(&zone->ddns_lock);
return NS_PROC_FAIL;
}
pthread_mutex_unlock(&zone_data->ddns_lock);
pthread_mutex_unlock(&zone->ddns_lock);
return NS_PROC_DONE;
}
......@@ -126,7 +126,6 @@ typedef int (*journal_apply_t)(journal_t *j, journal_node_t *n);
/* HEADER = magic, crc, max_entries, qhead, qtail */
#define JOURNAL_HSIZE (MAGIC_LENGTH + sizeof(crc_t) + sizeof(uint16_t) * 3)
/*!
* \brief Create new journal.
*
......@@ -197,7 +196,6 @@ int journal_read(journal_t *journal, uint64_t id, journal_cmp_t cf, char *dst);
*/
int journal_read_node(journal_t *journal, journal_node_t *n, char *dst);
/*!
* \brief Write journal entry data.
*
......
......@@ -97,18 +97,17 @@ int notify_process_response(knot_pkt_t *notify, int msgid)
}
static int notify_reschedule(knot_nameserver_t *ns,
const knot_zone_t *zone,
const zone_t *zone,
sockaddr_t *from)
{
dbg_ns("%s(%p, %p, %p)\n", __func__, ns, zone, from);
if (ns == NULL || zone == NULL || zone->data == NULL) {
if (ns == NULL || zone == NULL) {
return KNOT_EINVAL;
}
/* Cancel REFRESH/RETRY timer. */
server_t *server = ns->data;
zonedata_t *zone_data = (zonedata_t *)knot_zone_data(zone);
event_t *refresh_ev = zone_data->xfr_in.timer;
event_t *refresh_ev = zone->xfr_in.timer;
if (refresh_ev && server) {
dbg_ns("%s: expiring REFRESH timer\n", __func__);
evsched_cancel(server->sched, refresh_ev);
......@@ -138,12 +137,11 @@ int internet_notify(knot_pkt_t *pkt, knot_nameserver_t *ns, struct query_data *q
NS_NEED_VALID_ZONE(qdata, KNOT_RCODE_NOTAUTH);
/* Need valid transaction security. */
zonedata_t *zone_data = (zonedata_t *)knot_zone_data(qdata->zone);
NS_NEED_AUTH(zone_data->notify_in, qdata);
NS_NEED_AUTH(qdata->zone->notify_in, qdata);
/* Reserve space for TSIG. */
knot_pkt_tsig_set(pkt, qdata->sign.tsig_key);
/* SOA RR in answer may be included, recover serial. */
unsigned serial = 0;
const knot_pktsection_t *answer = knot_pkt_section(qdata->query, KNOT_ANSWER);
......
......@@ -29,6 +29,7 @@
#include "libknot/dnssec/random.h"
#include "common/descriptor.h"
#include "common/errors.h"
#include "knot/zone/zone.h"
/* Hopscotch defines. */
#define HOP_LEN (sizeof(unsigned)*8)
......@@ -128,14 +129,15 @@ static uint8_t rrl_clsid(rrl_req_t *p)
}
static int rrl_clsname(char *dst, size_t maxlen, uint8_t cls,
rrl_req_t *req, const knot_zone_t *zone)
rrl_req_t *req, const zone_t *zone)
{
/* Fallback zone (for errors etc.) */
const knot_dname_t *dn = (const knot_dname_t*)"\x00";
/* Found associated zone. */
if (zone != NULL)
dn = knot_zone_name(zone);
if (zone != NULL) {
dn = zone->name;
}
switch (cls) {
case CLS_ERROR: /* Could be a non-existent zone or garbage. */
......@@ -155,7 +157,7 @@ static int rrl_clsname(char *dst, size_t maxlen, uint8_t cls,
}
static int rrl_classify(char *dst, size_t maxlen, const sockaddr_t *a,
rrl_req_t *p, const knot_zone_t *z, uint32_t seed)
rrl_req_t *p, const zone_t *z, uint32_t seed)
{
if (!dst || !p || !a || maxlen == 0) {
return KNOT_EINVAL;
......@@ -355,7 +357,7 @@ int rrl_setlocks(rrl_table_t *rrl, unsigned granularity)
}
rrl_item_t* rrl_hash(rrl_table_t *t, const sockaddr_t *a, rrl_req_t *p,
const knot_zone_t *zone, uint32_t stamp, int *lock)
const zone_t *zone, uint32_t stamp, int *lock)
{
char buf[RRL_CLSBLK_MAXLEN];
int len = rrl_classify(buf, sizeof(buf), a, p, zone, t->seed);
......@@ -420,7 +422,7 @@ rrl_item_t* rrl_hash(rrl_table_t *t, const sockaddr_t *a, rrl_req_t *p,
}
int rrl_query(rrl_table_t *rrl, const sockaddr_t *a, rrl_req_t *req,
const knot_zone_t *zone)
const zone_t *zone)
{
if (!rrl || !req || !a) return KNOT_EINVAL;
......
......@@ -31,12 +31,13 @@
#include <pthread.h>
#include "common/sockaddr.h"
#include "libknot/packet/pkt.h"
#include "knot/zone/zone.h"
/* Defaults */
#define RRL_SLIP_MAX 100
#define RRL_LOCK_GRANULARITY 32 /* Last digit granularity */
struct zone_t;
/*!