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
17*1fb015a8Sflorian /* $Id: nxt_30.c,v 1.13 2020/09/14 08:40:43 florian Exp $ */
185185a700Sflorian
195185a700Sflorian /* reviewed: Wed Mar 15 18:21:15 PST 2000 by brister */
205185a700Sflorian
215185a700Sflorian /* RFC2535 */
225185a700Sflorian
235185a700Sflorian #ifndef RDATA_GENERIC_NXT_30_C
245185a700Sflorian #define RDATA_GENERIC_NXT_30_C
255185a700Sflorian
265185a700Sflorian /*
275185a700Sflorian * The attributes do not include DNS_RDATATYPEATTR_SINGLETON
285185a700Sflorian * because we must be able to handle a parent/child NXT pair.
295185a700Sflorian */
305185a700Sflorian
315185a700Sflorian static inline isc_result_t
totext_nxt(ARGS_TOTEXT)325185a700Sflorian totext_nxt(ARGS_TOTEXT) {
335185a700Sflorian isc_region_t sr;
345185a700Sflorian unsigned int i, j;
355185a700Sflorian dns_name_t name;
365185a700Sflorian dns_name_t prefix;
37*1fb015a8Sflorian int sub;
385185a700Sflorian
395185a700Sflorian REQUIRE(rdata->type == dns_rdatatype_nxt);
405185a700Sflorian REQUIRE(rdata->length != 0);
415185a700Sflorian
425185a700Sflorian dns_name_init(&name, NULL);
435185a700Sflorian dns_name_init(&prefix, NULL);
445185a700Sflorian dns_rdata_toregion(rdata, &sr);
455185a700Sflorian dns_name_fromregion(&name, &sr);
465185a700Sflorian isc_region_consume(&sr, name_length(&name));
475185a700Sflorian sub = name_prefix(&name, tctx->origin, &prefix);
485185a700Sflorian RETERR(dns_name_totext(&prefix, sub, target));
495185a700Sflorian
505185a700Sflorian for (i = 0; i < sr.length; i++) {
515185a700Sflorian if (sr.base[i] != 0)
525185a700Sflorian for (j = 0; j < 8; j++)
535185a700Sflorian if ((sr.base[i] & (0x80 >> j)) != 0) {
545185a700Sflorian dns_rdatatype_t t = i * 8 + j;
55873f12b9Sflorian RETERR(isc_str_tobuffer(" ", target));
56abb8b8a3Sflorian RETERR(dns_rdatatype_totext(t, target));
575185a700Sflorian }
585185a700Sflorian }
595185a700Sflorian return (ISC_R_SUCCESS);
605185a700Sflorian }
615185a700Sflorian
625185a700Sflorian static inline isc_result_t
fromwire_nxt(ARGS_FROMWIRE)635185a700Sflorian fromwire_nxt(ARGS_FROMWIRE) {
645185a700Sflorian isc_region_t sr;
655185a700Sflorian dns_name_t name;
665185a700Sflorian
675185a700Sflorian REQUIRE(type == dns_rdatatype_nxt);
685185a700Sflorian
695185a700Sflorian UNUSED(type);
705185a700Sflorian UNUSED(rdclass);
715185a700Sflorian
725185a700Sflorian dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
735185a700Sflorian
745185a700Sflorian dns_name_init(&name, NULL);
755185a700Sflorian RETERR(dns_name_fromwire(&name, source, dctx, options, target));
765185a700Sflorian
775185a700Sflorian isc_buffer_activeregion(source, &sr);
785185a700Sflorian if (sr.length > 0 && (sr.base[0] & 0x80) == 0 &&
795185a700Sflorian ((sr.length > 16) || sr.base[sr.length - 1] == 0))
805185a700Sflorian return (DNS_R_BADBITMAP);
81637d8eb6Sflorian RETERR(isc_mem_tobuffer(target, sr.base, sr.length));
825185a700Sflorian isc_buffer_forward(source, sr.length);
835185a700Sflorian return (ISC_R_SUCCESS);
845185a700Sflorian }
855185a700Sflorian
865185a700Sflorian static inline isc_result_t
towire_nxt(ARGS_TOWIRE)875185a700Sflorian towire_nxt(ARGS_TOWIRE) {
885185a700Sflorian isc_region_t sr;
895185a700Sflorian dns_name_t name;
905185a700Sflorian dns_offsets_t offsets;
915185a700Sflorian
925185a700Sflorian REQUIRE(rdata->type == dns_rdatatype_nxt);
935185a700Sflorian REQUIRE(rdata->length != 0);
945185a700Sflorian
955185a700Sflorian dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
965185a700Sflorian dns_name_init(&name, offsets);
975185a700Sflorian dns_rdata_toregion(rdata, &sr);
985185a700Sflorian dns_name_fromregion(&name, &sr);
995185a700Sflorian isc_region_consume(&sr, name_length(&name));
1005185a700Sflorian RETERR(dns_name_towire(&name, cctx, target));
1015185a700Sflorian
102637d8eb6Sflorian return (isc_mem_tobuffer(target, sr.base, sr.length));
1035185a700Sflorian }
1045185a700Sflorian
1055185a700Sflorian #endif /* RDATA_GENERIC_NXT_30_C */
106