hinfo_13.c revision 1.1.1.9 1 /* $NetBSD: hinfo_13.c,v 1.1.1.9 2026/01/29 18:19:54 christos Exp $ */
2
3 /*
4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 *
6 * SPDX-License-Identifier: MPL-2.0
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11 *
12 * See the COPYRIGHT file distributed with this work for additional
13 * information regarding copyright ownership.
14 */
15
16 #pragma once
17
18 #define RRTYPE_HINFO_ATTRIBUTES (0)
19
20 static isc_result_t
21 fromtext_hinfo(ARGS_FROMTEXT) {
22 isc_token_t token;
23 int i;
24
25 UNUSED(type);
26 UNUSED(rdclass);
27 UNUSED(origin);
28 UNUSED(options);
29 UNUSED(callbacks);
30
31 REQUIRE(type == dns_rdatatype_hinfo);
32
33 for (i = 0; i < 2; i++) {
34 RETERR(isc_lex_getmastertoken(lexer, &token,
35 isc_tokentype_qstring, false));
36 RETTOK(txt_fromtext(&token.value.as_textregion, target));
37 }
38 return ISC_R_SUCCESS;
39 }
40
41 static isc_result_t
42 totext_hinfo(ARGS_TOTEXT) {
43 isc_region_t region;
44
45 UNUSED(tctx);
46
47 REQUIRE(rdata->type == dns_rdatatype_hinfo);
48 REQUIRE(rdata->length != 0);
49
50 dns_rdata_toregion(rdata, ®ion);
51 RETERR(txt_totext(®ion, true, target));
52 RETERR(str_totext(" ", target));
53 return txt_totext(®ion, true, target);
54 }
55
56 static isc_result_t
57 fromwire_hinfo(ARGS_FROMWIRE) {
58 REQUIRE(type == dns_rdatatype_hinfo);
59
60 UNUSED(type);
61 UNUSED(dctx);
62 UNUSED(rdclass);
63
64 RETERR(txt_fromwire(source, target));
65 return txt_fromwire(source, target);
66 }
67
68 static isc_result_t
69 towire_hinfo(ARGS_TOWIRE) {
70 UNUSED(cctx);
71
72 REQUIRE(rdata->type == dns_rdatatype_hinfo);
73 REQUIRE(rdata->length != 0);
74
75 return mem_tobuffer(target, rdata->data, rdata->length);
76 }
77
78 static int
79 compare_hinfo(ARGS_COMPARE) {
80 isc_region_t r1;
81 isc_region_t r2;
82
83 REQUIRE(rdata1->type == rdata2->type);
84 REQUIRE(rdata1->rdclass == rdata2->rdclass);
85 REQUIRE(rdata1->type == dns_rdatatype_hinfo);
86 REQUIRE(rdata1->length != 0);
87 REQUIRE(rdata2->length != 0);
88
89 dns_rdata_toregion(rdata1, &r1);
90 dns_rdata_toregion(rdata2, &r2);
91 return isc_region_compare(&r1, &r2);
92 }
93
94 static isc_result_t
95 fromstruct_hinfo(ARGS_FROMSTRUCT) {
96 dns_rdata_hinfo_t *hinfo = source;
97
98 REQUIRE(type == dns_rdatatype_hinfo);
99 REQUIRE(hinfo != NULL);
100 REQUIRE(hinfo->common.rdtype == type);
101 REQUIRE(hinfo->common.rdclass == rdclass);
102
103 UNUSED(type);
104 UNUSED(rdclass);
105
106 RETERR(uint8_tobuffer(hinfo->cpu_len, target));
107 RETERR(mem_tobuffer(target, hinfo->cpu, hinfo->cpu_len));
108 RETERR(uint8_tobuffer(hinfo->os_len, target));
109 return mem_tobuffer(target, hinfo->os, hinfo->os_len);
110 }
111
112 static isc_result_t
113 tostruct_hinfo(ARGS_TOSTRUCT) {
114 dns_rdata_hinfo_t *hinfo = target;
115 isc_region_t region;
116
117 REQUIRE(rdata->type == dns_rdatatype_hinfo);
118 REQUIRE(hinfo != NULL);
119 REQUIRE(rdata->length != 0);
120
121 DNS_RDATACOMMON_INIT(hinfo, rdata->type, rdata->rdclass);
122
123 dns_rdata_toregion(rdata, ®ion);
124 hinfo->cpu_len = uint8_fromregion(®ion);
125 isc_region_consume(®ion, 1);
126 hinfo->cpu = mem_maybedup(mctx, region.base, hinfo->cpu_len);
127 isc_region_consume(®ion, hinfo->cpu_len);
128
129 hinfo->os_len = uint8_fromregion(®ion);
130 isc_region_consume(®ion, 1);
131 hinfo->os = mem_maybedup(mctx, region.base, hinfo->os_len);
132 hinfo->mctx = mctx;
133 return ISC_R_SUCCESS;
134 }
135
136 static void
137 freestruct_hinfo(ARGS_FREESTRUCT) {
138 dns_rdata_hinfo_t *hinfo = source;
139
140 REQUIRE(hinfo != NULL);
141
142 if (hinfo->mctx == NULL) {
143 return;
144 }
145
146 if (hinfo->cpu != NULL) {
147 isc_mem_free(hinfo->mctx, hinfo->cpu);
148 }
149 if (hinfo->os != NULL) {
150 isc_mem_free(hinfo->mctx, hinfo->os);
151 }
152 hinfo->mctx = NULL;
153 }
154
155 static isc_result_t
156 additionaldata_hinfo(ARGS_ADDLDATA) {
157 REQUIRE(rdata->type == dns_rdatatype_hinfo);
158
159 UNUSED(rdata);
160 UNUSED(owner);
161 UNUSED(add);
162 UNUSED(arg);
163
164 return ISC_R_SUCCESS;
165 }
166
167 static isc_result_t
168 digest_hinfo(ARGS_DIGEST) {
169 isc_region_t r;
170
171 REQUIRE(rdata->type == dns_rdatatype_hinfo);
172
173 dns_rdata_toregion(rdata, &r);
174
175 return (digest)(arg, &r);
176 }
177
178 static bool
179 checkowner_hinfo(ARGS_CHECKOWNER) {
180 REQUIRE(type == dns_rdatatype_hinfo);
181
182 UNUSED(name);
183 UNUSED(type);
184 UNUSED(rdclass);
185 UNUSED(wildcard);
186
187 return true;
188 }
189
190 static bool
191 checknames_hinfo(ARGS_CHECKNAMES) {
192 REQUIRE(rdata->type == dns_rdatatype_hinfo);
193
194 UNUSED(rdata);
195 UNUSED(owner);
196 UNUSED(bad);
197
198 return true;
199 }
200
201 static int
202 casecompare_hinfo(ARGS_COMPARE) {
203 return compare_hinfo(rdata1, rdata2);
204 }
205