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