1 /* $NetBSD: nid_104.c,v 1.1.1.4 2014/12/10 03:34:42 christos Exp $ */
4 * Copyright (C) 2013, 2014 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_NID_104_C
20 #define RDATA_GENERIC_NID_104_C
26 #define RRTYPE_NID_ATTRIBUTES (0)
28 static inline isc_result_t
29 fromtext_nid(ARGS_FROMTEXT
) {
31 unsigned char locator
[NS_LOCATORSZ
];
41 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
43 if (token
.value
.as_ulong
> 0xffffU
)
45 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
47 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
50 if (locator_pton(DNS_AS_STR(token
), locator
) != 1)
52 return (mem_tobuffer(target
, locator
, NS_LOCATORSZ
));
55 static inline isc_result_t
56 totext_nid(ARGS_TOTEXT
) {
58 char buf
[sizeof("xxxx:xxxx:xxxx:xxxx")];
61 REQUIRE(rdata
->type
== 104);
62 REQUIRE(rdata
->length
!= 0);
66 dns_rdata_toregion(rdata
, ®ion
);
67 num
= uint16_fromregion(®ion
);
68 isc_region_consume(®ion
, 2);
69 sprintf(buf
, "%u", num
);
70 RETERR(str_totext(buf
, target
));
72 RETERR(str_totext(" ", target
));
74 sprintf(buf
, "%x:%x:%x:%x",
75 region
.base
[0]<<8 | region
.base
[1],
76 region
.base
[2]<<8 | region
.base
[3],
77 region
.base
[4]<<8 | region
.base
[5],
78 region
.base
[6]<<8 | region
.base
[7]);
79 return (str_totext(buf
, target
));
82 static inline isc_result_t
83 fromwire_nid(ARGS_FROMWIRE
) {
93 isc_buffer_activeregion(source
, &sregion
);
94 if (sregion
.length
!= 10)
95 return (DNS_R_FORMERR
);
96 isc_buffer_forward(source
, sregion
.length
);
97 return (mem_tobuffer(target
, sregion
.base
, sregion
.length
));
100 static inline isc_result_t
101 towire_nid(ARGS_TOWIRE
) {
103 REQUIRE(rdata
->type
== 104);
104 REQUIRE(rdata
->length
== 10);
108 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
112 compare_nid(ARGS_COMPARE
) {
113 isc_region_t region1
;
114 isc_region_t region2
;
116 REQUIRE(rdata1
->type
== rdata2
->type
);
117 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
118 REQUIRE(rdata1
->type
== 104);
119 REQUIRE(rdata1
->length
== 10);
120 REQUIRE(rdata2
->length
== 10);
122 dns_rdata_toregion(rdata1
, ®ion1
);
123 dns_rdata_toregion(rdata2
, ®ion2
);
124 return (isc_region_compare(®ion1
, ®ion2
));
127 static inline isc_result_t
128 fromstruct_nid(ARGS_FROMSTRUCT
) {
129 dns_rdata_nid_t
*nid
= source
;
131 REQUIRE(type
== 104);
132 REQUIRE(source
!= NULL
);
133 REQUIRE(nid
->common
.rdtype
== type
);
134 REQUIRE(nid
->common
.rdclass
== rdclass
);
139 RETERR(uint16_tobuffer(nid
->pref
, target
));
140 return (mem_tobuffer(target
, nid
->nid
, sizeof(nid
->nid
)));
143 static inline isc_result_t
144 tostruct_nid(ARGS_TOSTRUCT
) {
146 dns_rdata_nid_t
*nid
= target
;
148 REQUIRE(rdata
->type
== 104);
149 REQUIRE(target
!= NULL
);
150 REQUIRE(rdata
->length
== 10);
154 nid
->common
.rdclass
= rdata
->rdclass
;
155 nid
->common
.rdtype
= rdata
->type
;
156 ISC_LINK_INIT(&nid
->common
, link
);
158 dns_rdata_toregion(rdata
, ®ion
);
159 nid
->pref
= uint16_fromregion(®ion
);
160 memmove(nid
->nid
, region
.base
, region
.length
);
161 return (ISC_R_SUCCESS
);
165 freestruct_nid(ARGS_FREESTRUCT
) {
166 dns_rdata_nid_t
*nid
= source
;
168 REQUIRE(source
!= NULL
);
169 REQUIRE(nid
->common
.rdtype
== 104);
174 static inline isc_result_t
175 additionaldata_nid(ARGS_ADDLDATA
) {
177 REQUIRE(rdata
->type
== 104);
178 REQUIRE(rdata
->length
== 10);
184 return (ISC_R_SUCCESS
);
187 static inline isc_result_t
188 digest_nid(ARGS_DIGEST
) {
191 REQUIRE(rdata
->type
== 104);
192 REQUIRE(rdata
->length
== 10);
194 dns_rdata_toregion(rdata
, &r
);
196 return ((digest
)(arg
, &r
));
199 static inline isc_boolean_t
200 checkowner_nid(ARGS_CHECKOWNER
) {
202 REQUIRE(type
== 104);
212 static inline isc_boolean_t
213 checknames_nid(ARGS_CHECKNAMES
) {
215 REQUIRE(rdata
->type
== 104);
216 REQUIRE(rdata
->length
== 10);
226 casecompare_nid(ARGS_COMPARE
) {
227 return (compare_nid(rdata1
, rdata2
));
230 #endif /* RDATA_GENERIC_NID_104_C */