4 * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001, 2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: rdatalist.c,v 1.36 2008/09/24 02:46:22 marka Exp */
31 #include <dns/nsec3.h>
32 #include <dns/rdata.h>
33 #include <dns/rdatalist.h>
34 #include <dns/rdataset.h>
36 #include "rdatalist_p.h"
38 static dns_rdatasetmethods_t methods
= {
39 isc__rdatalist_disassociate
,
42 isc__rdatalist_current
,
45 isc__rdatalist_addnoqname
,
46 isc__rdatalist_getnoqname
,
47 isc__rdatalist_addclosest
,
48 isc__rdatalist_getclosest
,
55 dns_rdatalist_init(dns_rdatalist_t
*rdatalist
) {
58 * Initialize rdatalist.
61 rdatalist
->rdclass
= 0;
63 rdatalist
->covers
= 0;
65 ISC_LIST_INIT(rdatalist
->rdata
);
66 ISC_LINK_INIT(rdatalist
, link
);
70 dns_rdatalist_tordataset(dns_rdatalist_t
*rdatalist
,
71 dns_rdataset_t
*rdataset
)
74 * Make 'rdataset' refer to the rdata in 'rdatalist'.
77 REQUIRE(rdatalist
!= NULL
);
78 REQUIRE(DNS_RDATASET_VALID(rdataset
));
79 REQUIRE(! dns_rdataset_isassociated(rdataset
));
81 rdataset
->methods
= &methods
;
82 rdataset
->rdclass
= rdatalist
->rdclass
;
83 rdataset
->type
= rdatalist
->type
;
84 rdataset
->covers
= rdatalist
->covers
;
85 rdataset
->ttl
= rdatalist
->ttl
;
87 rdataset
->private1
= rdatalist
;
88 rdataset
->private2
= NULL
;
89 rdataset
->private3
= NULL
;
90 rdataset
->privateuint4
= 0;
91 rdataset
->private5
= NULL
;
93 return (ISC_R_SUCCESS
);
97 dns_rdatalist_fromrdataset(dns_rdataset_t
*rdataset
,
98 dns_rdatalist_t
**rdatalist
)
100 REQUIRE(rdatalist
!= NULL
&& rdataset
!= NULL
);
101 *rdatalist
= rdataset
->private1
;
103 return (ISC_R_SUCCESS
);
107 isc__rdatalist_disassociate(dns_rdataset_t
*rdataset
) {
112 isc__rdatalist_first(dns_rdataset_t
*rdataset
) {
113 dns_rdatalist_t
*rdatalist
;
115 rdatalist
= rdataset
->private1
;
116 rdataset
->private2
= ISC_LIST_HEAD(rdatalist
->rdata
);
118 if (rdataset
->private2
== NULL
)
119 return (ISC_R_NOMORE
);
121 return (ISC_R_SUCCESS
);
125 isc__rdatalist_next(dns_rdataset_t
*rdataset
) {
128 rdata
= rdataset
->private2
;
130 return (ISC_R_NOMORE
);
132 rdataset
->private2
= ISC_LIST_NEXT(rdata
, link
);
134 if (rdataset
->private2
== NULL
)
135 return (ISC_R_NOMORE
);
137 return (ISC_R_SUCCESS
);
141 isc__rdatalist_current(dns_rdataset_t
*rdataset
, dns_rdata_t
*rdata
) {
142 dns_rdata_t
*list_rdata
;
144 list_rdata
= rdataset
->private2
;
145 INSIST(list_rdata
!= NULL
);
147 dns_rdata_clone(list_rdata
, rdata
);
151 isc__rdatalist_clone(dns_rdataset_t
*source
, dns_rdataset_t
*target
) {
155 * Reset iterator state.
157 target
->private2
= NULL
;
161 isc__rdatalist_count(dns_rdataset_t
*rdataset
) {
162 dns_rdatalist_t
*rdatalist
;
166 rdatalist
= rdataset
->private1
;
169 for (rdata
= ISC_LIST_HEAD(rdatalist
->rdata
);
171 rdata
= ISC_LIST_NEXT(rdata
, link
))
178 isc__rdatalist_addnoqname(dns_rdataset_t
*rdataset
, dns_name_t
*name
) {
179 dns_rdataset_t
*neg
= NULL
;
180 dns_rdataset_t
*negsig
= NULL
;
181 dns_rdataset_t
*rdset
;
184 for (rdset
= ISC_LIST_HEAD(name
->list
);
186 rdset
= ISC_LIST_NEXT(rdset
, link
))
188 if (rdset
->rdclass
!= rdataset
->rdclass
)
190 if (rdset
->type
== dns_rdatatype_nsec
||
191 rdset
->type
== dns_rdatatype_nsec3
)
195 return (ISC_R_NOTFOUND
);
197 for (rdset
= ISC_LIST_HEAD(name
->list
);
199 rdset
= ISC_LIST_NEXT(rdset
, link
))
201 if (rdset
->type
== dns_rdatatype_rrsig
&&
202 rdset
->covers
== neg
->type
)
207 return (ISC_R_NOTFOUND
);
214 if (negsig
->ttl
< ttl
)
216 rdataset
->ttl
= neg
->ttl
= negsig
->ttl
= ttl
;
217 rdataset
->attributes
|= DNS_RDATASETATTR_NOQNAME
;
218 rdataset
->private6
= name
;
219 return (ISC_R_SUCCESS
);
223 isc__rdatalist_getnoqname(dns_rdataset_t
*rdataset
, dns_name_t
*name
,
224 dns_rdataset_t
*neg
, dns_rdataset_t
*negsig
)
226 dns_rdataclass_t rdclass
= rdataset
->rdclass
;
227 dns_rdataset_t
*tneg
= NULL
;
228 dns_rdataset_t
*tnegsig
= NULL
;
229 dns_name_t
*noqname
= rdataset
->private6
;
231 REQUIRE((rdataset
->attributes
& DNS_RDATASETATTR_NOQNAME
) != 0);
232 (void)dns_name_dynamic(noqname
); /* Sanity Check. */
234 for (rdataset
= ISC_LIST_HEAD(noqname
->list
);
236 rdataset
= ISC_LIST_NEXT(rdataset
, link
))
238 if (rdataset
->rdclass
!= rdclass
)
240 if (rdataset
->type
== dns_rdatatype_nsec
||
241 rdataset
->type
== dns_rdatatype_nsec3
)
245 return (ISC_R_NOTFOUND
);
247 for (rdataset
= ISC_LIST_HEAD(noqname
->list
);
249 rdataset
= ISC_LIST_NEXT(rdataset
, link
))
251 if (rdataset
->type
== dns_rdatatype_rrsig
&&
252 rdataset
->covers
== tneg
->type
)
256 return (ISC_R_NOTFOUND
);
258 dns_name_clone(noqname
, name
);
259 dns_rdataset_clone(tneg
, neg
);
260 dns_rdataset_clone(tnegsig
, negsig
);
261 return (ISC_R_SUCCESS
);
265 isc__rdatalist_addclosest(dns_rdataset_t
*rdataset
, dns_name_t
*name
) {
266 dns_rdataset_t
*neg
= NULL
;
267 dns_rdataset_t
*negsig
= NULL
;
268 dns_rdataset_t
*rdset
;
271 for (rdset
= ISC_LIST_HEAD(name
->list
);
273 rdset
= ISC_LIST_NEXT(rdset
, link
))
275 if (rdset
->rdclass
!= rdataset
->rdclass
)
277 if (rdset
->type
== dns_rdatatype_nsec
||
278 rdset
->type
== dns_rdatatype_nsec3
)
282 return (ISC_R_NOTFOUND
);
284 for (rdset
= ISC_LIST_HEAD(name
->list
);
286 rdset
= ISC_LIST_NEXT(rdset
, link
))
288 if (rdset
->type
== dns_rdatatype_rrsig
&&
289 rdset
->covers
== neg
->type
)
294 return (ISC_R_NOTFOUND
);
301 if (negsig
->ttl
< ttl
)
303 rdataset
->ttl
= neg
->ttl
= negsig
->ttl
= ttl
;
304 rdataset
->attributes
|= DNS_RDATASETATTR_CLOSEST
;
305 rdataset
->private7
= name
;
306 return (ISC_R_SUCCESS
);
310 isc__rdatalist_getclosest(dns_rdataset_t
*rdataset
, dns_name_t
*name
,
311 dns_rdataset_t
*neg
, dns_rdataset_t
*negsig
)
313 dns_rdataclass_t rdclass
= rdataset
->rdclass
;
314 dns_rdataset_t
*tneg
= NULL
;
315 dns_rdataset_t
*tnegsig
= NULL
;
316 dns_name_t
*closest
= rdataset
->private7
;
318 REQUIRE((rdataset
->attributes
& DNS_RDATASETATTR_CLOSEST
) != 0);
319 (void)dns_name_dynamic(closest
); /* Sanity Check. */
321 for (rdataset
= ISC_LIST_HEAD(closest
->list
);
323 rdataset
= ISC_LIST_NEXT(rdataset
, link
))
325 if (rdataset
->rdclass
!= rdclass
)
327 if (rdataset
->type
== dns_rdatatype_nsec
||
328 rdataset
->type
== dns_rdatatype_nsec3
)
332 return (ISC_R_NOTFOUND
);
334 for (rdataset
= ISC_LIST_HEAD(closest
->list
);
336 rdataset
= ISC_LIST_NEXT(rdataset
, link
))
338 if (rdataset
->type
== dns_rdatatype_rrsig
&&
339 rdataset
->covers
== tneg
->type
)
343 return (ISC_R_NOTFOUND
);
345 dns_name_clone(closest
, name
);
346 dns_rdataset_clone(tneg
, neg
);
347 dns_rdataset_clone(tnegsig
, negsig
);
348 return (ISC_R_SUCCESS
);