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