/src/bind9/lib/dns/rdata/generic/lp_107.c
Line | Count | Source |
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_LP_107_C |
15 | | #define RDATA_GENERIC_LP_107_C |
16 | | |
17 | | #include <string.h> |
18 | | |
19 | | #include <isc/net.h> |
20 | | |
21 | 8.77k | #define RRTYPE_LP_ATTRIBUTES (0) |
22 | | |
23 | | static isc_result_t |
24 | 1.10k | fromtext_lp(ARGS_FROMTEXT) { |
25 | 1.10k | isc_token_t token; |
26 | 1.10k | isc_buffer_t buffer; |
27 | | |
28 | 1.10k | REQUIRE(type == dns_rdatatype_lp); |
29 | | |
30 | 1.10k | UNUSED(type); |
31 | 1.10k | UNUSED(rdclass); |
32 | 1.10k | UNUSED(callbacks); |
33 | | |
34 | 1.10k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
35 | 1.10k | false)); |
36 | 1.09k | if (token.value.as_ulong > 0xffffU) { |
37 | 19 | RETTOK(ISC_R_RANGE); |
38 | 19 | } |
39 | 1.07k | RETERR(uint16_tobuffer(token.value.as_ulong, target)); |
40 | | |
41 | 1.07k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
42 | 1.07k | false)); |
43 | | |
44 | 1.04k | buffer_fromregion(&buffer, &token.value.as_region); |
45 | 1.04k | if (origin == NULL) { |
46 | 1 | origin = dns_rootname; |
47 | 1 | } |
48 | 1.04k | return dns_name_wirefromtext(&buffer, origin, options, target); |
49 | 1.07k | } |
50 | | |
51 | | static isc_result_t |
52 | 832 | totext_lp(ARGS_TOTEXT) { |
53 | 832 | isc_region_t region; |
54 | 832 | dns_name_t name; |
55 | 832 | dns_name_t prefix; |
56 | 832 | unsigned int opts; |
57 | 832 | char buf[sizeof("64000")]; |
58 | 832 | unsigned short num; |
59 | | |
60 | 832 | REQUIRE(rdata->type == dns_rdatatype_lp); |
61 | 832 | REQUIRE(rdata->length != 0); |
62 | | |
63 | 832 | dns_name_init(&name); |
64 | 832 | dns_name_init(&prefix); |
65 | | |
66 | 832 | dns_rdata_toregion(rdata, ®ion); |
67 | 832 | num = uint16_fromregion(®ion); |
68 | 832 | isc_region_consume(®ion, 2); |
69 | 832 | snprintf(buf, sizeof(buf), "%u", num); |
70 | 832 | RETERR(str_totext(buf, target)); |
71 | | |
72 | 832 | RETERR(str_totext(" ", target)); |
73 | | |
74 | 832 | dns_name_fromregion(&name, ®ion); |
75 | 832 | opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT |
76 | 832 | : 0; |
77 | 832 | return dns_name_totext(&prefix, opts, target); |
78 | 832 | } |
79 | | |
80 | | static isc_result_t |
81 | 989 | fromwire_lp(ARGS_FROMWIRE) { |
82 | 989 | dns_name_t name; |
83 | 989 | isc_region_t sregion; |
84 | | |
85 | 989 | REQUIRE(type == dns_rdatatype_lp); |
86 | | |
87 | 989 | UNUSED(type); |
88 | 989 | UNUSED(rdclass); |
89 | | |
90 | 989 | dctx = dns_decompress_setpermitted(dctx, true); |
91 | | |
92 | 989 | dns_name_init(&name); |
93 | | |
94 | 989 | isc_buffer_activeregion(source, &sregion); |
95 | 989 | if (sregion.length < 2) { |
96 | 10 | return ISC_R_UNEXPECTEDEND; |
97 | 10 | } |
98 | 979 | RETERR(mem_tobuffer(target, sregion.base, 2)); |
99 | 913 | isc_buffer_forward(source, 2); |
100 | 913 | return dns_name_fromwire(&name, source, dctx, target); |
101 | 979 | } |
102 | | |
103 | | static isc_result_t |
104 | 418 | towire_lp(ARGS_TOWIRE) { |
105 | 418 | REQUIRE(rdata->type == dns_rdatatype_lp); |
106 | 418 | REQUIRE(rdata->length != 0); |
107 | | |
108 | 418 | UNUSED(cctx); |
109 | | |
110 | 418 | return mem_tobuffer(target, rdata->data, rdata->length); |
111 | 418 | } |
112 | | |
113 | | static int |
114 | 32.6k | compare_lp(ARGS_COMPARE) { |
115 | 32.6k | isc_region_t region1; |
116 | 32.6k | isc_region_t region2; |
117 | | |
118 | 32.6k | REQUIRE(rdata1->type == rdata2->type); |
119 | 32.6k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
120 | 32.6k | REQUIRE(rdata1->type == dns_rdatatype_lp); |
121 | 32.6k | REQUIRE(rdata1->length != 0); |
122 | 32.6k | REQUIRE(rdata2->length != 0); |
123 | | |
124 | 32.6k | dns_rdata_toregion(rdata1, ®ion1); |
125 | 32.6k | dns_rdata_toregion(rdata2, ®ion2); |
126 | | |
127 | 32.6k | return isc_region_compare(®ion1, ®ion2); |
128 | 32.6k | } |
129 | | |
130 | | static isc_result_t |
131 | 0 | fromstruct_lp(ARGS_FROMSTRUCT) { |
132 | 0 | dns_rdata_lp_t *lp = source; |
133 | 0 | isc_region_t region; |
134 | |
|
135 | 0 | REQUIRE(type == dns_rdatatype_lp); |
136 | 0 | REQUIRE(lp != NULL); |
137 | 0 | REQUIRE(lp->common.rdtype == type); |
138 | 0 | REQUIRE(lp->common.rdclass == rdclass); |
139 | |
|
140 | 0 | UNUSED(type); |
141 | 0 | UNUSED(rdclass); |
142 | |
|
143 | 0 | RETERR(uint16_tobuffer(lp->pref, target)); |
144 | 0 | dns_name_toregion(&lp->lp, ®ion); |
145 | 0 | return isc_buffer_copyregion(target, ®ion); |
146 | 0 | } |
147 | | |
148 | | static isc_result_t |
149 | 0 | tostruct_lp(ARGS_TOSTRUCT) { |
150 | 0 | isc_region_t region; |
151 | 0 | dns_rdata_lp_t *lp = target; |
152 | 0 | dns_name_t name; |
153 | |
|
154 | 0 | REQUIRE(rdata->type == dns_rdatatype_lp); |
155 | 0 | REQUIRE(lp != NULL); |
156 | 0 | REQUIRE(rdata->length != 0); |
157 | |
|
158 | 0 | DNS_RDATACOMMON_INIT(lp, rdata->type, rdata->rdclass); |
159 | |
|
160 | 0 | dns_name_init(&name); |
161 | 0 | dns_rdata_toregion(rdata, ®ion); |
162 | 0 | lp->pref = uint16_fromregion(®ion); |
163 | 0 | isc_region_consume(®ion, 2); |
164 | 0 | dns_name_fromregion(&name, ®ion); |
165 | 0 | dns_name_init(&lp->lp); |
166 | 0 | name_duporclone(&name, mctx, &lp->lp); |
167 | 0 | lp->mctx = mctx; |
168 | 0 | return ISC_R_SUCCESS; |
169 | 0 | } |
170 | | |
171 | | static void |
172 | 0 | freestruct_lp(ARGS_FREESTRUCT) { |
173 | 0 | dns_rdata_lp_t *lp = source; |
174 | |
|
175 | 0 | REQUIRE(lp != NULL); |
176 | 0 | REQUIRE(lp->common.rdtype == dns_rdatatype_lp); |
177 | |
|
178 | 0 | if (lp->mctx == NULL) { |
179 | 0 | return; |
180 | 0 | } |
181 | | |
182 | 0 | dns_name_free(&lp->lp, lp->mctx); |
183 | 0 | lp->mctx = NULL; |
184 | 0 | } |
185 | | |
186 | | static isc_result_t |
187 | 0 | additionaldata_lp(ARGS_ADDLDATA) { |
188 | 0 | dns_name_t name; |
189 | 0 | isc_region_t region; |
190 | |
|
191 | 0 | REQUIRE(rdata->type == dns_rdatatype_lp); |
192 | |
|
193 | 0 | UNUSED(owner); |
194 | |
|
195 | 0 | dns_name_init(&name); |
196 | 0 | dns_rdata_toregion(rdata, ®ion); |
197 | 0 | isc_region_consume(®ion, 2); |
198 | 0 | dns_name_fromregion(&name, ®ion); |
199 | |
|
200 | 0 | RETERR((add)(arg, &name, dns_rdatatype_l32, NULL DNS__DB_FILELINE)); |
201 | 0 | return (add)(arg, &name, dns_rdatatype_l64, NULL DNS__DB_FILELINE); |
202 | 0 | } |
203 | | |
204 | | static isc_result_t |
205 | 0 | digest_lp(ARGS_DIGEST) { |
206 | 0 | isc_region_t region; |
207 | |
|
208 | 0 | REQUIRE(rdata->type == dns_rdatatype_lp); |
209 | |
|
210 | 0 | dns_rdata_toregion(rdata, ®ion); |
211 | 0 | return (digest)(arg, ®ion); |
212 | 0 | } |
213 | | |
214 | | static bool |
215 | 0 | checkowner_lp(ARGS_CHECKOWNER) { |
216 | 0 | REQUIRE(type == dns_rdatatype_lp); |
217 | |
|
218 | 0 | UNUSED(type); |
219 | 0 | UNUSED(rdclass); |
220 | 0 | UNUSED(name); |
221 | 0 | UNUSED(wildcard); |
222 | |
|
223 | 0 | return true; |
224 | 0 | } |
225 | | |
226 | | static bool |
227 | 0 | checknames_lp(ARGS_CHECKNAMES) { |
228 | 0 | REQUIRE(rdata->type == dns_rdatatype_lp); |
229 | |
|
230 | 0 | UNUSED(bad); |
231 | 0 | UNUSED(owner); |
232 | |
|
233 | 0 | return true; |
234 | 0 | } |
235 | | |
236 | | static int |
237 | 0 | casecompare_lp(ARGS_COMPARE) { |
238 | 0 | dns_name_t name1; |
239 | 0 | dns_name_t name2; |
240 | 0 | isc_region_t region1; |
241 | 0 | isc_region_t region2; |
242 | 0 | int order; |
243 | |
|
244 | 0 | REQUIRE(rdata1->type == rdata2->type); |
245 | 0 | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
246 | 0 | REQUIRE(rdata1->type == dns_rdatatype_lp); |
247 | 0 | REQUIRE(rdata1->length != 0); |
248 | 0 | REQUIRE(rdata2->length != 0); |
249 | |
|
250 | 0 | order = memcmp(rdata1->data, rdata2->data, 2); |
251 | 0 | if (order != 0) { |
252 | 0 | return order < 0 ? -1 : 1; |
253 | 0 | } |
254 | | |
255 | 0 | dns_name_init(&name1); |
256 | 0 | dns_name_init(&name2); |
257 | |
|
258 | 0 | dns_rdata_toregion(rdata1, ®ion1); |
259 | 0 | dns_rdata_toregion(rdata2, ®ion2); |
260 | |
|
261 | 0 | isc_region_consume(®ion1, 2); |
262 | 0 | isc_region_consume(®ion2, 2); |
263 | |
|
264 | 0 | dns_name_fromregion(&name1, ®ion1); |
265 | 0 | dns_name_fromregion(&name2, ®ion2); |
266 | |
|
267 | 0 | return dns_name_rdatacompare(&name1, &name2); |
268 | 0 | } |
269 | | |
270 | | #endif /* RDATA_GENERIC_LP_107_C */ |