summaryrefslogtreecommitdiffstats
path: root/src/knot/zone/measure.h
blob: 5c73c91f57511ef935b8a037d2021d37b3d81d11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*  Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#pragma once

#include "knot/updates/zone-update.h"

typedef enum {
	MEASURE_SIZE_NONE = 0, // don't measure size of zone
	MEASURE_SIZE_WHOLE,    // measure complete size of zone nodes
	MEASURE_SIZE_DIFF,     // measure difference in size for bi-nodes in zone update
} measure_size_t;

typedef enum {
	MEASURE_TTL_NONE = 0,  // don't measure max TTL of zone records
	MEASURE_TTL_WHOLE,     // measure max TTL among all zone records
	MEASURE_TTL_DIFF,      // check out zone update (bi-nodes) if the max TTL is affected
	MEASURE_TTL_LIMIT,     // measure max TTL whole; stop if a specific value is reached
} measure_ttl_t;

typedef struct {
	measure_size_t how_size;
	measure_ttl_t how_ttl;
	ssize_t zone_size;
	uint32_t max_ttl;
	uint32_t rem_max_ttl;
	uint32_t limit_max_ttl;
} measure_t;

/*! \brief Initialize measure struct. */
measure_t knot_measure_init(bool measure_whole, bool measure_diff);

/*!
 * \brief Measure one node's size and max TTL, collecting into measure struct.
 *
 * \param node   Node to be measured.
 * \param m      Measure context with instructions and results.
 *
 * \return False if no more measure is needed.
 * \note You will probably ignore the return value.
 */
bool knot_measure_node(zone_node_t *node, measure_t *m);

/*!
 * \brief Collect the measured results and update the new zone with measured properties.
 *
 * \param zone     Zone.
 * \param m        Measured results.
 */
void knot_measure_finish_zone(measure_t *m, zone_contents_t *zone);

/*!
 * \brief Collect the measured results and update the new zone with measured properties.
 *
 * \param update   Zone update with the zone.
 * \param m        Measured results.
 */
void knot_measure_finish_update(measure_t *m, zone_update_t *update);