1 /* $NetBSD: l64_106.c,v 1.1.1.4 2014/12/10 03:34:42 christos Exp $ */
2
3 /*
4 * Copyright (C) 2013, 2014 Internet Systems Consortium, Inc. ("ISC")
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef RDATA_GENERIC_L64_106_C
20 #define RDATA_GENERIC_L64_106_C
21
22 #include <string.h>
23
24 #include <isc/net.h>
25
26 #define RRTYPE_L64_ATTRIBUTES (0)
27
28 static inline isc_result_t
fromtext_l64(ARGS_FROMTEXT)29 fromtext_l64(ARGS_FROMTEXT) {
30 isc_token_t token;
31 unsigned char locator[NS_LOCATORSZ];
32
33 REQUIRE(type == 106);
34
35 UNUSED(type);
36 UNUSED(rdclass);
37 UNUSED(origin);
38 UNUSED(options);
39 UNUSED(callbacks);
40
41 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
42 ISC_FALSE));
43 if (token.value.as_ulong > 0xffffU)
44 RETTOK(ISC_R_RANGE);
45 RETERR(uint16_tobuffer(token.value.as_ulong, target));
46
47 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
48 ISC_FALSE));
49
50 if (locator_pton(DNS_AS_STR(token), locator) != 1)
51 RETTOK(DNS_R_SYNTAX);
52 return (mem_tobuffer(target, locator, NS_LOCATORSZ));
53 }
54
55 static inline isc_result_t
totext_l64(ARGS_TOTEXT)56 totext_l64(ARGS_TOTEXT) {
57 isc_region_t region;
58 char buf[sizeof("xxxx:xxxx:xxxx:xxxx")];
59 unsigned short num;
60
61 REQUIRE(rdata->type == 106);
62 REQUIRE(rdata->length == 10);
63
64 UNUSED(tctx);
65
66 dns_rdata_toregion(rdata, ®ion);
67 num = uint16_fromregion(®ion);
68 isc_region_consume(®ion, 2);
69 sprintf(buf, "%u", num);
70 RETERR(str_totext(buf, target));
71
72 RETERR(str_totext(" ", target));
73
74 sprintf(buf, "%x:%x:%x:%x",
75 region.base[0]<<8 | region.base[1],
76 region.base[2]<<8 | region.base[3],
77 region.base[4]<<8 | region.base[5],
78 region.base[6]<<8 | region.base[7]);
79 return (str_totext(buf, target));
80 }
81
82 static inline isc_result_t
fromwire_l64(ARGS_FROMWIRE)83 fromwire_l64(ARGS_FROMWIRE) {
84 isc_region_t sregion;
85
86 REQUIRE(type == 106);
87
88 UNUSED(type);
89 UNUSED(options);
90 UNUSED(rdclass);
91 UNUSED(dctx);
92
93 isc_buffer_activeregion(source, &sregion);
94 if (sregion.length != 10)
95 return (DNS_R_FORMERR);
96 isc_buffer_forward(source, sregion.length);
97 return (mem_tobuffer(target, sregion.base, sregion.length));
98 }
99
100 static inline isc_result_t
towire_l64(ARGS_TOWIRE)101 towire_l64(ARGS_TOWIRE) {
102
103 REQUIRE(rdata->type == 106);
104 REQUIRE(rdata->length == 10);
105
106 UNUSED(cctx);
107
108 return (mem_tobuffer(target, rdata->data, rdata->length));
109 }
110
111 static inline int
compare_l64(ARGS_COMPARE)112 compare_l64(ARGS_COMPARE) {
113 isc_region_t region1;
114 isc_region_t region2;
115
116 REQUIRE(rdata1->type == rdata2->type);
117 REQUIRE(rdata1->rdclass == rdata2->rdclass);
118 REQUIRE(rdata1->type == 106);
119 REQUIRE(rdata1->length == 10);
120 REQUIRE(rdata2->length == 10);
121
122 dns_rdata_toregion(rdata1, ®ion1);
123 dns_rdata_toregion(rdata2, ®ion2);
124 return (isc_region_compare(®ion1, ®ion2));
125 }
126
127 static inline isc_result_t
fromstruct_l64(ARGS_FROMSTRUCT)128 fromstruct_l64(ARGS_FROMSTRUCT) {
129 dns_rdata_l64_t *l64 = source;
130
131 REQUIRE(type == 106);
132 REQUIRE(source != NULL);
133 REQUIRE(l64->common.rdtype == type);
134 REQUIRE(l64->common.rdclass == rdclass);
135
136 UNUSED(type);
137 UNUSED(rdclass);
138
139 RETERR(uint16_tobuffer(l64->pref, target));
140 return (mem_tobuffer(target, l64->l64, sizeof(l64->l64)));
141 }
142
143 static inline isc_result_t
tostruct_l64(ARGS_TOSTRUCT)144 tostruct_l64(ARGS_TOSTRUCT) {
145 isc_region_t region;
146 dns_rdata_l64_t *l64 = target;
147
148 REQUIRE(rdata->type == 106);
149 REQUIRE(target != NULL);
150 REQUIRE(rdata->length == 10);
151
152 UNUSED(mctx);
153
154 l64->common.rdclass = rdata->rdclass;
155 l64->common.rdtype = rdata->type;
156 ISC_LINK_INIT(&l64->common, link);
157
158 dns_rdata_toregion(rdata, ®ion);
159 l64->pref = uint16_fromregion(®ion);
160 memmove(l64->l64, region.base, region.length);
161 return (ISC_R_SUCCESS);
162 }
163
164 static inline void
freestruct_l64(ARGS_FREESTRUCT)165 freestruct_l64(ARGS_FREESTRUCT) {
166 dns_rdata_l64_t *l64 = source;
167
168 REQUIRE(source != NULL);
169 REQUIRE(l64->common.rdtype == 106);
170
171 return;
172 }
173
174 static inline isc_result_t
additionaldata_l64(ARGS_ADDLDATA)175 additionaldata_l64(ARGS_ADDLDATA) {
176
177 REQUIRE(rdata->type == 106);
178 REQUIRE(rdata->length == 10);
179
180 UNUSED(rdata);
181 UNUSED(add);
182 UNUSED(arg);
183
184 return (ISC_R_SUCCESS);
185 }
186
187 static inline isc_result_t
digest_l64(ARGS_DIGEST)188 digest_l64(ARGS_DIGEST) {
189 isc_region_t r;
190
191 REQUIRE(rdata->type == 106);
192 REQUIRE(rdata->length == 10);
193
194 dns_rdata_toregion(rdata, &r);
195
196 return ((digest)(arg, &r));
197 }
198
199 static inline isc_boolean_t
checkowner_l64(ARGS_CHECKOWNER)200 checkowner_l64(ARGS_CHECKOWNER) {
201
202 REQUIRE(type == 106);
203
204 UNUSED(name);
205 UNUSED(type);
206 UNUSED(rdclass);
207 UNUSED(wildcard);
208
209 return (ISC_TRUE);
210 }
211
212 static inline isc_boolean_t
checknames_l64(ARGS_CHECKNAMES)213 checknames_l64(ARGS_CHECKNAMES) {
214
215 REQUIRE(rdata->type == 106);
216 REQUIRE(rdata->length == 10);
217
218 UNUSED(rdata);
219 UNUSED(owner);
220 UNUSED(bad);
221
222 return (ISC_TRUE);
223 }
224
225 static inline int
casecompare_l64(ARGS_COMPARE)226 casecompare_l64(ARGS_COMPARE) {
227 return (compare_l64(rdata1, rdata2));
228 }
229
230 #endif /* RDATA_GENERIC_L64_106_C */
231