1 /* $NetBSD: caa_257.c,v 1.1.1.3 2014/12/10 03:34:42 christos Exp $ */
4 * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 #ifndef GENERIC_CAA_257_C
20 #define GENERIC_CAA_257_C 1
22 #define RRTYPE_CAA_ATTRIBUTES (0)
24 static unsigned char const alphanumeric
[256] = {
25 /* 0x00-0x0f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
26 /* 0x10-0x1f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27 /* 0x20-0x2f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
28 /* 0x30-0x3f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
29 /* 0x40-0x4f */ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
30 /* 0x50-0x5f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
31 /* 0x60-0x6f */ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
32 /* 0x70-0x7f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
33 /* 0x80-0x8f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34 /* 0x90-0x9f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35 /* 0xa0-0xaf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36 /* 0xb0-0xbf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37 /* 0xc0-0xcf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38 /* 0xd0-0xdf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39 /* 0xe0-0xef */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
40 /* 0xf0-0xff */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 static inline isc_result_t
44 fromtext_caa(ARGS_FROMTEXT
) {
59 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
61 if (token
.value
.as_ulong
> 255U)
63 flags
= token
.value
.as_ulong
;
64 RETERR(uint8_tobuffer(flags
, target
));
69 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
71 tr
= token
.value
.as_textregion
;
72 for (i
= 0; i
< tr
.length
; i
++)
73 if (!alphanumeric
[(unsigned int) tr
.base
[i
]])
75 RETERR(uint8_tobuffer(tr
.length
, target
));
76 RETERR(mem_tobuffer(target
, tr
.base
, tr
.length
));
81 RETERR(isc_lex_getmastertoken(lexer
, &token
,
82 isc_tokentype_qstring
, ISC_FALSE
));
83 if (token
.type
!= isc_tokentype_qstring
&&
84 token
.type
!= isc_tokentype_string
)
86 RETERR(multitxt_fromtext(&token
.value
.as_textregion
, target
));
87 return (ISC_R_SUCCESS
);
90 static inline isc_result_t
91 totext_caa(ARGS_TOTEXT
) {
98 REQUIRE(rdata
->type
== 257);
99 REQUIRE(rdata
->length
>= 3U);
100 REQUIRE(rdata
->data
!= NULL
);
102 dns_rdata_toregion(rdata
, ®ion
);
107 flags
= uint8_consume_fromregion(®ion
);
108 sprintf(buf
, "%u ", flags
);
109 RETERR(str_totext(buf
, target
));
114 RETERR(txt_totext(®ion
, ISC_FALSE
, target
));
115 RETERR(str_totext(" ", target
));
120 RETERR(multitxt_totext(®ion
, target
));
121 return (ISC_R_SUCCESS
);
124 static inline isc_result_t
125 fromwire_caa(ARGS_FROMWIRE
) {
129 REQUIRE(type
== 257);
139 isc_buffer_activeregion(source
, &sr
);
141 return (ISC_R_UNEXPECTEDEND
);
146 RETERR(mem_tobuffer(target
, sr
.base
, 2));
148 isc_region_consume(&sr
, 2);
149 isc_buffer_forward(source
, 2);
152 * Zero length tag fields are illegal.
154 if (sr
.length
< len
|| len
== 0)
155 RETERR(DNS_R_FORMERR
);
157 /* Check the Tag's value */
158 for (i
= 0; i
< len
; i
++)
159 if (!alphanumeric
[sr
.base
[i
]])
160 RETERR(DNS_R_FORMERR
);
164 isc_buffer_forward(source
, sr
.length
);
165 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
168 static inline isc_result_t
169 towire_caa(ARGS_TOWIRE
) {
172 REQUIRE(rdata
->type
== 257);
173 REQUIRE(rdata
->length
>= 3U);
174 REQUIRE(rdata
->data
!= NULL
);
178 dns_rdata_toregion(rdata
, ®ion
);
179 return (mem_tobuffer(target
, region
.base
, region
.length
));
183 compare_caa(ARGS_COMPARE
) {
186 REQUIRE(rdata1
->type
== rdata2
->type
);
187 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
188 REQUIRE(rdata1
->type
== 257);
189 REQUIRE(rdata1
->length
>= 3U);
190 REQUIRE(rdata2
->length
>= 3U);
191 REQUIRE(rdata1
->data
!= NULL
);
192 REQUIRE(rdata2
->data
!= NULL
);
194 dns_rdata_toregion(rdata1
, &r1
);
195 dns_rdata_toregion(rdata2
, &r2
);
196 return (isc_region_compare(&r1
, &r2
));
199 static inline isc_result_t
200 fromstruct_caa(ARGS_FROMSTRUCT
) {
201 dns_rdata_caa_t
*caa
= source
;
205 REQUIRE(type
== 257);
206 REQUIRE(source
!= NULL
);
207 REQUIRE(caa
->common
.rdtype
== type
);
208 REQUIRE(caa
->common
.rdclass
== rdclass
);
209 REQUIRE(caa
->tag
!= NULL
&& caa
->tag_len
!= 0);
210 REQUIRE(caa
->value
!= NULL
);
218 RETERR(uint8_tobuffer(caa
->flags
, target
));
223 RETERR(uint8_tobuffer(caa
->tag_len
, target
));
228 region
.base
= caa
->tag
;
229 region
.length
= caa
->tag_len
;
230 for (i
= 0; i
< region
.length
; i
++)
231 if (!alphanumeric
[region
.base
[i
]])
232 RETERR(DNS_R_SYNTAX
);
233 RETERR(isc_buffer_copyregion(target
, ®ion
));
238 region
.base
= caa
->value
;
239 region
.length
= caa
->value_len
;
240 return (isc_buffer_copyregion(target
, ®ion
));
243 static inline isc_result_t
244 tostruct_caa(ARGS_TOSTRUCT
) {
245 dns_rdata_caa_t
*caa
= target
;
248 REQUIRE(rdata
->type
== 257);
249 REQUIRE(target
!= NULL
);
250 REQUIRE(rdata
->length
>= 3U);
251 REQUIRE(rdata
->data
!= NULL
);
253 caa
->common
.rdclass
= rdata
->rdclass
;
254 caa
->common
.rdtype
= rdata
->type
;
255 ISC_LINK_INIT(&caa
->common
, link
);
257 dns_rdata_toregion(rdata
, &sr
);
263 return (ISC_R_UNEXPECTEDEND
);
264 caa
->flags
= uint8_fromregion(&sr
);
265 isc_region_consume(&sr
, 1);
271 return (ISC_R_UNEXPECTEDEND
);
272 caa
->tag_len
= uint8_fromregion(&sr
);
273 isc_region_consume(&sr
, 1);
278 if (sr
.length
< caa
->tag_len
)
279 return (ISC_R_UNEXPECTEDEND
);
280 caa
->tag
= mem_maybedup(mctx
, sr
.base
, caa
->tag_len
);
281 if (caa
->tag
== NULL
)
282 return (ISC_R_NOMEMORY
);
283 isc_region_consume(&sr
, caa
->tag_len
);
288 caa
->value_len
= sr
.length
;
289 caa
->value
= mem_maybedup(mctx
, sr
.base
, sr
.length
);
290 if (caa
->value
== NULL
)
291 return (ISC_R_NOMEMORY
);
294 return (ISC_R_SUCCESS
);
298 freestruct_caa(ARGS_FREESTRUCT
) {
299 dns_rdata_caa_t
*caa
= (dns_rdata_caa_t
*) source
;
301 REQUIRE(source
!= NULL
);
302 REQUIRE(caa
->common
.rdtype
== 257);
304 if (caa
->mctx
== NULL
)
307 if (caa
->tag
!= NULL
)
308 isc_mem_free(caa
->mctx
, caa
->tag
);
309 if (caa
->value
!= NULL
)
310 isc_mem_free(caa
->mctx
, caa
->value
);
314 static inline isc_result_t
315 additionaldata_caa(ARGS_ADDLDATA
) {
316 REQUIRE(rdata
->type
== 257);
317 REQUIRE(rdata
->data
!= NULL
);
318 REQUIRE(rdata
->length
>= 3U);
324 return (ISC_R_SUCCESS
);
327 static inline isc_result_t
328 digest_caa(ARGS_DIGEST
) {
331 REQUIRE(rdata
->type
== 257);
332 REQUIRE(rdata
->data
!= NULL
);
333 REQUIRE(rdata
->length
>= 3U);
335 dns_rdata_toregion(rdata
, &r
);
337 return ((digest
)(arg
, &r
));
340 static inline isc_boolean_t
341 checkowner_caa(ARGS_CHECKOWNER
) {
343 REQUIRE(type
== 257);
353 static inline isc_boolean_t
354 checknames_caa(ARGS_CHECKNAMES
) {
356 REQUIRE(rdata
->type
== 257);
357 REQUIRE(rdata
->data
!= NULL
);
358 REQUIRE(rdata
->length
>= 3U);
368 casecompare_caa(ARGS_COMPARE
) {
369 return (compare_caa(rdata1
, rdata2
));
372 #endif /* GENERIC_CAA_257_C */