15185a700Sflorian /*
25185a700Sflorian * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
35185a700Sflorian *
45185a700Sflorian * Permission to use, copy, modify, and/or distribute this software for any
55185a700Sflorian * purpose with or without fee is hereby granted, provided that the above
65185a700Sflorian * copyright notice and this permission notice appear in all copies.
75185a700Sflorian *
85185a700Sflorian * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
95185a700Sflorian * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
105185a700Sflorian * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
115185a700Sflorian * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
125185a700Sflorian * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
135185a700Sflorian * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
145185a700Sflorian * PERFORMANCE OF THIS SOFTWARE.
155185a700Sflorian */
165185a700Sflorian
175185a700Sflorian #ifndef GENERIC_CAA_257_C
185185a700Sflorian #define GENERIC_CAA_257_C 1
195185a700Sflorian
205185a700Sflorian static unsigned char const alphanumeric[256] = {
215185a700Sflorian /* 0x00-0x0f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
225185a700Sflorian /* 0x10-0x1f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
235185a700Sflorian /* 0x20-0x2f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
245185a700Sflorian /* 0x30-0x3f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
255185a700Sflorian /* 0x40-0x4f */ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
265185a700Sflorian /* 0x50-0x5f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
275185a700Sflorian /* 0x60-0x6f */ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
285185a700Sflorian /* 0x70-0x7f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
295185a700Sflorian /* 0x80-0x8f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
305185a700Sflorian /* 0x90-0x9f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
315185a700Sflorian /* 0xa0-0xaf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
325185a700Sflorian /* 0xb0-0xbf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
335185a700Sflorian /* 0xc0-0xcf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
345185a700Sflorian /* 0xd0-0xdf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
355185a700Sflorian /* 0xe0-0xef */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
365185a700Sflorian /* 0xf0-0xff */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
375185a700Sflorian };
385185a700Sflorian
395185a700Sflorian static inline isc_result_t
totext_caa(ARGS_TOTEXT)405185a700Sflorian totext_caa(ARGS_TOTEXT) {
415185a700Sflorian isc_region_t region;
425185a700Sflorian uint8_t flags;
435185a700Sflorian char buf[256];
445185a700Sflorian
455185a700Sflorian UNUSED(tctx);
465185a700Sflorian
475185a700Sflorian REQUIRE(rdata->type == dns_rdatatype_caa);
485185a700Sflorian REQUIRE(rdata->length >= 3U);
495185a700Sflorian REQUIRE(rdata->data != NULL);
505185a700Sflorian
515185a700Sflorian dns_rdata_toregion(rdata, ®ion);
525185a700Sflorian
535185a700Sflorian /*
545185a700Sflorian * Flags
555185a700Sflorian */
565185a700Sflorian flags = uint8_consume_fromregion(®ion);
575185a700Sflorian snprintf(buf, sizeof(buf), "%u ", flags);
58873f12b9Sflorian RETERR(isc_str_tobuffer(buf, target));
595185a700Sflorian
605185a700Sflorian /*
615185a700Sflorian * Tag
625185a700Sflorian */
63*1fb015a8Sflorian RETERR(txt_totext(®ion, 0, target));
64873f12b9Sflorian RETERR(isc_str_tobuffer(" ", target));
655185a700Sflorian
665185a700Sflorian /*
675185a700Sflorian * Value
685185a700Sflorian */
695185a700Sflorian RETERR(multitxt_totext(®ion, target));
705185a700Sflorian return (ISC_R_SUCCESS);
715185a700Sflorian }
725185a700Sflorian
735185a700Sflorian static inline isc_result_t
fromwire_caa(ARGS_FROMWIRE)745185a700Sflorian fromwire_caa(ARGS_FROMWIRE) {
755185a700Sflorian isc_region_t sr;
765185a700Sflorian unsigned int len, i;
775185a700Sflorian
785185a700Sflorian REQUIRE(type == dns_rdatatype_caa);
795185a700Sflorian
805185a700Sflorian UNUSED(type);
815185a700Sflorian UNUSED(rdclass);
825185a700Sflorian UNUSED(dctx);
835185a700Sflorian UNUSED(options);
845185a700Sflorian
855185a700Sflorian /*
865185a700Sflorian * Flags
875185a700Sflorian */
885185a700Sflorian isc_buffer_activeregion(source, &sr);
895185a700Sflorian if (sr.length < 2)
905185a700Sflorian return (ISC_R_UNEXPECTEDEND);
915185a700Sflorian
925185a700Sflorian /*
935185a700Sflorian * Flags, tag length
945185a700Sflorian */
95637d8eb6Sflorian RETERR(isc_mem_tobuffer(target, sr.base, 2));
965185a700Sflorian len = sr.base[1];
975185a700Sflorian isc_region_consume(&sr, 2);
985185a700Sflorian isc_buffer_forward(source, 2);
995185a700Sflorian
1005185a700Sflorian /*
1015185a700Sflorian * Zero length tag fields are illegal.
1025185a700Sflorian */
1035185a700Sflorian if (sr.length < len || len == 0)
104fbc1dec8Sflorian return (DNS_R_FORMERR);
1055185a700Sflorian
1065185a700Sflorian /* Check the Tag's value */
1075185a700Sflorian for (i = 0; i < len; i++)
1085185a700Sflorian if (!alphanumeric[sr.base[i]])
109fbc1dec8Sflorian return (DNS_R_FORMERR);
1105185a700Sflorian /*
1115185a700Sflorian * Tag + Value
1125185a700Sflorian */
1135185a700Sflorian isc_buffer_forward(source, sr.length);
114637d8eb6Sflorian return (isc_mem_tobuffer(target, sr.base, sr.length));
1155185a700Sflorian }
1165185a700Sflorian
1175185a700Sflorian static inline isc_result_t
towire_caa(ARGS_TOWIRE)1185185a700Sflorian towire_caa(ARGS_TOWIRE) {
1195185a700Sflorian isc_region_t region;
1205185a700Sflorian
1215185a700Sflorian REQUIRE(rdata->type == dns_rdatatype_caa);
1225185a700Sflorian REQUIRE(rdata->length >= 3U);
1235185a700Sflorian REQUIRE(rdata->data != NULL);
1245185a700Sflorian
1255185a700Sflorian UNUSED(cctx);
1265185a700Sflorian
1275185a700Sflorian dns_rdata_toregion(rdata, ®ion);
128637d8eb6Sflorian return (isc_mem_tobuffer(target, region.base, region.length));
1295185a700Sflorian }
1305185a700Sflorian
1315185a700Sflorian #endif /* GENERIC_CAA_257_C */
132