1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7  *
8  * See the COPYRIGHT file distributed with this work for additional
9  * information regarding copyright ownership.
10  */
11 
12 /* RFC1348.  Obsoleted in RFC 1706 - use PTR instead. */
13 
14 #ifndef RDATA_IN_1_NSAP_PTR_23_C
15 #define RDATA_IN_1_NSAP_PTR_23_C
16 
17 #define RRTYPE_NSAP_PTR_ATTRIBUTES (0)
18 
19 static inline isc_result_t
fromtext_in_nsap_ptr(ARGS_FROMTEXT)20 fromtext_in_nsap_ptr(ARGS_FROMTEXT) {
21 	isc_token_t token;
22 	dns_name_t name;
23 	isc_buffer_t buffer;
24 
25 	REQUIRE(type == dns_rdatatype_nsap_ptr);
26 	REQUIRE(rdclass == dns_rdataclass_in);
27 
28 	UNUSED(type);
29 	UNUSED(rdclass);
30 	UNUSED(callbacks);
31 
32 	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
33 				      false));
34 
35 	dns_name_init(&name, NULL);
36 	buffer_fromregion(&buffer, &token.value.as_region);
37 	if (origin == NULL) {
38 		origin = dns_rootname;
39 	}
40 	RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
41 	return (ISC_R_SUCCESS);
42 }
43 
44 static inline isc_result_t
totext_in_nsap_ptr(ARGS_TOTEXT)45 totext_in_nsap_ptr(ARGS_TOTEXT) {
46 	isc_region_t region;
47 	dns_name_t name;
48 	dns_name_t prefix;
49 	bool sub;
50 
51 	REQUIRE(rdata->type == dns_rdatatype_nsap_ptr);
52 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
53 	REQUIRE(rdata->length != 0);
54 
55 	dns_name_init(&name, NULL);
56 	dns_name_init(&prefix, NULL);
57 
58 	dns_rdata_toregion(rdata, &region);
59 	dns_name_fromregion(&name, &region);
60 
61 	sub = name_prefix(&name, tctx->origin, &prefix);
62 
63 	return (dns_name_totext(&prefix, sub, target));
64 }
65 
66 static inline isc_result_t
fromwire_in_nsap_ptr(ARGS_FROMWIRE)67 fromwire_in_nsap_ptr(ARGS_FROMWIRE) {
68 	dns_name_t name;
69 
70 	REQUIRE(type == dns_rdatatype_nsap_ptr);
71 	REQUIRE(rdclass == dns_rdataclass_in);
72 
73 	UNUSED(type);
74 	UNUSED(rdclass);
75 
76 	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
77 
78 	dns_name_init(&name, NULL);
79 	return (dns_name_fromwire(&name, source, dctx, options, target));
80 }
81 
82 static inline isc_result_t
towire_in_nsap_ptr(ARGS_TOWIRE)83 towire_in_nsap_ptr(ARGS_TOWIRE) {
84 	dns_name_t name;
85 	dns_offsets_t offsets;
86 	isc_region_t region;
87 
88 	REQUIRE(rdata->type == dns_rdatatype_nsap_ptr);
89 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
90 	REQUIRE(rdata->length != 0);
91 
92 	dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
93 	dns_name_init(&name, offsets);
94 	dns_rdata_toregion(rdata, &region);
95 	dns_name_fromregion(&name, &region);
96 
97 	return (dns_name_towire(&name, cctx, target));
98 }
99 
100 static inline int
compare_in_nsap_ptr(ARGS_COMPARE)101 compare_in_nsap_ptr(ARGS_COMPARE) {
102 	dns_name_t name1;
103 	dns_name_t name2;
104 	isc_region_t region1;
105 	isc_region_t region2;
106 
107 	REQUIRE(rdata1->type == rdata2->type);
108 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
109 	REQUIRE(rdata1->type == dns_rdatatype_nsap_ptr);
110 	REQUIRE(rdata1->rdclass == dns_rdataclass_in);
111 	REQUIRE(rdata1->length != 0);
112 	REQUIRE(rdata2->length != 0);
113 
114 	dns_name_init(&name1, NULL);
115 	dns_name_init(&name2, NULL);
116 
117 	dns_rdata_toregion(rdata1, &region1);
118 	dns_rdata_toregion(rdata2, &region2);
119 
120 	dns_name_fromregion(&name1, &region1);
121 	dns_name_fromregion(&name2, &region2);
122 
123 	return (dns_name_rdatacompare(&name1, &name2));
124 }
125 
126 static inline isc_result_t
fromstruct_in_nsap_ptr(ARGS_FROMSTRUCT)127 fromstruct_in_nsap_ptr(ARGS_FROMSTRUCT) {
128 	dns_rdata_in_nsap_ptr_t *nsap_ptr = source;
129 	isc_region_t region;
130 
131 	REQUIRE(type == dns_rdatatype_nsap_ptr);
132 	REQUIRE(rdclass == dns_rdataclass_in);
133 	REQUIRE(nsap_ptr != NULL);
134 	REQUIRE(nsap_ptr->common.rdtype == type);
135 	REQUIRE(nsap_ptr->common.rdclass == rdclass);
136 
137 	UNUSED(type);
138 	UNUSED(rdclass);
139 
140 	dns_name_toregion(&nsap_ptr->owner, &region);
141 	return (isc_buffer_copyregion(target, &region));
142 }
143 
144 static inline isc_result_t
tostruct_in_nsap_ptr(ARGS_TOSTRUCT)145 tostruct_in_nsap_ptr(ARGS_TOSTRUCT) {
146 	isc_region_t region;
147 	dns_rdata_in_nsap_ptr_t *nsap_ptr = target;
148 	dns_name_t name;
149 
150 	REQUIRE(rdata->type == dns_rdatatype_nsap_ptr);
151 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
152 	REQUIRE(nsap_ptr != NULL);
153 	REQUIRE(rdata->length != 0);
154 
155 	nsap_ptr->common.rdclass = rdata->rdclass;
156 	nsap_ptr->common.rdtype = rdata->type;
157 	ISC_LINK_INIT(&nsap_ptr->common, link);
158 
159 	dns_name_init(&name, NULL);
160 	dns_rdata_toregion(rdata, &region);
161 	dns_name_fromregion(&name, &region);
162 	dns_name_init(&nsap_ptr->owner, NULL);
163 	RETERR(name_duporclone(&name, mctx, &nsap_ptr->owner));
164 	nsap_ptr->mctx = mctx;
165 	return (ISC_R_SUCCESS);
166 }
167 
168 static inline void
freestruct_in_nsap_ptr(ARGS_FREESTRUCT)169 freestruct_in_nsap_ptr(ARGS_FREESTRUCT) {
170 	dns_rdata_in_nsap_ptr_t *nsap_ptr = source;
171 
172 	REQUIRE(nsap_ptr != NULL);
173 	REQUIRE(nsap_ptr->common.rdclass == dns_rdataclass_in);
174 	REQUIRE(nsap_ptr->common.rdtype == dns_rdatatype_nsap_ptr);
175 
176 	if (nsap_ptr->mctx == NULL) {
177 		return;
178 	}
179 
180 	dns_name_free(&nsap_ptr->owner, nsap_ptr->mctx);
181 	nsap_ptr->mctx = NULL;
182 }
183 
184 static inline isc_result_t
additionaldata_in_nsap_ptr(ARGS_ADDLDATA)185 additionaldata_in_nsap_ptr(ARGS_ADDLDATA) {
186 	REQUIRE(rdata->type == dns_rdatatype_nsap_ptr);
187 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
188 
189 	UNUSED(rdata);
190 	UNUSED(owner);
191 	UNUSED(add);
192 	UNUSED(arg);
193 
194 	return (ISC_R_SUCCESS);
195 }
196 
197 static inline isc_result_t
digest_in_nsap_ptr(ARGS_DIGEST)198 digest_in_nsap_ptr(ARGS_DIGEST) {
199 	isc_region_t r;
200 	dns_name_t name;
201 
202 	REQUIRE(rdata->type == dns_rdatatype_nsap_ptr);
203 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
204 
205 	dns_rdata_toregion(rdata, &r);
206 	dns_name_init(&name, NULL);
207 	dns_name_fromregion(&name, &r);
208 
209 	return (dns_name_digest(&name, digest, arg));
210 }
211 
212 static inline bool
checkowner_in_nsap_ptr(ARGS_CHECKOWNER)213 checkowner_in_nsap_ptr(ARGS_CHECKOWNER) {
214 	REQUIRE(type == dns_rdatatype_nsap_ptr);
215 	REQUIRE(rdclass == dns_rdataclass_in);
216 
217 	UNUSED(name);
218 	UNUSED(type);
219 	UNUSED(rdclass);
220 	UNUSED(wildcard);
221 
222 	return (true);
223 }
224 
225 static inline bool
checknames_in_nsap_ptr(ARGS_CHECKNAMES)226 checknames_in_nsap_ptr(ARGS_CHECKNAMES) {
227 	REQUIRE(rdata->type == dns_rdatatype_nsap_ptr);
228 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
229 
230 	UNUSED(rdata);
231 	UNUSED(owner);
232 	UNUSED(bad);
233 
234 	return (true);
235 }
236 
237 static inline int
casecompare_in_nsap_ptr(ARGS_COMPARE)238 casecompare_in_nsap_ptr(ARGS_COMPARE) {
239 	return (compare_in_nsap_ptr(rdata1, rdata2));
240 }
241 
242 #endif /* RDATA_IN_1_NSAP_PTR_23_C */
243