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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
/*!
* \file node.h
*
* \author Lubos Slovak <lubos.slovak@nic.cz>
*
* \brief Structure representing one node in domain name tree and API for
* manipulating it.
*
* \addtogroup libknot
* @{
*/
/* Copyright (C) 2011 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _KNOT_NODE_H_
#define _KNOT_NODE_H_
#include "dname.h"
#include "common/skip-list.h"
#include "rrset.h"
#include "common/tree.h"
#include "common/general-tree.h"
struct knot_zone;
/*----------------------------------------------------------------------------*/
/*!
* \brief Structure representing one node in a domain name tree, i.e. one domain
* name in a zone.
*
* RRSets are ordered by type and stored in a skip-list to allow fast lookup.
*/
struct knot_node {
knot_dname_t *owner; /*!< Domain name being the owner of this node. */
struct knot_node *parent; /*!< Parent node in the name hierarchy. */
/*! \brief Type-ordered list of RRSets belonging to this node. */
general_tree_t *rrset_tree;
unsigned short rrset_count; /*!< Number of RRSets stored in the node. */
/*! \brief Wildcard node being the direct descendant of this node. */
struct knot_node *wildcard_child;
/*!
* \brief Previous node in canonical order.
*
* Only authoritative nodes or delegation points are referenced by this,
* as only they may contain NSEC records needed for authenticating
* negative answers.
*/
struct knot_node *prev;
struct knot_node *next;
/*!
* \brief NSEC3 node corresponding to this node.
*
* Such NSEC3 node has owner in form of the hashed domain name of this
* node prepended as a single label to the zone name.
*/
struct knot_node *nsec3_node;
struct knot_node *nsec3_referer;
/*!
* \brief Various flags.
*
* Currently only two:
* 0x01 - node is a delegation point
* 0x02 - node is non-authoritative (under a delegation point)
* 0x80 - node is old and will be removed (during update)
* 0x40 - node is new, should not be used while zone is old
*/
uint8_t flags;
struct knot_node *new_node;
unsigned int children;
/*!
* \brief Generation of node to be used.
*
* If set to 0, the old node will be used. Otherwise new nodes will
* be used. This applies when getting some referenced node.
*/
// short **generation;
struct knot_zone *zone;
};
typedef struct knot_node knot_node_t;
/*----------------------------------------------------------------------------*/
/*! \brief Flags used to mark nodes with some property. */
typedef enum {
/*! \brief Node is a delegation point (i.e. marking a zone cut). */
KNOT_NODE_FLAGS_DELEG = (uint8_t)0x01,
/*! \brief Node is not authoritative (i.e. below a zone cut). */
KNOT_NODE_FLAGS_NONAUTH = (uint8_t)0x02,
/*! \brief Node is old and will be removed (during update). */
KNOT_NODE_FLAGS_OLD = (uint8_t)0x80,
/*! \brief Node is new and should not be used while zoen is old. */
KNOT_NODE_FLAGS_NEW = (uint8_t)0x40
} knot_node_flags_t;
/*----------------------------------------------------------------------------*/
/*!
* \brief Creates and initializes new node structure.
*
* \todo Owner reference counter will be increased.
*
* \param owner Owner of the created node.
* \param parent Parent of the created node.
* \param flags Document me.
*
* \todo Document missing parameters.
*
* \return Newly created node or NULL if an error occured.
*/
knot_node_t *knot_node_new(knot_dname_t *owner, knot_node_t *parent,
uint8_t flags);
/*!
* \brief Adds an RRSet to the node.
*
* \param node Node to add the RRSet to.
* \param rrset RRSet to add.
*
* \retval KNOT_EOK on success.
* \retval KNOT_ERROR if the RRSet could not be inserted.
*/
int knot_node_add_rrset(knot_node_t *node, knot_rrset_t *rrset,
int merge);
/*!
* \brief Returns the RRSet of the given type from the node.
*
* \param node Node to get the RRSet from.
* \param type Type of the RRSet to retrieve.
*
* \return RRSet from node \a node having type \a type, or NULL if no such
* RRSet exists in this node.
*/
const knot_rrset_t *knot_node_rrset(const knot_node_t *node,
uint16_t type);
/*!
* \brief Returns the RRSet of the given type from the node (non-const version).
*
* \param node Node to get the RRSet from.
* \param type Type of the RRSet to retrieve.
*
* \return RRSet from node \a node having type \a type, or NULL if no such
* RRSet exists in this node.
*/
knot_rrset_t *knot_node_get_rrset(knot_node_t *node, uint16_t type);
knot_rrset_t *knot_node_remove_rrset(knot_node_t *node, uint16_t type);
void knot_node_remove_all_rrsets(knot_node_t *node);
/*!
* \brief Returns number of RRSets in the node.
*
* \param node Node to get the RRSet count from.
*
* \return Number of RRSets in \a node.
*/
short knot_node_rrset_count(const knot_node_t *node);
/*!
* \brief Returns all RRSets from the node.
*
* \param node Node to get the RRSets from.
*
* \return Newly allocated array of RRSets or NULL if an error occured.
*/
knot_rrset_t **knot_node_get_rrsets(const knot_node_t *node);
/*!
* \brief Returns all RRSets from the node.
*
* \note This function is identical to knot_node_get_rrsets(), only it returns
* non-modifiable data.
*
* \param node Node to get the RRSets from.
*
* \return Newly allocated array of RRSets or NULL if an error occured.
*/
const knot_rrset_t **knot_node_rrsets(const knot_node_t *node);
/*!
* \brief Returns the parent of the node.
*
* \param node Node to get the parent of.
*
* \return Parent node of the given node or NULL if no parent has been set (e.g.
* node in a zone apex has no parent).
*/
const knot_node_t *knot_node_parent(const knot_node_t *node,
int check_version);
/*!
* \brief Sets the parent of the node.
*
* \param node Node to set the parent of.
* \param parent Parent to set to the node.
*/
void knot_node_set_parent(knot_node_t *node, knot_node_t *parent);
unsigned int knot_node_children(const knot_node_t *node);
/*!
* \brief Returns the previous authoritative node or delegation point in
* canonical order or the first node in zone.
*
* \param node Node to get the previous node of.
*
* \return Previous authoritative node or delegation point in canonical order or
* the first node in zone if \a node is the last node in zone.
* \retval NULL if previous node is not set.
*/
const knot_node_t *knot_node_previous(const knot_node_t *node,
int check_version);
/*!
* \brief Returns the previous authoritative node or delegation point in
* canonical order or the first node in zone.
*
* \note This function is identical to knot_node_previous() except that it
* returns non-const node.
*
* \param node Node to get the previous node of.
*
* \return Previous authoritative node or delegation point in canonical order or
* the first node in zone if \a node is the last node in zone.
* \retval NULL if previous node is not set.
*/
knot_node_t *knot_node_get_previous(const knot_node_t *node,
int check_version);
/*!
* \brief Sets the previous node of the given node.
*
* \param node Node to set the previous node to.
* \param prev Previous node to set.
*/
void knot_node_set_previous(knot_node_t *node, knot_node_t *prev);
/*!
* \brief Returns the NSEC3 node corresponding to the given node.
*
* \param node Node to get the NSEC3 node for.
*
* \return NSEC3 node corresponding to \a node (i.e. node with owner name
* created by concatenating the hash of owner domain name of \a node
* and the name of the zone \a node belongs to).
* \retval NULL if the NSEC3 node is not set.
*/
const knot_node_t *knot_node_nsec3_node(const knot_node_t *node,
int check_version);
/*!
* \brief Sets the corresponding NSEC3 node of the given node.
*
* \param node Node to set the NSEC3 node to.
* \param nsec3_node NSEC3 node to set.
*/
void knot_node_set_nsec3_node(knot_node_t *node, knot_node_t *nsec3_node);
/*!
* \brief Returns the owner of the node.
*
* \param node Node to get the owner of.
*
* \return Owner of the given node.
*/
const knot_dname_t *knot_node_owner(const knot_node_t *node);
/*!
* \todo Document me.
*/
knot_dname_t *knot_node_get_owner(const knot_node_t *node);
/*!
* \brief Set node owner to specified dname.
*
* Previous owner will be replaced if exist.
*
* \param node Specified node.
* \param owner New owner dname.
*/
void knot_node_set_owner(knot_node_t *node, knot_dname_t* owner);
/*!
* \brief Returns the wildcard child of the node.
*
* \param node Node to get the owner of.
*
* \return Wildcard child of the given node or NULL if it has none.
*/
const knot_node_t *knot_node_wildcard_child(const knot_node_t *node,
int check_version);
/*!
* \brief Sets the wildcard child of the node.
*
* \param node Node to set the wildcard child of.
* \param wildcard_child Wildcard child of the node.
*/
void knot_node_set_wildcard_child(knot_node_t *node,
knot_node_t *wildcard_child);
const knot_node_t *knot_node_current(const knot_node_t *node);
knot_node_t *knot_node_get_current(knot_node_t *node);
const knot_node_t *knot_node_new_node(const knot_node_t *node);
knot_node_t *knot_node_get_new_node(const knot_node_t *node);
void knot_node_set_new_node(knot_node_t *node,
knot_node_t *new_node);
void knot_node_set_zone(knot_node_t *node, struct knot_zone *zone);
void knot_node_update_ref(knot_node_t **ref);
void knot_node_update_refs(knot_node_t *node);
/*!
* \brief Mark the node as a delegation point.
*
* \param node Node to mark as a delegation point.
*/
void knot_node_set_deleg_point(knot_node_t *node);
/*!
* \brief Checks if the node is a delegation point.
*
* \param node Node to check.
*
* \retval <> 0 if \a node is marked as delegation point.
* \retval 0 otherwise.
*/
int knot_node_is_deleg_point(const knot_node_t *node);
/*!
* \brief Mark the node as non-authoritative.
*
* \param node Node to mark as non-authoritative.
*/
void knot_node_set_non_auth(knot_node_t *node);
/*!
* \brief Checks if the node is non-authoritative.
*
* \param node Node to check.
*
* \retval <> 0 if \a node is marked as non-authoritative.
* \retval 0 otherwise.
*/
int knot_node_is_non_auth(const knot_node_t *node);
int knot_node_is_auth(const knot_node_t *node);
int knot_node_is_new(const knot_node_t *node);
int knot_node_is_old(const knot_node_t *node);
void knot_node_set_new(knot_node_t *node);
void knot_node_set_old(knot_node_t *node);
void knot_node_clear_new(knot_node_t *node);
void knot_node_clear_old(knot_node_t *node);
/*!
* \brief Destroys the RRSets within the node structure.
*
* \param node Node to be destroyed.
* \param free_rdata_dnames Set to <> 0 if you want to delete ALL domain names
* present in RDATA. Set to 0 otherwise. (See
* knot_rdata_deep_free().)
*/
void knot_node_free_rrsets(knot_node_t *node, int free_rdata_dnames);
/*!
* \brief Destroys the node structure.
*
* Does not destroy the RRSets within the node.
* Also sets the given pointer to NULL.
*
* \param node Node to be destroyed.
* \param free_owner Set to 0 if you do not want the owner domain name to be
* destroyed also. Set to <> 0 otherwise.
* \param fix_refs
*
* \todo Document missing parameters.
*/
void knot_node_free(knot_node_t **node, int free_owner, int fix_refs);
/*!
* \brief Compares two nodes according to their owner.
*
* \param node1 First node.
* \param node2 Second node.
*
* \retval < 0 if \a node1 goes before \a node2 according to canonical order
* of their owner names.
* \retval 0 if they are equal.
* \retval > 0 if \a node1 goes after \a node2.
*/
int knot_node_compare(knot_node_t *node1, knot_node_t *node2);
int knot_node_shallow_copy(const knot_node_t *from, knot_node_t **to);
#endif /* _KNOT_NODE_H_ */
/*! @} */
|