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