Skip to content

Commit 00a6268

Browse files
committed
Merge branch 'each-cleanup-rbt' into 'main'
replace RBT usage throughout named See merge request isc-projects/bind9!8213
2 parents 5969a7c + 9c25a09 commit 00a6268

File tree

13 files changed

+976
-376
lines changed

13 files changed

+976
-376
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
6238. [cleanup] Refactor several objects relying on dns_rbt trees
2+
to instead of dns_nametree, a wrapper around dns_qp.
3+
[GL !8213]
4+
15
6237. [bug] Address memory leaks due to not clearing OpenSSL error
26
stack. [GL #4159]
37

bin/named/server.c

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include <dns/keyvalues.h>
8484
#include <dns/master.h>
8585
#include <dns/masterdump.h>
86+
#include <dns/nametree.h>
8687
#include <dns/nsec3.h>
8788
#include <dns/nta.h>
8889
#include <dns/order.h>
@@ -602,21 +603,23 @@ configure_view_sortlist(const cfg_obj_t *vconfig, const cfg_obj_t *config,
602603
static isc_result_t
603604
configure_view_nametable(const cfg_obj_t *vconfig, const cfg_obj_t *config,
604605
const char *confname, const char *conftuplename,
605-
isc_mem_t *mctx, dns_rbt_t **rbtp) {
606-
isc_result_t result;
606+
isc_mem_t *mctx, dns_nametree_t **ntp) {
607+
isc_result_t result = ISC_R_SUCCESS;
607608
const cfg_obj_t *maps[3];
608609
const cfg_obj_t *obj = NULL;
609-
const cfg_listelt_t *element;
610+
const cfg_listelt_t *element = NULL;
610611
int i = 0;
611612
dns_fixedname_t fixed;
612-
dns_name_t *name;
613+
dns_name_t *name = NULL;
613614
isc_buffer_t b;
614-
const char *str;
615-
const cfg_obj_t *nameobj;
615+
const char *str = NULL;
616+
const cfg_obj_t *nameobj = NULL;
616617

617-
if (*rbtp != NULL) {
618-
dns_rbt_destroy(rbtp);
618+
if (*ntp != NULL) {
619+
dns_nametree_detach(ntp);
619620
}
621+
dns_nametree_create(mctx, DNS_NAMETREE_BOOL, confname, ntp);
622+
620623
if (vconfig != NULL) {
621624
maps[i++] = cfg_tuple_get(vconfig, "options");
622625
}
@@ -632,7 +635,7 @@ configure_view_nametable(const cfg_obj_t *vconfig, const cfg_obj_t *config,
632635
(void)named_config_get(maps, confname, &obj);
633636
if (obj == NULL) {
634637
/*
635-
* No value available. *rbtp == NULL.
638+
* No value available. *ntp == NULL.
636639
*/
637640
return (ISC_R_SUCCESS);
638641
}
@@ -644,11 +647,6 @@ configure_view_nametable(const cfg_obj_t *vconfig, const cfg_obj_t *config,
644647
}
645648
}
646649

647-
result = dns_rbt_create(mctx, NULL, NULL, rbtp);
648-
if (result != ISC_R_SUCCESS) {
649-
return (result);
650-
}
651-
652650
name = dns_fixedname_initname(&fixed);
653651
for (element = cfg_list_first(obj); element != NULL;
654652
element = cfg_list_next(element))
@@ -658,14 +656,7 @@ configure_view_nametable(const cfg_obj_t *vconfig, const cfg_obj_t *config,
658656
isc_buffer_constinit(&b, str, strlen(str));
659657
isc_buffer_add(&b, strlen(str));
660658
CHECK(dns_name_fromtext(name, &b, dns_rootname, 0, NULL));
661-
/*
662-
* We don't need the node data, but need to set dummy data to
663-
* avoid a partial match with an empty node. For example, if
664-
* we have foo.example.com and bar.example.com, we'd get a match
665-
* for baz.example.com, which is not the expected result.
666-
* We simply use (void *)1 as the dummy data.
667-
*/
668-
result = dns_rbt_addname(*rbtp, name, (void *)1);
659+
result = dns_nametree_add(*ntp, name, true);
669660
if (result != ISC_R_SUCCESS) {
670661
cfg_obj_log(nameobj, named_g_lctx, ISC_LOG_ERROR,
671662
"failed to add %s for %s: %s", str,
@@ -674,10 +665,10 @@ configure_view_nametable(const cfg_obj_t *vconfig, const cfg_obj_t *config,
674665
}
675666
}
676667

677-
return (result);
668+
return (ISC_R_SUCCESS);
678669

679670
cleanup:
680-
dns_rbt_destroy(rbtp);
671+
dns_nametree_detach(ntp);
681672
return (result);
682673
}
683674

@@ -4915,7 +4906,6 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
49154906
/*
49164907
* Set supported DNSSEC algorithms.
49174908
*/
4918-
dns_resolver_reset_algorithms(view->resolver);
49194909
disabled = NULL;
49204910
(void)named_config_get(maps, "disable-algorithms", &disabled);
49214911
if (disabled != NULL) {
@@ -4930,7 +4920,6 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
49304920
/*
49314921
* Set supported DS digest types.
49324922
*/
4933-
dns_resolver_reset_ds_digests(view->resolver);
49344923
disabled = NULL;
49354924
(void)named_config_get(maps, "disable-ds-digests", &disabled);
49364925
if (disabled != NULL) {
@@ -5530,7 +5519,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
55305519
*/
55315520
CHECK(configure_view_dnsseckeys(view, vconfig, config, bindkeys,
55325521
auto_root));
5533-
dns_resolver_resetmustbesecure(view->resolver);
5522+
55345523
obj = NULL;
55355524
result = named_config_get(maps, "dnssec-must-be-secure", &obj);
55365525
if (result == ISC_R_SUCCESS) {

lib/dns/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ libdns_la_HEADERS = \
9191
include/dns/masterdump.h \
9292
include/dns/message.h \
9393
include/dns/name.h \
94+
include/dns/nametree.h \
9495
include/dns/ncache.h \
9596
include/dns/nsec.h \
9697
include/dns/nsec3.h \
@@ -196,6 +197,7 @@ libdns_la_SOURCES = \
196197
masterdump.c \
197198
message.c \
198199
name.c \
200+
nametree.c \
199201
ncache.c \
200202
nsec.c \
201203
nsec3.c \

lib/dns/include/dns/nametree.h

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3+
*
4+
* SPDX-License-Identifier: MPL-2.0
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* See the COPYRIGHT file distributed with this work for additional
11+
* information regarding copyright ownership.
12+
*/
13+
14+
#pragma once
15+
16+
/*****
17+
***** Module Info
18+
*****/
19+
20+
/*! \file
21+
* \brief
22+
* A nametree module is a tree of DNS names containing boolean values
23+
* or bitfields, allowing a quick lookup to see whether a name is included
24+
* in or excluded from some policy.
25+
*/
26+
27+
#include <stdbool.h>
28+
29+
#include <isc/lang.h>
30+
#include <isc/magic.h>
31+
#include <isc/refcount.h>
32+
#include <isc/rwlock.h>
33+
#include <isc/stdtime.h>
34+
35+
#include <dns/rdatastruct.h>
36+
#include <dns/types.h>
37+
38+
#include <dst/dst.h>
39+
40+
/* Define to 1 for detailed reference tracing */
41+
#undef DNS_NAMETREE_TRACE
42+
43+
typedef enum {
44+
DNS_NAMETREE_BOOL,
45+
DNS_NAMETREE_BITS,
46+
DNS_NAMETREE_COUNT
47+
} dns_nametree_type_t;
48+
49+
ISC_LANG_BEGINDECLS
50+
51+
void
52+
dns_nametree_create(isc_mem_t *mctx, dns_nametree_type_t type, const char *name,
53+
dns_nametree_t **ntp);
54+
/*%<
55+
* Create a nametree.
56+
*
57+
* If 'name' is not NULL, it will be saved as the name of the QP trie
58+
* for debugging purposes.
59+
*
60+
* 'type' indicates whether the tree will be used for storing boolean
61+
* values (DNS_NAMETREE_BOOL), bitfields (DNS_NAMETREE_BITS), or counters
62+
* (DNS_NAMETREE_COUNT).
63+
*
64+
* Requires:
65+
*
66+
*\li 'mctx' is a valid memory context.
67+
*\li ntp != NULL && *ntp == NULL
68+
*/
69+
70+
isc_result_t
71+
dns_nametree_add(dns_nametree_t *nametree, const dns_name_t *name,
72+
uint32_t value);
73+
/*%<
74+
* Add a node to 'nametree'.
75+
*
76+
* If the nametree type was set to DNS_NAMETREE_BOOL, then 'value'
77+
* represents a single boolean value, true or false. If the name already
78+
* exists within the tree, then return ISC_R_EXISTS.
79+
*
80+
* If the nametree type was set to DNS_NAMETREE_COUNT, then 'value'
81+
* can only be true. Each time the same name is added to the tree,
82+
* ISC_R_SUCCESS is returned and a counter is incremented.
83+
* dns_nametree_delete() must be deleted the same number of times
84+
* as dns_nametree_add() before the name is removed from the tree.
85+
*
86+
* If the nametree type was set to DNS_NAMETREE_BITS, then 'value' is
87+
* a bit number within a bit field, which is sized to accomodate at least
88+
* 'value' bits. If the name already exists, then that bit will be set
89+
* in the bitfield, other bits will be retained, and ISC_R_SUCCESS will be
90+
* returned. If 'value' excees the number of bits in the existing bit
91+
* field, the field will be expanded.
92+
*
93+
* Requires:
94+
*
95+
*\li 'nametree' points to a valid nametree.
96+
*
97+
* Returns:
98+
*
99+
*\li ISC_R_SUCCESS
100+
*\li ISC_R_EXISTS
101+
*
102+
*\li Any other result indicates failure.
103+
*/
104+
105+
isc_result_t
106+
dns_nametree_delete(dns_nametree_t *nametree, const dns_name_t *name);
107+
/*%<
108+
* Delete 'name' from 'nametree'.
109+
*
110+
* If the nametree type was set to DNS_NAMETREE_COUNT, then this must
111+
* be called for each name the same number of times as dns_nametree_add()
112+
* was called before the name is removed.
113+
*
114+
* Requires:
115+
*
116+
*\li 'nametree' points to a valid nametree.
117+
*\li 'name' is not NULL
118+
*
119+
* Returns:
120+
*
121+
*\li ISC_R_SUCCESS
122+
*
123+
*\li Any other result indicates failure.
124+
*/
125+
126+
isc_result_t
127+
dns_nametree_find(dns_nametree_t *nametree, const dns_name_t *name,
128+
dns_ntnode_t **ntp);
129+
/*%<
130+
* Retrieve the node that exactly matches 'name' from 'nametree'.
131+
*
132+
* Requires:
133+
*
134+
*\li 'nametree' is a valid nametree.
135+
*
136+
*\li 'name' is a valid name.
137+
*
138+
*\li ntp != NULL && *ntp == NULL
139+
*
140+
* Returns:
141+
*
142+
*\li ISC_R_SUCCESS
143+
*\li ISC_R_NOTFOUND
144+
*
145+
*\li Any other result indicates an error.
146+
*/
147+
148+
bool
149+
dns_nametree_covered(dns_nametree_t *nametree, const dns_name_t *name,
150+
dns_name_t *found, uint32_t bit);
151+
/*%<
152+
* Indicates whether a 'name' (with optional 'bit' value) is covered by
153+
* 'nametree'.
154+
*
155+
* In DNS_NAMETREE_BOOL nametrees, this returns true if 'name' has a match
156+
* or a closest ancestor in 'nametree' with its value set to 'true'.
157+
* 'bit' is ignored.
158+
*
159+
* In DNS_NAMETREE_BITS trees, this returns true if 'name' has a match or
160+
* a closest ancestor in 'nametree' with the 'bit' set in its bitfield.
161+
*
162+
* If a name is not found, the default return value is false.
163+
*
164+
* If 'found' is not NULL, the name or ancestor name that was found in
165+
* the tree is copied into it.
166+
*
167+
* Requires:
168+
*
169+
*\li 'nametree' is a valid nametree, or is NULL.
170+
*/
171+
172+
#if DNS_NAMETREE_TRACE
173+
#define dns_nametree_ref(ptr) \
174+
dns_nametree__ref(ptr, __func__, __FILE__, __LINE__)
175+
#define dns_nametree_unref(ptr) \
176+
dns_nametree__unref(ptr, __func__, __FILE__, __LINE__)
177+
#define dns_nametree_attach(ptr, ptrp) \
178+
dns_nametree__attach(ptr, ptrp, __func__, __FILE__, __LINE__)
179+
#define dns_nametree_detach(ptrp) \
180+
dns_nametree__detach(ptrp, __func__, __FILE__, __LINE__)
181+
#define dns_ntnode_ref(ptr) dns_ntnode__ref(ptr, __func__, __FILE__, __LINE__)
182+
#define dns_ntnode_unref(ptr) \
183+
dns_ntnode__unref(ptr, __func__, __FILE__, __LINE__)
184+
#define dns_ntnode_attach(ptr, ptrp) \
185+
dns_ntnode__attach(ptr, ptrp, __func__, __FILE__, __LINE__)
186+
#define dns_ntnode_detach(ptrp) \
187+
dns_ntnode__detach(ptrp, __func__, __FILE__, __LINE__)
188+
ISC_REFCOUNT_TRACE_DECL(dns_nametree);
189+
ISC_REFCOUNT_TRACE_DECL(dns_ntnode);
190+
#else
191+
ISC_REFCOUNT_DECL(dns_nametree);
192+
ISC_REFCOUNT_DECL(dns_ntnode);
193+
#endif
194+
ISC_LANG_ENDDECLS

lib/dns/include/dns/resolver.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,6 @@ dns_resolver_addalternate(dns_resolver_t *resolver, const isc_sockaddr_t *alt,
423423
* \li only one of 'name' or 'alt' to be valid.
424424
*/
425425

426-
void
427-
dns_resolver_reset_algorithms(dns_resolver_t *resolver);
428-
/*%<
429-
* Clear the disabled DNSSEC algorithms.
430-
*/
431-
432-
void
433-
dns_resolver_reset_ds_digests(dns_resolver_t *resolver);
434-
/*%<
435-
* Clear the disabled DS digest types.
436-
*/
437-
438426
isc_result_t
439427
dns_resolver_disable_algorithm(dns_resolver_t *resolver, const dns_name_t *name,
440428
unsigned int alg);
@@ -482,9 +470,6 @@ dns_resolver_ds_digest_supported(dns_resolver_t *resolver,
482470
* crypto libraries if it was not specifically disabled.
483471
*/
484472

485-
void
486-
dns_resolver_resetmustbesecure(dns_resolver_t *resolver);
487-
488473
isc_result_t
489474
dns_resolver_setmustbesecure(dns_resolver_t *resolver, const dns_name_t *name,
490475
bool value);

lib/dns/include/dns/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ typedef struct dns_message dns_message_t;
116116
typedef uint16_t dns_messageid_t;
117117
typedef isc_region_t dns_label_t;
118118
typedef struct dns_name dns_name_t;
119+
typedef struct dns_nametree dns_nametree_t;
119120
typedef ISC_LIST(dns_name_t) dns_namelist_t;
120121
typedef struct dns_ntatable dns_ntatable_t;
122+
typedef struct dns_ntnode dns_ntnode_t;
121123
typedef uint16_t dns_opcode_t;
122124
typedef struct dns_order dns_order_t;
123125
typedef struct dns_peer dns_peer_t;

lib/dns/include/dns/view.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,11 @@ struct dns_view {
140140
dns_acl_t *denyansweracl;
141141
dns_acl_t *nocasecompress;
142142
bool msgcompression;
143-
dns_rbt_t *answeracl_exclude;
144-
dns_rbt_t *denyanswernames;
145-
dns_rbt_t *answernames_exclude;
143+
dns_nametree_t *answeracl_exclude;
144+
dns_nametree_t *denyanswernames;
145+
dns_nametree_t *answernames_exclude;
146+
dns_nametree_t *sfd;
146147
dns_rrl_t *rrl;
147-
dns_rbt_t *sfd;
148-
isc_rwlock_t sfd_lock;
149148
bool provideixfr;
150149
bool requestnsid;
151150
bool sendcookie;

0 commit comments

Comments
 (0)