Commit cd5c5664 authored by Vitezslav Kriz's avatar Vitezslav Kriz

zone-size-limit: added function to measure size of zone contents

parent 85f3217b
......@@ -374,11 +374,9 @@ static int ixfrin_answer_init(struct answer_data *data)
data->ext = proc;
data->ext_cleanup = &ixfrin_cleanup;
/// \TODO Temporary solution, because not every zone input is checked
/// measured. Used only for measure size of zone.
err_handler_logger_t handler;
handler._cb.cb = err_handler_logger;
zone_do_sem_checks(proc->zone->contents, false, &handler._cb);
/// \TODO Temporary solution, because not every zone input is checked by
/// semantic checks. And zone size is not set properly.
zone_contents_measure_size(proc->zone->contents);
return KNOT_EOK;
}
......@@ -671,7 +669,6 @@ static int process_ixfrin_packet(knot_pkt_t *pkt, struct answer_data *adata)
if (ixfr->add_size > ixfr->del_size &&
(zone_size + ixfr->add_size - ixfr->del_size) > size_limit) {
log_zone_debug(ixfr->zone->name, "zone_size:%zu + add_size:%zu + del_size:%zu", zone_size, ixfr->add_size, ixfr->del_size);
IXFRIN_LOG(LOG_WARNING, "zone size exceeded, limit %ld",
size_limit);
return KNOT_STATE_FAIL;
......
......@@ -1129,3 +1129,21 @@ bool zone_contents_is_empty(const zone_contents_t *zone)
{
return !zone || !node_rrtype_exists(zone->apex, KNOT_RRTYPE_SOA);
}
static int measure_size(const zone_node_t *node, void *data){
size_t *size = data;
int rrset_count = node->rrset_count;
for (int i = 0; i < rrset_count; i++) {
knot_rrset_t rrset = node_rrset_at(node, i);
*size += knot_rrset_size(&rrset);
}
return KNOT_EOK;
}
size_t zone_contents_measure_size(zone_contents_t *zone)
{
zone->size = 0;
zone_contents_tree_apply_inorder(zone, measure_size, &zone->size);
return zone->size;
}
......@@ -283,4 +283,7 @@ bool zone_contents_is_signed(const zone_contents_t *zone);
*/
bool zone_contents_is_empty(const zone_contents_t *zone);
size_t zone_contents_measure_size(zone_contents_t *zone);
/*! @} */
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