Merge branch 'vendor/FILE'
[dragonfly.git] / contrib / bind / lib / dns / rdata / in_1 / aaaa_28.c
1 /*
2  * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2002  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: aaaa_28.c,v 1.45 2007/06/19 23:47:17 tbox Exp $ */
19
20 /* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
21
22 /* RFC1886 */
23
24 #ifndef RDATA_IN_1_AAAA_28_C
25 #define RDATA_IN_1_AAAA_28_C
26
27 #include <isc/net.h>
28
29 #define RRTYPE_AAAA_ATTRIBUTES (0)
30
31 static inline isc_result_t
32 fromtext_in_aaaa(ARGS_FROMTEXT) {
33         isc_token_t token;
34         unsigned char addr[16];
35         isc_region_t region;
36
37         REQUIRE(type == 28);
38         REQUIRE(rdclass == 1);
39
40         UNUSED(type);
41         UNUSED(origin);
42         UNUSED(options);
43         UNUSED(rdclass);
44         UNUSED(callbacks);
45
46         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
47                                       ISC_FALSE));
48
49         if (inet_pton(AF_INET6, DNS_AS_STR(token), addr) != 1)
50                 RETTOK(DNS_R_BADAAAA);
51         isc_buffer_availableregion(target, &region);
52         if (region.length < 16)
53                 return (ISC_R_NOSPACE);
54         memcpy(region.base, addr, 16);
55         isc_buffer_add(target, 16);
56         return (ISC_R_SUCCESS);
57 }
58
59 static inline isc_result_t
60 totext_in_aaaa(ARGS_TOTEXT) {
61         isc_region_t region;
62
63         UNUSED(tctx);
64
65         REQUIRE(rdata->type == 28);
66         REQUIRE(rdata->rdclass == 1);
67         REQUIRE(rdata->length == 16);
68
69         dns_rdata_toregion(rdata, &region);
70         return (inet_totext(AF_INET6, &region, target));
71 }
72
73 static inline isc_result_t
74 fromwire_in_aaaa(ARGS_FROMWIRE) {
75         isc_region_t sregion;
76         isc_region_t tregion;
77
78         REQUIRE(type == 28);
79         REQUIRE(rdclass == 1);
80
81         UNUSED(type);
82         UNUSED(dctx);
83         UNUSED(options);
84         UNUSED(rdclass);
85
86         isc_buffer_activeregion(source, &sregion);
87         isc_buffer_availableregion(target, &tregion);
88         if (sregion.length < 16)
89                 return (ISC_R_UNEXPECTEDEND);
90         if (tregion.length < 16)
91                 return (ISC_R_NOSPACE);
92
93         memcpy(tregion.base, sregion.base, 16);
94         isc_buffer_forward(source, 16);
95         isc_buffer_add(target, 16);
96         return (ISC_R_SUCCESS);
97 }
98
99 static inline isc_result_t
100 towire_in_aaaa(ARGS_TOWIRE) {
101         isc_region_t region;
102
103         UNUSED(cctx);
104
105         REQUIRE(rdata->type == 28);
106         REQUIRE(rdata->rdclass == 1);
107         REQUIRE(rdata->length == 16);
108
109         isc_buffer_availableregion(target, &region);
110         if (region.length < rdata->length)
111                 return (ISC_R_NOSPACE);
112         memcpy(region.base, rdata->data, rdata->length);
113         isc_buffer_add(target, 16);
114         return (ISC_R_SUCCESS);
115 }
116
117 static inline int
118 compare_in_aaaa(ARGS_COMPARE) {
119         isc_region_t r1;
120         isc_region_t r2;
121
122         REQUIRE(rdata1->type == rdata2->type);
123         REQUIRE(rdata1->rdclass == rdata2->rdclass);
124         REQUIRE(rdata1->type == 28);
125         REQUIRE(rdata1->rdclass == 1);
126         REQUIRE(rdata1->length == 16);
127         REQUIRE(rdata2->length == 16);
128
129         dns_rdata_toregion(rdata1, &r1);
130         dns_rdata_toregion(rdata2, &r2);
131         return (isc_region_compare(&r1, &r2));
132 }
133
134 static inline isc_result_t
135 fromstruct_in_aaaa(ARGS_FROMSTRUCT) {
136         dns_rdata_in_aaaa_t *aaaa = source;
137
138         REQUIRE(type == 28);
139         REQUIRE(rdclass == 1);
140         REQUIRE(source != NULL);
141         REQUIRE(aaaa->common.rdtype == type);
142         REQUIRE(aaaa->common.rdclass == rdclass);
143
144         UNUSED(type);
145         UNUSED(rdclass);
146
147         return (mem_tobuffer(target, aaaa->in6_addr.s6_addr, 16));
148 }
149
150 static inline isc_result_t
151 tostruct_in_aaaa(ARGS_TOSTRUCT) {
152         dns_rdata_in_aaaa_t *aaaa = target;
153         isc_region_t r;
154
155         REQUIRE(rdata->type == 28);
156         REQUIRE(rdata->rdclass == 1);
157         REQUIRE(target != NULL);
158         REQUIRE(rdata->length == 16);
159
160         UNUSED(mctx);
161
162         aaaa->common.rdclass = rdata->rdclass;
163         aaaa->common.rdtype = rdata->type;
164         ISC_LINK_INIT(&aaaa->common, link);
165
166         dns_rdata_toregion(rdata, &r);
167         INSIST(r.length == 16);
168         memcpy(aaaa->in6_addr.s6_addr, r.base, 16);
169
170         return (ISC_R_SUCCESS);
171 }
172
173 static inline void
174 freestruct_in_aaaa(ARGS_FREESTRUCT) {
175         dns_rdata_in_aaaa_t *aaaa = source;
176
177         REQUIRE(source != NULL);
178         REQUIRE(aaaa->common.rdclass == 1);
179         REQUIRE(aaaa->common.rdtype == 28);
180
181         UNUSED(aaaa);
182 }
183
184 static inline isc_result_t
185 additionaldata_in_aaaa(ARGS_ADDLDATA) {
186         REQUIRE(rdata->type == 28);
187         REQUIRE(rdata->rdclass == 1);
188
189         UNUSED(rdata);
190         UNUSED(add);
191         UNUSED(arg);
192
193         return (ISC_R_SUCCESS);
194 }
195
196 static inline isc_result_t
197 digest_in_aaaa(ARGS_DIGEST) {
198         isc_region_t r;
199
200         REQUIRE(rdata->type == 28);
201         REQUIRE(rdata->rdclass == 1);
202
203         dns_rdata_toregion(rdata, &r);
204
205         return ((digest)(arg, &r));
206 }
207
208 static inline isc_boolean_t
209 checkowner_in_aaaa(ARGS_CHECKOWNER) {
210
211         REQUIRE(type == 28);
212         REQUIRE(rdclass == 1);
213
214         UNUSED(type);
215         UNUSED(rdclass);
216
217         return (dns_name_ishostname(name, wildcard));
218 }
219
220 static inline isc_boolean_t
221 checknames_in_aaaa(ARGS_CHECKNAMES) {
222
223         REQUIRE(rdata->type == 28);
224         REQUIRE(rdata->rdclass == 1);
225
226         UNUSED(rdata);
227         UNUSED(owner);
228         UNUSED(bad);
229
230         return (ISC_TRUE);
231 }
232
233 #endif  /* RDATA_IN_1_AAAA_28_C */