1/* 2 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (C) 1999-2001 Internet Software Consortium. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 * PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18/* $Id: nsap-ptr_23.c,v 1.40 2009/12/04 22:06:37 tbox Exp $ */ 19 20/* Reviewed: Fri Mar 17 10:16:02 PST 2000 by gson */ 21 22/* RFC1348. Obsoleted in RFC 1706 - use PTR instead. */ 23 24#ifndef RDATA_IN_1_NSAP_PTR_23_C 25#define RDATA_IN_1_NSAP_PTR_23_C 26 27#define RRTYPE_NSAP_PTR_ATTRIBUTES (0) 28 29static inline isc_result_t 30fromtext_in_nsap_ptr(ARGS_FROMTEXT) { 31 isc_token_t token; 32 dns_name_t name; 33 isc_buffer_t buffer; 34 35 REQUIRE(type == 23); 36 REQUIRE(rdclass == 1); 37 38 UNUSED(type); 39 UNUSED(rdclass); 40 UNUSED(callbacks); 41 42 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, 43 ISC_FALSE)); 44 45 dns_name_init(&name, NULL); 46 buffer_fromregion(&buffer, &token.value.as_region); 47 origin = (origin != NULL) ? origin : dns_rootname; 48 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); 49 return (ISC_R_SUCCESS); 50} 51 52static inline isc_result_t 53totext_in_nsap_ptr(ARGS_TOTEXT) { 54 isc_region_t region; 55 dns_name_t name; 56 dns_name_t prefix; 57 isc_boolean_t sub; 58 59 REQUIRE(rdata->type == 23); 60 REQUIRE(rdata->rdclass == 1); 61 REQUIRE(rdata->length != 0); 62 63 dns_name_init(&name, NULL); 64 dns_name_init(&prefix, NULL); 65 66 dns_rdata_toregion(rdata, ®ion); 67 dns_name_fromregion(&name, ®ion); 68 69 sub = name_prefix(&name, tctx->origin, &prefix); 70 71 return (dns_name_totext(&prefix, sub, target)); 72} 73 74static inline isc_result_t 75fromwire_in_nsap_ptr(ARGS_FROMWIRE) { 76 dns_name_t name; 77 78 REQUIRE(type == 23); 79 REQUIRE(rdclass == 1); 80 81 UNUSED(type); 82 UNUSED(rdclass); 83 84 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); 85 86 dns_name_init(&name, NULL); 87 return (dns_name_fromwire(&name, source, dctx, options, target)); 88} 89 90static inline isc_result_t 91towire_in_nsap_ptr(ARGS_TOWIRE) { 92 dns_name_t name; 93 dns_offsets_t offsets; 94 isc_region_t region; 95 96 REQUIRE(rdata->type == 23); 97 REQUIRE(rdata->rdclass == 1); 98 REQUIRE(rdata->length != 0); 99 100 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); 101 dns_name_init(&name, offsets); 102 dns_rdata_toregion(rdata, ®ion); 103 dns_name_fromregion(&name, ®ion); 104 105 return (dns_name_towire(&name, cctx, target)); 106} 107 108static inline int 109compare_in_nsap_ptr(ARGS_COMPARE) { 110 dns_name_t name1; 111 dns_name_t name2; 112 isc_region_t region1; 113 isc_region_t region2; 114 115 REQUIRE(rdata1->type == rdata2->type); 116 REQUIRE(rdata1->rdclass == rdata2->rdclass); 117 REQUIRE(rdata1->type == 23); 118 REQUIRE(rdata1->rdclass == 1); 119 REQUIRE(rdata1->length != 0); 120 REQUIRE(rdata2->length != 0); 121 122 dns_name_init(&name1, NULL); 123 dns_name_init(&name2, NULL); 124 125 dns_rdata_toregion(rdata1, ®ion1); 126 dns_rdata_toregion(rdata2, ®ion2); 127 128 dns_name_fromregion(&name1, ®ion1); 129 dns_name_fromregion(&name2, ®ion2); 130 131 return (dns_name_rdatacompare(&name1, &name2)); 132} 133 134static inline isc_result_t 135fromstruct_in_nsap_ptr(ARGS_FROMSTRUCT) { 136 dns_rdata_in_nsap_ptr_t *nsap_ptr = source; 137 isc_region_t region; 138 139 REQUIRE(type == 23); 140 REQUIRE(rdclass == 1); 141 REQUIRE(source != NULL); 142 REQUIRE(nsap_ptr->common.rdtype == type); 143 REQUIRE(nsap_ptr->common.rdclass == rdclass); 144 145 UNUSED(type); 146 UNUSED(rdclass); 147 148 dns_name_toregion(&nsap_ptr->owner, ®ion); 149 return (isc_buffer_copyregion(target, ®ion)); 150} 151 152static inline isc_result_t 153tostruct_in_nsap_ptr(ARGS_TOSTRUCT) { 154 isc_region_t region; 155 dns_rdata_in_nsap_ptr_t *nsap_ptr = target; 156 dns_name_t name; 157 158 REQUIRE(rdata->type == 23); 159 REQUIRE(rdata->rdclass == 1); 160 REQUIRE(target != NULL); 161 REQUIRE(rdata->length != 0); 162 163 nsap_ptr->common.rdclass = rdata->rdclass; 164 nsap_ptr->common.rdtype = rdata->type; 165 ISC_LINK_INIT(&nsap_ptr->common, link); 166 167 dns_name_init(&name, NULL); 168 dns_rdata_toregion(rdata, ®ion); 169 dns_name_fromregion(&name, ®ion); 170 dns_name_init(&nsap_ptr->owner, NULL); 171 RETERR(name_duporclone(&name, mctx, &nsap_ptr->owner)); 172 nsap_ptr->mctx = mctx; 173 return (ISC_R_SUCCESS); 174} 175 176static inline void 177freestruct_in_nsap_ptr(ARGS_FREESTRUCT) { 178 dns_rdata_in_nsap_ptr_t *nsap_ptr = source; 179 180 REQUIRE(source != NULL); 181 REQUIRE(nsap_ptr->common.rdclass == 1); 182 REQUIRE(nsap_ptr->common.rdtype == 23); 183 184 if (nsap_ptr->mctx == NULL) 185 return; 186 187 dns_name_free(&nsap_ptr->owner, nsap_ptr->mctx); 188 nsap_ptr->mctx = NULL; 189} 190 191static inline isc_result_t 192additionaldata_in_nsap_ptr(ARGS_ADDLDATA) { 193 REQUIRE(rdata->type == 23); 194 REQUIRE(rdata->rdclass == 1); 195 196 UNUSED(rdata); 197 UNUSED(add); 198 UNUSED(arg); 199 200 return (ISC_R_SUCCESS); 201} 202 203static inline isc_result_t 204digest_in_nsap_ptr(ARGS_DIGEST) { 205 isc_region_t r; 206 dns_name_t name; 207 208 REQUIRE(rdata->type == 23); 209 REQUIRE(rdata->rdclass == 1); 210 211 dns_rdata_toregion(rdata, &r); 212 dns_name_init(&name, NULL); 213 dns_name_fromregion(&name, &r); 214 215 return (dns_name_digest(&name, digest, arg)); 216} 217 218static inline isc_boolean_t 219checkowner_in_nsap_ptr(ARGS_CHECKOWNER) { 220 221 REQUIRE(type == 23); 222 REQUIRE(rdclass == 1); 223 224 UNUSED(name); 225 UNUSED(type); 226 UNUSED(rdclass); 227 UNUSED(wildcard); 228 229 return (ISC_TRUE); 230} 231 232static inline isc_boolean_t 233checknames_in_nsap_ptr(ARGS_CHECKNAMES) { 234 235 REQUIRE(rdata->type == 23); 236 REQUIRE(rdata->rdclass == 1); 237 238 UNUSED(rdata); 239 UNUSED(owner); 240 UNUSED(bad); 241 242 return (ISC_TRUE); 243} 244 245static inline int 246casecompare_in_nsap_ptr(ARGS_COMPARE) { 247 return (compare_in_nsap_ptr(rdata1, rdata2)); 248} 249 250#endif /* RDATA_IN_1_NSAP_PTR_23_C */ 251