/src/bind9/lib/dns/rdata/generic/nid_104.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) Internet Systems Consortium, Inc. ("ISC") |
3 | | * |
4 | | * SPDX-License-Identifier: MPL-2.0 |
5 | | * |
6 | | * This Source Code Form is subject to the terms of the Mozilla Public |
7 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
8 | | * file, you can obtain one at https://mozilla.org/MPL/2.0/. |
9 | | * |
10 | | * See the COPYRIGHT file distributed with this work for additional |
11 | | * information regarding copyright ownership. |
12 | | */ |
13 | | |
14 | | #ifndef RDATA_GENERIC_NID_104_C |
15 | | #define RDATA_GENERIC_NID_104_C |
16 | | |
17 | | #include <string.h> |
18 | | |
19 | | #include <isc/net.h> |
20 | | |
21 | 11.8k | #define RRTYPE_NID_ATTRIBUTES (0) |
22 | | |
23 | | static inline isc_result_t |
24 | 136 | fromtext_nid(ARGS_FROMTEXT) { |
25 | 136 | isc_token_t token; |
26 | 136 | unsigned char locator[NS_LOCATORSZ]; |
27 | | |
28 | 136 | REQUIRE(type == dns_rdatatype_nid); |
29 | | |
30 | 136 | UNUSED(type); |
31 | 136 | UNUSED(rdclass); |
32 | 136 | UNUSED(origin); |
33 | 136 | UNUSED(options); |
34 | 136 | UNUSED(callbacks); |
35 | | |
36 | 136 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
37 | 136 | false)); |
38 | 132 | if (token.value.as_ulong > 0xffffU) { |
39 | 19 | RETTOK(ISC_R_RANGE); |
40 | 19 | } |
41 | 113 | RETERR(uint16_tobuffer(token.value.as_ulong, target)); |
42 | | |
43 | 113 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
44 | 113 | false)); |
45 | | |
46 | 92 | if (locator_pton(DNS_AS_STR(token), locator) != 1) { |
47 | 44 | RETTOK(DNS_R_SYNTAX); |
48 | 44 | } |
49 | 48 | return (mem_tobuffer(target, locator, NS_LOCATORSZ)); |
50 | 92 | } |
51 | | |
52 | | static inline isc_result_t |
53 | 2.30k | totext_nid(ARGS_TOTEXT) { |
54 | 2.30k | isc_region_t region; |
55 | 2.30k | char buf[sizeof("xxxx:xxxx:xxxx:xxxx")]; |
56 | 2.30k | unsigned short num; |
57 | | |
58 | 2.30k | REQUIRE(rdata->type == dns_rdatatype_nid); |
59 | 2.30k | REQUIRE(rdata->length != 0); |
60 | | |
61 | 2.30k | UNUSED(tctx); |
62 | | |
63 | 2.30k | dns_rdata_toregion(rdata, ®ion); |
64 | 2.30k | num = uint16_fromregion(®ion); |
65 | 2.30k | isc_region_consume(®ion, 2); |
66 | 0 | snprintf(buf, sizeof(buf), "%u", num); |
67 | 2.30k | RETERR(str_totext(buf, target)); |
68 | | |
69 | 2.30k | RETERR(str_totext(" ", target)); |
70 | | |
71 | 2.30k | snprintf(buf, sizeof(buf), "%x:%x:%x:%x", |
72 | 2.30k | region.base[0] << 8 | region.base[1], |
73 | 2.30k | region.base[2] << 8 | region.base[3], |
74 | 2.30k | region.base[4] << 8 | region.base[5], |
75 | 2.30k | region.base[6] << 8 | region.base[7]); |
76 | 2.30k | return (str_totext(buf, target)); |
77 | 2.30k | } |
78 | | |
79 | | static inline isc_result_t |
80 | 2.76k | fromwire_nid(ARGS_FROMWIRE) { |
81 | 2.76k | isc_region_t sregion; |
82 | | |
83 | 2.76k | REQUIRE(type == dns_rdatatype_nid); |
84 | | |
85 | 2.76k | UNUSED(type); |
86 | 2.76k | UNUSED(options); |
87 | 2.76k | UNUSED(rdclass); |
88 | 2.76k | UNUSED(dctx); |
89 | | |
90 | 2.76k | isc_buffer_activeregion(source, &sregion); |
91 | 2.76k | if (sregion.length != 10) { |
92 | 51 | return (DNS_R_FORMERR); |
93 | 51 | } |
94 | 2.71k | isc_buffer_forward(source, sregion.length); |
95 | 2.71k | return (mem_tobuffer(target, sregion.base, sregion.length)); |
96 | 2.76k | } |
97 | | |
98 | | static inline isc_result_t |
99 | 1.04k | towire_nid(ARGS_TOWIRE) { |
100 | 1.04k | REQUIRE(rdata->type == dns_rdatatype_nid); |
101 | 1.04k | REQUIRE(rdata->length == 10); |
102 | | |
103 | 1.04k | UNUSED(cctx); |
104 | | |
105 | 1.04k | return (mem_tobuffer(target, rdata->data, rdata->length)); |
106 | 1.04k | } |
107 | | |
108 | | static inline int |
109 | 0 | compare_nid(ARGS_COMPARE) { |
110 | 0 | isc_region_t region1; |
111 | 0 | isc_region_t region2; |
112 | |
|
113 | 0 | REQUIRE(rdata1->type == rdata2->type); |
114 | 0 | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
115 | 0 | REQUIRE(rdata1->type == dns_rdatatype_nid); |
116 | 0 | REQUIRE(rdata1->length == 10); |
117 | 0 | REQUIRE(rdata2->length == 10); |
118 | | |
119 | 0 | dns_rdata_toregion(rdata1, ®ion1); |
120 | 0 | dns_rdata_toregion(rdata2, ®ion2); |
121 | 0 | return (isc_region_compare(®ion1, ®ion2)); |
122 | 0 | } |
123 | | |
124 | | static inline isc_result_t |
125 | 0 | fromstruct_nid(ARGS_FROMSTRUCT) { |
126 | 0 | dns_rdata_nid_t *nid = source; |
127 | |
|
128 | 0 | REQUIRE(type == dns_rdatatype_nid); |
129 | 0 | REQUIRE(nid != NULL); |
130 | 0 | REQUIRE(nid->common.rdtype == type); |
131 | 0 | REQUIRE(nid->common.rdclass == rdclass); |
132 | | |
133 | 0 | UNUSED(type); |
134 | 0 | UNUSED(rdclass); |
135 | |
|
136 | 0 | RETERR(uint16_tobuffer(nid->pref, target)); |
137 | 0 | return (mem_tobuffer(target, nid->nid, sizeof(nid->nid))); |
138 | 0 | } |
139 | | |
140 | | static inline isc_result_t |
141 | 0 | tostruct_nid(ARGS_TOSTRUCT) { |
142 | 0 | isc_region_t region; |
143 | 0 | dns_rdata_nid_t *nid = target; |
144 | |
|
145 | 0 | REQUIRE(rdata->type == dns_rdatatype_nid); |
146 | 0 | REQUIRE(nid != NULL); |
147 | 0 | REQUIRE(rdata->length == 10); |
148 | | |
149 | 0 | UNUSED(mctx); |
150 | |
|
151 | 0 | nid->common.rdclass = rdata->rdclass; |
152 | 0 | nid->common.rdtype = rdata->type; |
153 | 0 | ISC_LINK_INIT(&nid->common, link); |
154 | |
|
155 | 0 | dns_rdata_toregion(rdata, ®ion); |
156 | 0 | nid->pref = uint16_fromregion(®ion); |
157 | 0 | memmove(nid->nid, region.base, region.length); |
158 | 0 | return (ISC_R_SUCCESS); |
159 | 0 | } |
160 | | |
161 | | static inline void |
162 | 0 | freestruct_nid(ARGS_FREESTRUCT) { |
163 | 0 | dns_rdata_nid_t *nid = source; |
164 | |
|
165 | 0 | REQUIRE(nid != NULL); |
166 | 0 | REQUIRE(nid->common.rdtype == dns_rdatatype_nid); |
167 | | |
168 | 0 | return; |
169 | 0 | } |
170 | | |
171 | | static inline isc_result_t |
172 | 0 | additionaldata_nid(ARGS_ADDLDATA) { |
173 | 0 | REQUIRE(rdata->type == dns_rdatatype_nid); |
174 | 0 | REQUIRE(rdata->length == 10); |
175 | | |
176 | 0 | UNUSED(rdata); |
177 | 0 | UNUSED(owner); |
178 | 0 | UNUSED(add); |
179 | 0 | UNUSED(arg); |
180 | |
|
181 | 0 | return (ISC_R_SUCCESS); |
182 | 0 | } |
183 | | |
184 | | static inline isc_result_t |
185 | 0 | digest_nid(ARGS_DIGEST) { |
186 | 0 | isc_region_t r; |
187 | |
|
188 | 0 | REQUIRE(rdata->type == dns_rdatatype_nid); |
189 | 0 | REQUIRE(rdata->length == 10); |
190 | | |
191 | 0 | dns_rdata_toregion(rdata, &r); |
192 | |
|
193 | 0 | return ((digest)(arg, &r)); |
194 | 0 | } |
195 | | |
196 | | static inline bool |
197 | 0 | checkowner_nid(ARGS_CHECKOWNER) { |
198 | 0 | REQUIRE(type == dns_rdatatype_nid); |
199 | | |
200 | 0 | UNUSED(name); |
201 | 0 | UNUSED(type); |
202 | 0 | UNUSED(rdclass); |
203 | 0 | UNUSED(wildcard); |
204 | |
|
205 | 0 | return (true); |
206 | 0 | } |
207 | | |
208 | | static inline bool |
209 | 0 | checknames_nid(ARGS_CHECKNAMES) { |
210 | 0 | REQUIRE(rdata->type == dns_rdatatype_nid); |
211 | 0 | REQUIRE(rdata->length == 10); |
212 | | |
213 | 0 | UNUSED(rdata); |
214 | 0 | UNUSED(owner); |
215 | 0 | UNUSED(bad); |
216 | |
|
217 | 0 | return (true); |
218 | 0 | } |
219 | | |
220 | | static inline int |
221 | 0 | casecompare_nid(ARGS_COMPARE) { |
222 | 0 | return (compare_nid(rdata1, rdata2)); |
223 | 0 | } |
224 | | |
225 | | #endif /* RDATA_GENERIC_NID_104_C */ |