1 /*	$NetBSD: aaaa_28.c,v 1.5 2014/12/10 04:37:59 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004, 2005, 2007, 2009, 2014  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 1999-2002  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Id: aaaa_28.c,v 1.47 2009/12/04 22:06:37 tbox Exp  */
21 
22 /* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
23 
24 /* RFC1886 */
25 
26 #ifndef RDATA_IN_1_AAAA_28_C
27 #define RDATA_IN_1_AAAA_28_C
28 
29 #include <isc/net.h>
30 
31 #define RRTYPE_AAAA_ATTRIBUTES (0)
32 
33 static inline isc_result_t
fromtext_in_aaaa(ARGS_FROMTEXT)34 fromtext_in_aaaa(ARGS_FROMTEXT) {
35 	isc_token_t token;
36 	unsigned char addr[16];
37 	isc_region_t region;
38 
39 	REQUIRE(type == 28);
40 	REQUIRE(rdclass == 1);
41 
42 	UNUSED(type);
43 	UNUSED(origin);
44 	UNUSED(options);
45 	UNUSED(rdclass);
46 	UNUSED(callbacks);
47 
48 	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
49 				      ISC_FALSE));
50 
51 	if (inet_pton(AF_INET6, DNS_AS_STR(token), addr) != 1)
52 		RETTOK(DNS_R_BADAAAA);
53 	isc_buffer_availableregion(target, &region);
54 	if (region.length < 16)
55 		return (ISC_R_NOSPACE);
56 	memmove(region.base, addr, 16);
57 	isc_buffer_add(target, 16);
58 	return (ISC_R_SUCCESS);
59 }
60 
61 static inline isc_result_t
totext_in_aaaa(ARGS_TOTEXT)62 totext_in_aaaa(ARGS_TOTEXT) {
63 	isc_region_t region;
64 
65 	UNUSED(tctx);
66 
67 	REQUIRE(rdata->type == 28);
68 	REQUIRE(rdata->rdclass == 1);
69 	REQUIRE(rdata->length == 16);
70 
71 	dns_rdata_toregion(rdata, &region);
72 	return (inet_totext(AF_INET6, &region, target));
73 }
74 
75 static inline isc_result_t
fromwire_in_aaaa(ARGS_FROMWIRE)76 fromwire_in_aaaa(ARGS_FROMWIRE) {
77 	isc_region_t sregion;
78 	isc_region_t tregion;
79 
80 	REQUIRE(type == 28);
81 	REQUIRE(rdclass == 1);
82 
83 	UNUSED(type);
84 	UNUSED(dctx);
85 	UNUSED(options);
86 	UNUSED(rdclass);
87 
88 	isc_buffer_activeregion(source, &sregion);
89 	isc_buffer_availableregion(target, &tregion);
90 	if (sregion.length < 16)
91 		return (ISC_R_UNEXPECTEDEND);
92 	if (tregion.length < 16)
93 		return (ISC_R_NOSPACE);
94 
95 	memmove(tregion.base, sregion.base, 16);
96 	isc_buffer_forward(source, 16);
97 	isc_buffer_add(target, 16);
98 	return (ISC_R_SUCCESS);
99 }
100 
101 static inline isc_result_t
towire_in_aaaa(ARGS_TOWIRE)102 towire_in_aaaa(ARGS_TOWIRE) {
103 	isc_region_t region;
104 
105 	UNUSED(cctx);
106 
107 	REQUIRE(rdata->type == 28);
108 	REQUIRE(rdata->rdclass == 1);
109 	REQUIRE(rdata->length == 16);
110 
111 	isc_buffer_availableregion(target, &region);
112 	if (region.length < rdata->length)
113 		return (ISC_R_NOSPACE);
114 	memmove(region.base, rdata->data, rdata->length);
115 	isc_buffer_add(target, 16);
116 	return (ISC_R_SUCCESS);
117 }
118 
119 static inline int
compare_in_aaaa(ARGS_COMPARE)120 compare_in_aaaa(ARGS_COMPARE) {
121 	isc_region_t r1;
122 	isc_region_t r2;
123 
124 	REQUIRE(rdata1->type == rdata2->type);
125 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
126 	REQUIRE(rdata1->type == 28);
127 	REQUIRE(rdata1->rdclass == 1);
128 	REQUIRE(rdata1->length == 16);
129 	REQUIRE(rdata2->length == 16);
130 
131 	dns_rdata_toregion(rdata1, &r1);
132 	dns_rdata_toregion(rdata2, &r2);
133 	return (isc_region_compare(&r1, &r2));
134 }
135 
136 static inline isc_result_t
fromstruct_in_aaaa(ARGS_FROMSTRUCT)137 fromstruct_in_aaaa(ARGS_FROMSTRUCT) {
138 	dns_rdata_in_aaaa_t *aaaa = source;
139 
140 	REQUIRE(type == 28);
141 	REQUIRE(rdclass == 1);
142 	REQUIRE(source != NULL);
143 	REQUIRE(aaaa->common.rdtype == type);
144 	REQUIRE(aaaa->common.rdclass == rdclass);
145 
146 	UNUSED(type);
147 	UNUSED(rdclass);
148 
149 	return (mem_tobuffer(target, aaaa->in6_addr.s6_addr, 16));
150 }
151 
152 static inline isc_result_t
tostruct_in_aaaa(ARGS_TOSTRUCT)153 tostruct_in_aaaa(ARGS_TOSTRUCT) {
154 	dns_rdata_in_aaaa_t *aaaa = target;
155 	isc_region_t r;
156 
157 	REQUIRE(rdata->type == 28);
158 	REQUIRE(rdata->rdclass == 1);
159 	REQUIRE(target != NULL);
160 	REQUIRE(rdata->length == 16);
161 
162 	UNUSED(mctx);
163 
164 	aaaa->common.rdclass = rdata->rdclass;
165 	aaaa->common.rdtype = rdata->type;
166 	ISC_LINK_INIT(&aaaa->common, link);
167 
168 	dns_rdata_toregion(rdata, &r);
169 	INSIST(r.length == 16);
170 	memmove(aaaa->in6_addr.s6_addr, r.base, 16);
171 
172 	return (ISC_R_SUCCESS);
173 }
174 
175 static inline void
freestruct_in_aaaa(ARGS_FREESTRUCT)176 freestruct_in_aaaa(ARGS_FREESTRUCT) {
177 	dns_rdata_in_aaaa_t *aaaa = source;
178 
179 	REQUIRE(source != NULL);
180 	REQUIRE(aaaa->common.rdclass == 1);
181 	REQUIRE(aaaa->common.rdtype == 28);
182 
183 	UNUSED(aaaa);
184 }
185 
186 static inline isc_result_t
additionaldata_in_aaaa(ARGS_ADDLDATA)187 additionaldata_in_aaaa(ARGS_ADDLDATA) {
188 	REQUIRE(rdata->type == 28);
189 	REQUIRE(rdata->rdclass == 1);
190 
191 	UNUSED(rdata);
192 	UNUSED(add);
193 	UNUSED(arg);
194 
195 	return (ISC_R_SUCCESS);
196 }
197 
198 static inline isc_result_t
digest_in_aaaa(ARGS_DIGEST)199 digest_in_aaaa(ARGS_DIGEST) {
200 	isc_region_t r;
201 
202 	REQUIRE(rdata->type == 28);
203 	REQUIRE(rdata->rdclass == 1);
204 
205 	dns_rdata_toregion(rdata, &r);
206 
207 	return ((digest)(arg, &r));
208 }
209 
210 static inline isc_boolean_t
checkowner_in_aaaa(ARGS_CHECKOWNER)211 checkowner_in_aaaa(ARGS_CHECKOWNER) {
212 
213 	REQUIRE(type == 28);
214 	REQUIRE(rdclass == 1);
215 
216 	UNUSED(type);
217 	UNUSED(rdclass);
218 
219 	return (dns_name_ishostname(name, wildcard));
220 }
221 
222 static inline isc_boolean_t
checknames_in_aaaa(ARGS_CHECKNAMES)223 checknames_in_aaaa(ARGS_CHECKNAMES) {
224 
225 	REQUIRE(rdata->type == 28);
226 	REQUIRE(rdata->rdclass == 1);
227 
228 	UNUSED(rdata);
229 	UNUSED(owner);
230 	UNUSED(bad);
231 
232 	return (ISC_TRUE);
233 }
234 
235 static inline int
casecompare_in_aaaa(ARGS_COMPARE)236 casecompare_in_aaaa(ARGS_COMPARE) {
237 	return (compare_in_aaaa(rdata1, rdata2));
238 }
239 #endif	/* RDATA_IN_1_AAAA_28_C */
240