]> CyberLeo.Net >> Repos - FreeBSD/releng/9.3.git/blob - contrib/bind9/lib/dns/rdata/generic/eui48_108.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 / eui48_108.c
1 /*
2  * Copyright (C) 2013, 2014  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_EUI48_108_C
18 #define RDATA_GENERIC_EUI48_108_C
19
20 #include <string.h>
21
22 #define RRTYPE_EUI48_ATTRIBUTES (0)
23
24 static inline isc_result_t
25 fromtext_eui48(ARGS_FROMTEXT) {
26         isc_token_t token;
27         unsigned char eui48[6];
28         unsigned int l0, l1, l2, l3, l4, l5;
29         int n;
30
31         REQUIRE(type == 108);
32
33         UNUSED(type);
34         UNUSED(rdclass);
35         UNUSED(origin);
36         UNUSED(options);
37         UNUSED(callbacks);
38
39         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
40                                       ISC_FALSE));
41         n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x",
42                    &l0, &l1, &l2, &l3, &l4, &l5);
43         if (n != 6 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U ||
44             l4 > 255U || l5 > 255U)
45                 return (DNS_R_BADEUI);
46
47         eui48[0] = l0;
48         eui48[1] = l1;
49         eui48[2] = l2;
50         eui48[3] = l3;
51         eui48[4] = l4;
52         eui48[5] = l5;
53         return (mem_tobuffer(target, eui48, sizeof(eui48)));
54 }
55
56 static inline isc_result_t
57 totext_eui48(ARGS_TOTEXT) {
58         char buf[sizeof("xx-xx-xx-xx-xx-xx")];
59
60         REQUIRE(rdata->type == 108);
61         REQUIRE(rdata->length == 6);
62
63         UNUSED(tctx);
64
65         (void)snprintf(buf, sizeof(buf), "%02x-%02x-%02x-%02x-%02x-%02x",
66                        rdata->data[0], rdata->data[1], rdata->data[2],
67                        rdata->data[3], rdata->data[4], rdata->data[5]);
68         return (str_totext(buf, target));
69 }
70
71 static inline isc_result_t
72 fromwire_eui48(ARGS_FROMWIRE) {
73         isc_region_t sregion;
74
75         REQUIRE(type == 108);
76
77         UNUSED(type);
78         UNUSED(options);
79         UNUSED(rdclass);
80         UNUSED(dctx);
81
82         isc_buffer_activeregion(source, &sregion);
83         if (sregion.length != 6)
84                 return (DNS_R_FORMERR);
85         isc_buffer_forward(source, sregion.length);
86         return (mem_tobuffer(target, sregion.base, sregion.length));
87 }
88
89 static inline isc_result_t
90 towire_eui48(ARGS_TOWIRE) {
91
92         REQUIRE(rdata->type == 108);
93         REQUIRE(rdata->length == 6);
94
95         UNUSED(cctx);
96
97         return (mem_tobuffer(target, rdata->data, rdata->length));
98 }
99
100 static inline int
101 compare_eui48(ARGS_COMPARE) {
102         isc_region_t region1;
103         isc_region_t region2;
104
105         REQUIRE(rdata1->type == rdata2->type);
106         REQUIRE(rdata1->rdclass == rdata2->rdclass);
107         REQUIRE(rdata1->type == 108);
108         REQUIRE(rdata1->length == 6);
109         REQUIRE(rdata2->length == 6);
110
111         dns_rdata_toregion(rdata1, &region1);
112         dns_rdata_toregion(rdata2, &region2);
113         return (isc_region_compare(&region1, &region2));
114 }
115
116 static inline isc_result_t
117 fromstruct_eui48(ARGS_FROMSTRUCT) {
118         dns_rdata_eui48_t *eui48 = source;
119
120         REQUIRE(type == 108);
121         REQUIRE(source != NULL);
122         REQUIRE(eui48->common.rdtype == type);
123         REQUIRE(eui48->common.rdclass == rdclass);
124
125         UNUSED(type);
126         UNUSED(rdclass);
127
128         return (mem_tobuffer(target, eui48->eui48, sizeof(eui48->eui48)));
129 }
130
131 static inline isc_result_t
132 tostruct_eui48(ARGS_TOSTRUCT) {
133         dns_rdata_eui48_t *eui48 = target;
134
135         REQUIRE(rdata->type == 108);
136         REQUIRE(target != NULL);
137         REQUIRE(rdata->length == 6);
138
139         UNUSED(mctx);
140
141         eui48->common.rdclass = rdata->rdclass;
142         eui48->common.rdtype = rdata->type;
143         ISC_LINK_INIT(&eui48->common, link);
144
145         memmove(eui48->eui48, rdata->data, rdata->length);
146         return (ISC_R_SUCCESS);
147 }
148
149 static inline void
150 freestruct_eui48(ARGS_FREESTRUCT) {
151         dns_rdata_eui48_t *eui48 = source;
152
153         REQUIRE(source != NULL);
154         REQUIRE(eui48->common.rdtype == 108);
155
156         return;
157 }
158
159 static inline isc_result_t
160 additionaldata_eui48(ARGS_ADDLDATA) {
161
162         REQUIRE(rdata->type == 108);
163         REQUIRE(rdata->length == 6);
164
165         UNUSED(rdata);
166         UNUSED(add);
167         UNUSED(arg);
168
169         return (ISC_R_SUCCESS);
170 }
171
172 static inline isc_result_t
173 digest_eui48(ARGS_DIGEST) {
174         isc_region_t r;
175
176         REQUIRE(rdata->type == 108);
177         REQUIRE(rdata->length == 6);
178
179         dns_rdata_toregion(rdata, &r);
180
181         return ((digest)(arg, &r));
182 }
183
184 static inline isc_boolean_t
185 checkowner_eui48(ARGS_CHECKOWNER) {
186
187         REQUIRE(type == 108);
188
189         UNUSED(name);
190         UNUSED(type);
191         UNUSED(rdclass);
192         UNUSED(wildcard);
193
194         return (ISC_TRUE);
195 }
196
197 static inline isc_boolean_t
198 checknames_eui48(ARGS_CHECKNAMES) {
199
200         REQUIRE(rdata->type == 108);
201         REQUIRE(rdata->length == 6);
202
203         UNUSED(rdata);
204         UNUSED(owner);
205         UNUSED(bad);
206
207         return (ISC_TRUE);
208 }
209
210 static inline int
211 casecompare_eui48(ARGS_COMPARE) {
212         return (compare_eui48(rdata1, rdata2));
213 }
214
215 #endif  /* RDATA_GENERIC_EUI48_108_C */