xref: /minix/external/bsd/bind/dist/lib/dns/rdata/hs_4/a_1.c (revision bb9622b5)
1 /*	$NetBSD: a_1.c,v 1.5 2014/12/10 04:37:59 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004, 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: a_1.c,v 1.33 2009/12/04 22:06:37 tbox Exp  */
21 
22 /* reviewed: Thu Mar 16 15:58:36 PST 2000 by brister */
23 
24 #ifndef RDATA_HS_4_A_1_C
25 #define RDATA_HS_4_A_1_C
26 
27 #include <isc/net.h>
28 
29 #define RRTYPE_A_ATTRIBUTES (0)
30 
31 static inline isc_result_t
32 fromtext_hs_a(ARGS_FROMTEXT) {
33 	isc_token_t token;
34 	struct in_addr addr;
35 	isc_region_t region;
36 
37 	REQUIRE(type == 1);
38 	REQUIRE(rdclass == 4);
39 
40 	UNUSED(type);
41 	UNUSED(origin);
42 	UNUSED(options);
43 	UNUSED(rdclass);
44 
45 	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
46 				      ISC_FALSE));
47 
48 	if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
49 		RETTOK(DNS_R_BADDOTTEDQUAD);
50 	isc_buffer_availableregion(target, &region);
51 	if (region.length < 4)
52 		return (ISC_R_NOSPACE);
53 	memmove(region.base, &addr, 4);
54 	isc_buffer_add(target, 4);
55 	return (ISC_R_SUCCESS);
56 }
57 
58 static inline isc_result_t
59 totext_hs_a(ARGS_TOTEXT) {
60 	isc_region_t region;
61 
62 	REQUIRE(rdata->type == 1);
63 	REQUIRE(rdata->rdclass == 4);
64 	REQUIRE(rdata->length == 4);
65 
66 	UNUSED(tctx);
67 
68 	dns_rdata_toregion(rdata, &region);
69 	return (inet_totext(AF_INET, &region, target));
70 }
71 
72 static inline isc_result_t
73 fromwire_hs_a(ARGS_FROMWIRE) {
74 	isc_region_t sregion;
75 	isc_region_t tregion;
76 
77 	REQUIRE(type == 1);
78 	REQUIRE(rdclass == 4);
79 
80 	UNUSED(type);
81 	UNUSED(dctx);
82 	UNUSED(options);
83 	UNUSED(rdclass);
84 
85 	isc_buffer_activeregion(source, &sregion);
86 	isc_buffer_availableregion(target, &tregion);
87 	if (sregion.length < 4)
88 		return (ISC_R_UNEXPECTEDEND);
89 	if (tregion.length < 4)
90 		return (ISC_R_NOSPACE);
91 
92 	memmove(tregion.base, sregion.base, 4);
93 	isc_buffer_forward(source, 4);
94 	isc_buffer_add(target, 4);
95 	return (ISC_R_SUCCESS);
96 }
97 
98 static inline isc_result_t
99 towire_hs_a(ARGS_TOWIRE) {
100 	isc_region_t region;
101 
102 	REQUIRE(rdata->type == 1);
103 	REQUIRE(rdata->rdclass == 4);
104 	REQUIRE(rdata->length == 4);
105 
106 	UNUSED(cctx);
107 
108 	isc_buffer_availableregion(target, &region);
109 	if (region.length < rdata->length)
110 		return (ISC_R_NOSPACE);
111 	memmove(region.base, rdata->data, rdata->length);
112 	isc_buffer_add(target, 4);
113 	return (ISC_R_SUCCESS);
114 }
115 
116 static inline int
117 compare_hs_a(ARGS_COMPARE) {
118 	int order;
119 
120 	REQUIRE(rdata1->type == rdata2->type);
121 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
122 	REQUIRE(rdata1->type == 1);
123 	REQUIRE(rdata1->rdclass == 4);
124 	REQUIRE(rdata1->length == 4);
125 	REQUIRE(rdata2->length == 4);
126 
127 	order = memcmp(rdata1->data, rdata2->data, 4);
128 	if (order != 0)
129 		order = (order < 0) ? -1 : 1;
130 
131 	return (order);
132 }
133 
134 static inline isc_result_t
135 fromstruct_hs_a(ARGS_FROMSTRUCT) {
136 	dns_rdata_hs_a_t *a = source;
137 	isc_uint32_t n;
138 
139 	REQUIRE(type == 1);
140 	REQUIRE(rdclass == 4);
141 	REQUIRE(source != NULL);
142 	REQUIRE(a->common.rdtype == type);
143 	REQUIRE(a->common.rdclass == rdclass);
144 
145 	UNUSED(type);
146 	UNUSED(rdclass);
147 
148 	n = ntohl(a->in_addr.s_addr);
149 
150 	return (uint32_tobuffer(n, target));
151 }
152 
153 static inline isc_result_t
154 tostruct_hs_a(ARGS_TOSTRUCT) {
155 	dns_rdata_hs_a_t *a = target;
156 	isc_uint32_t n;
157 	isc_region_t region;
158 
159 	REQUIRE(rdata->type == 1);
160 	REQUIRE(rdata->rdclass == 4);
161 	REQUIRE(rdata->length == 4);
162 
163 	UNUSED(mctx);
164 
165 	a->common.rdclass = rdata->rdclass;
166 	a->common.rdtype = rdata->type;
167 	ISC_LINK_INIT(&a->common, link);
168 
169 	dns_rdata_toregion(rdata, &region);
170 	n = uint32_fromregion(&region);
171 	a->in_addr.s_addr = htonl(n);
172 
173 	return (ISC_R_SUCCESS);
174 }
175 
176 static inline void
177 freestruct_hs_a(ARGS_FREESTRUCT) {
178 	UNUSED(source);
179 
180 	REQUIRE(source != NULL);
181 }
182 
183 static inline isc_result_t
184 additionaldata_hs_a(ARGS_ADDLDATA) {
185 	REQUIRE(rdata->type == 1);
186 	REQUIRE(rdata->rdclass == 4);
187 
188 	UNUSED(rdata);
189 	UNUSED(add);
190 	UNUSED(arg);
191 
192 	return (ISC_R_SUCCESS);
193 }
194 
195 static inline isc_result_t
196 digest_hs_a(ARGS_DIGEST) {
197 	isc_region_t r;
198 
199 	REQUIRE(rdata->type == 1);
200 	REQUIRE(rdata->rdclass == 4);
201 
202 	dns_rdata_toregion(rdata, &r);
203 
204 	return ((digest)(arg, &r));
205 }
206 
207 static inline isc_boolean_t
208 checkowner_hs_a(ARGS_CHECKOWNER) {
209 
210 	REQUIRE(type == 1);
211 	REQUIRE(rdclass == 4);
212 
213 	UNUSED(name);
214 	UNUSED(type);
215 	UNUSED(rdclass);
216 	UNUSED(wildcard);
217 
218 	return (ISC_TRUE);
219 }
220 
221 static inline isc_boolean_t
222 checknames_hs_a(ARGS_CHECKNAMES) {
223 
224 	REQUIRE(rdata->type == 1);
225 	REQUIRE(rdata->rdclass == 4);
226 
227 	UNUSED(rdata);
228 	UNUSED(owner);
229 	UNUSED(bad);
230 
231 	return (ISC_TRUE);
232 }
233 
234 static inline int
235 casecompare_hs_a(ARGS_COMPARE) {
236 	return (compare_hs_a(rdata1, rdata2));
237 }
238 
239 #endif	/* RDATA_HS_4_A_1_C */
240