1 /* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 * PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 /* $Id: rt_21.c,v 1.11 2020/02/26 18:47:59 florian Exp $ */ 18 19 /* reviewed: Thu Mar 16 15:02:31 PST 2000 by brister */ 20 21 /* RFC1183 */ 22 23 #ifndef RDATA_GENERIC_RT_21_C 24 #define RDATA_GENERIC_RT_21_C 25 26 static inline isc_result_t 27 totext_rt(ARGS_TOTEXT) { 28 isc_region_t region; 29 dns_name_t name; 30 dns_name_t prefix; 31 isc_boolean_t sub; 32 char buf[sizeof("64000")]; 33 unsigned short num; 34 35 REQUIRE(rdata->type == dns_rdatatype_rt); 36 REQUIRE(rdata->length != 0); 37 38 dns_name_init(&name, NULL); 39 dns_name_init(&prefix, NULL); 40 41 dns_rdata_toregion(rdata, ®ion); 42 num = uint16_fromregion(®ion); 43 isc_region_consume(®ion, 2); 44 snprintf(buf, sizeof(buf), "%u", num); 45 RETERR(isc_str_tobuffer(buf, target)); 46 RETERR(isc_str_tobuffer(" ", target)); 47 dns_name_fromregion(&name, ®ion); 48 sub = name_prefix(&name, tctx->origin, &prefix); 49 return (dns_name_totext(&prefix, sub, target)); 50 } 51 52 static inline isc_result_t 53 fromwire_rt(ARGS_FROMWIRE) { 54 dns_name_t name; 55 isc_region_t sregion; 56 isc_region_t tregion; 57 58 REQUIRE(type == dns_rdatatype_rt); 59 60 UNUSED(type); 61 UNUSED(rdclass); 62 63 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); 64 65 dns_name_init(&name, NULL); 66 67 isc_buffer_activeregion(source, &sregion); 68 isc_buffer_availableregion(target, &tregion); 69 if (tregion.length < 2) 70 return (ISC_R_NOSPACE); 71 if (sregion.length < 2) 72 return (ISC_R_UNEXPECTEDEND); 73 memmove(tregion.base, sregion.base, 2); 74 isc_buffer_forward(source, 2); 75 isc_buffer_add(target, 2); 76 return (dns_name_fromwire(&name, source, dctx, options, target)); 77 } 78 79 static inline isc_result_t 80 towire_rt(ARGS_TOWIRE) { 81 dns_name_t name; 82 dns_offsets_t offsets; 83 isc_region_t region; 84 isc_region_t tr; 85 86 REQUIRE(rdata->type == dns_rdatatype_rt); 87 REQUIRE(rdata->length != 0); 88 89 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); 90 isc_buffer_availableregion(target, &tr); 91 dns_rdata_toregion(rdata, ®ion); 92 if (tr.length < 2) 93 return (ISC_R_NOSPACE); 94 memmove(tr.base, region.base, 2); 95 isc_region_consume(®ion, 2); 96 isc_buffer_add(target, 2); 97 98 dns_name_init(&name, offsets); 99 dns_name_fromregion(&name, ®ion); 100 101 return (dns_name_towire(&name, cctx, target)); 102 } 103 104 #endif /* RDATA_GENERIC_RT_21_C */ 105