1 /* $NetBSD: lp_107.c,v 1.1.1.3 2014/12/10 03:34:42 christos Exp $ */
4 * Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
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.
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.
19 #ifndef RDATA_GENERIC_LP_107_C
20 #define RDATA_GENERIC_LP_107_C
26 #define RRTYPE_LP_ATTRIBUTES (0)
28 static inline isc_result_t
29 fromtext_lp(ARGS_FROMTEXT
) {
40 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
42 if (token
.value
.as_ulong
> 0xffffU
)
44 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
46 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
49 dns_name_init(&name
, NULL
);
50 buffer_fromregion(&buffer
, &token
.value
.as_region
);
51 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
52 return (dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
55 static inline isc_result_t
56 totext_lp(ARGS_TOTEXT
) {
61 char buf
[sizeof("64000")];
64 REQUIRE(rdata
->type
== 107);
65 REQUIRE(rdata
->length
!= 0);
67 dns_name_init(&name
, NULL
);
68 dns_name_init(&prefix
, NULL
);
70 dns_rdata_toregion(rdata
, ®ion
);
71 num
= uint16_fromregion(®ion
);
72 isc_region_consume(®ion
, 2);
73 sprintf(buf
, "%u", num
);
74 RETERR(str_totext(buf
, target
));
76 RETERR(str_totext(" ", target
));
78 dns_name_fromregion(&name
, ®ion
);
79 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
80 return (dns_name_totext(&prefix
, sub
, target
));
83 static inline isc_result_t
84 fromwire_lp(ARGS_FROMWIRE
) {
93 dns_decompress_setmethods(dctx
, DNS_COMPRESS_GLOBAL14
);
95 dns_name_init(&name
, NULL
);
97 isc_buffer_activeregion(source
, &sregion
);
98 if (sregion
.length
< 2)
99 return (ISC_R_UNEXPECTEDEND
);
100 RETERR(mem_tobuffer(target
, sregion
.base
, 2));
101 isc_buffer_forward(source
, 2);
102 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
105 static inline isc_result_t
106 towire_lp(ARGS_TOWIRE
) {
108 REQUIRE(rdata
->type
== 107);
109 REQUIRE(rdata
->length
!= 0);
113 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
117 compare_lp(ARGS_COMPARE
) {
118 isc_region_t region1
;
119 isc_region_t region2
;
121 REQUIRE(rdata1
->type
== rdata2
->type
);
122 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
123 REQUIRE(rdata1
->type
== 107);
124 REQUIRE(rdata1
->length
!= 0);
125 REQUIRE(rdata2
->length
!= 0);
127 dns_rdata_toregion(rdata1
, ®ion1
);
128 dns_rdata_toregion(rdata2
, ®ion2
);
130 return (isc_region_compare(®ion1
, ®ion2
));
133 static inline isc_result_t
134 fromstruct_lp(ARGS_FROMSTRUCT
) {
135 dns_rdata_lp_t
*lp
= source
;
138 REQUIRE(type
== 107);
139 REQUIRE(source
!= NULL
);
140 REQUIRE(lp
->common
.rdtype
== type
);
141 REQUIRE(lp
->common
.rdclass
== rdclass
);
146 RETERR(uint16_tobuffer(lp
->pref
, target
));
147 dns_name_toregion(&lp
->lp
, ®ion
);
148 return (isc_buffer_copyregion(target
, ®ion
));
151 static inline isc_result_t
152 tostruct_lp(ARGS_TOSTRUCT
) {
154 dns_rdata_lp_t
*lp
= target
;
157 REQUIRE(rdata
->type
== 107);
158 REQUIRE(target
!= NULL
);
159 REQUIRE(rdata
->length
!= 0);
161 lp
->common
.rdclass
= rdata
->rdclass
;
162 lp
->common
.rdtype
= rdata
->type
;
163 ISC_LINK_INIT(&lp
->common
, link
);
165 dns_name_init(&name
, NULL
);
166 dns_rdata_toregion(rdata
, ®ion
);
167 lp
->pref
= uint16_fromregion(®ion
);
168 isc_region_consume(®ion
, 2);
169 dns_name_fromregion(&name
, ®ion
);
170 dns_name_init(&lp
->lp
, NULL
);
171 RETERR(name_duporclone(&name
, mctx
, &lp
->lp
));
173 return (ISC_R_SUCCESS
);
177 freestruct_lp(ARGS_FREESTRUCT
) {
178 dns_rdata_lp_t
*lp
= source
;
180 REQUIRE(source
!= NULL
);
181 REQUIRE(lp
->common
.rdtype
== 107);
183 if (lp
->mctx
== NULL
)
186 dns_name_free(&lp
->lp
, lp
->mctx
);
190 static inline isc_result_t
191 additionaldata_lp(ARGS_ADDLDATA
) {
193 dns_offsets_t offsets
;
197 REQUIRE(rdata
->type
== 107);
199 dns_name_init(&name
, offsets
);
200 dns_rdata_toregion(rdata
, ®ion
);
201 isc_region_consume(®ion
, 2);
202 dns_name_fromregion(&name
, ®ion
);
204 result
= (add
)(arg
, &name
, dns_rdatatype_l32
);
205 if (result
!= ISC_R_SUCCESS
)
207 return ((add
)(arg
, &name
, dns_rdatatype_l64
));
210 static inline isc_result_t
211 digest_lp(ARGS_DIGEST
) {
214 REQUIRE(rdata
->type
== 107);
216 dns_rdata_toregion(rdata
, ®ion
);
217 return ((digest
)(arg
, ®ion
));
220 static inline isc_boolean_t
221 checkowner_lp(ARGS_CHECKOWNER
) {
223 REQUIRE(type
== 107);
233 static inline isc_boolean_t
234 checknames_lp(ARGS_CHECKNAMES
) {
236 REQUIRE(rdata
->type
== 107);
245 casecompare_lp(ARGS_COMPARE
) {
248 isc_region_t region1
;
249 isc_region_t region2
;
252 REQUIRE(rdata1
->type
== rdata2
->type
);
253 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
254 REQUIRE(rdata1
->type
== 107);
255 REQUIRE(rdata1
->length
!= 0);
256 REQUIRE(rdata2
->length
!= 0);
258 order
= memcmp(rdata1
->data
, rdata2
->data
, 2);
260 return (order
< 0 ? -1 : 1);
262 dns_name_init(&name1
, NULL
);
263 dns_name_init(&name2
, NULL
);
265 dns_rdata_toregion(rdata1
, ®ion1
);
266 dns_rdata_toregion(rdata2
, ®ion2
);
268 isc_region_consume(®ion1
, 2);
269 isc_region_consume(®ion2
, 2);
271 dns_name_fromregion(&name1
, ®ion1
);
272 dns_name_fromregion(&name2
, ®ion2
);
274 return (dns_name_rdatacompare(&name1
, &name2
));
277 #endif /* RDATA_GENERIC_LP_107_C */