Coverage Report

Created: 2026-01-24 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/lib/dns/rdata/generic/sink_40.c
Line
Count
Source
1
/*
2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3
 *
4
 * SPDX-License-Identifier: MPL-2.0
5
 *
6
 * This Source Code Form is subject to the terms of the Mozilla Public
7
 * License, v. 2.0. If a copy of the MPL was not distributed with this
8
 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9
 *
10
 * See the COPYRIGHT file distributed with this work for additional
11
 * information regarding copyright ownership.
12
 */
13
14
#ifndef RDATA_GENERIC_SINK_40_C
15
#define RDATA_GENERIC_SINK_40_C
16
17
#include <dst/dst.h>
18
19
11.5k
#define RRTYPE_SINK_ATTRIBUTES (0)
20
21
static isc_result_t
22
468
fromtext_sink(ARGS_FROMTEXT) {
23
468
  isc_token_t token;
24
25
468
  REQUIRE(type == dns_rdatatype_sink);
26
27
468
  UNUSED(type);
28
468
  UNUSED(rdclass);
29
468
  UNUSED(origin);
30
468
  UNUSED(options);
31
468
  UNUSED(callbacks);
32
33
  /* meaning */
34
468
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
35
468
              false));
36
465
  if (token.value.as_ulong > 0xffU) {
37
48
    RETTOK(ISC_R_RANGE);
38
48
  }
39
417
  RETERR(uint8_tobuffer(token.value.as_ulong, target));
40
41
  /* coding */
42
417
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
43
417
              false));
44
394
  if (token.value.as_ulong > 0xffU) {
45
34
    RETTOK(ISC_R_RANGE);
46
34
  }
47
360
  RETERR(uint8_tobuffer(token.value.as_ulong, target));
48
49
  /* subcoding */
50
360
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
51
360
              false));
52
343
  if (token.value.as_ulong > 0xffU) {
53
21
    RETTOK(ISC_R_RANGE);
54
21
  }
55
322
  RETERR(uint8_tobuffer(token.value.as_ulong, target));
56
57
322
  return isc_base64_tobuffer(lexer, target, -1);
58
322
}
59
60
static isc_result_t
61
1.69k
totext_sink(ARGS_TOTEXT) {
62
1.69k
  isc_region_t sr;
63
1.69k
  char buf[sizeof("255 255 255")];
64
1.69k
  uint8_t meaning, coding, subcoding;
65
66
1.69k
  REQUIRE(rdata->type == dns_rdatatype_sink);
67
1.69k
  REQUIRE(rdata->length >= 3);
68
69
1.69k
  dns_rdata_toregion(rdata, &sr);
70
71
  /* Meaning, Coding and Subcoding */
72
1.69k
  meaning = uint8_fromregion(&sr);
73
1.69k
  isc_region_consume(&sr, 1);
74
1.69k
  coding = uint8_fromregion(&sr);
75
1.69k
  isc_region_consume(&sr, 1);
76
1.69k
  subcoding = uint8_fromregion(&sr);
77
1.69k
  isc_region_consume(&sr, 1);
78
1.69k
  snprintf(buf, sizeof(buf), "%u %u %u", meaning, coding, subcoding);
79
1.69k
  RETERR(str_totext(buf, target));
80
81
1.69k
  if (sr.length == 0U) {
82
659
    return ISC_R_SUCCESS;
83
659
  }
84
85
  /* data */
86
1.03k
  if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
87
18
    RETERR(str_totext(" (", target));
88
18
  }
89
90
1.03k
  RETERR(str_totext(tctx->linebreak, target));
91
92
1.03k
  if (tctx->width == 0) { /* No splitting */
93
0
    RETERR(isc_base64_totext(&sr, 60, "", target));
94
1.03k
  } else {
95
1.03k
    RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak,
96
1.03k
           target));
97
1.03k
  }
98
99
1.03k
  if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
100
18
    RETERR(str_totext(" )", target));
101
18
  }
102
103
1.03k
  return ISC_R_SUCCESS;
104
1.03k
}
105
106
static isc_result_t
107
2.65k
fromwire_sink(ARGS_FROMWIRE) {
108
2.65k
  isc_region_t sr;
109
110
2.65k
  REQUIRE(type == dns_rdatatype_sink);
111
112
2.65k
  UNUSED(type);
113
2.65k
  UNUSED(rdclass);
114
2.65k
  UNUSED(dctx);
115
116
2.65k
  isc_buffer_activeregion(source, &sr);
117
2.65k
  if (sr.length < 3) {
118
10
    return ISC_R_UNEXPECTEDEND;
119
10
  }
120
121
2.64k
  RETERR(mem_tobuffer(target, sr.base, sr.length));
122
2.41k
  isc_buffer_forward(source, sr.length);
123
2.41k
  return ISC_R_SUCCESS;
124
2.64k
}
125
126
static isc_result_t
127
862
towire_sink(ARGS_TOWIRE) {
128
862
  REQUIRE(rdata->type == dns_rdatatype_sink);
129
862
  REQUIRE(rdata->length >= 3);
130
131
862
  UNUSED(cctx);
132
133
862
  return mem_tobuffer(target, rdata->data, rdata->length);
134
862
}
135
136
static int
137
604
compare_sink(ARGS_COMPARE) {
138
604
  isc_region_t r1;
139
604
  isc_region_t r2;
140
141
604
  REQUIRE(rdata1->type == rdata2->type);
142
604
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
143
604
  REQUIRE(rdata1->type == dns_rdatatype_sink);
144
604
  REQUIRE(rdata1->length >= 3);
145
604
  REQUIRE(rdata2->length >= 3);
146
147
604
  dns_rdata_toregion(rdata1, &r1);
148
604
  dns_rdata_toregion(rdata2, &r2);
149
604
  return isc_region_compare(&r1, &r2);
150
604
}
151
152
static isc_result_t
153
0
fromstruct_sink(ARGS_FROMSTRUCT) {
154
0
  dns_rdata_sink_t *sink = source;
155
156
0
  REQUIRE(type == dns_rdatatype_sink);
157
0
  REQUIRE(sink != NULL);
158
0
  REQUIRE(sink->common.rdtype == type);
159
0
  REQUIRE(sink->common.rdclass == rdclass);
160
161
0
  UNUSED(type);
162
0
  UNUSED(rdclass);
163
164
  /* Meaning */
165
0
  RETERR(uint8_tobuffer(sink->meaning, target));
166
167
  /* Coding */
168
0
  RETERR(uint8_tobuffer(sink->coding, target));
169
170
  /* Subcoding */
171
0
  RETERR(uint8_tobuffer(sink->subcoding, target));
172
173
  /* Data */
174
0
  return mem_tobuffer(target, sink->data, sink->datalen);
175
0
}
176
177
static isc_result_t
178
0
tostruct_sink(ARGS_TOSTRUCT) {
179
0
  dns_rdata_sink_t *sink = target;
180
0
  isc_region_t sr;
181
182
0
  REQUIRE(rdata->type == dns_rdatatype_sink);
183
0
  REQUIRE(sink != NULL);
184
0
  REQUIRE(rdata->length >= 3);
185
186
0
  DNS_RDATACOMMON_INIT(sink, rdata->type, rdata->rdclass);
187
188
0
  dns_rdata_toregion(rdata, &sr);
189
190
  /* Meaning */
191
0
  sink->meaning = uint8_fromregion(&sr);
192
0
  isc_region_consume(&sr, 1);
193
194
  /* Coding */
195
0
  sink->coding = uint8_fromregion(&sr);
196
0
  isc_region_consume(&sr, 1);
197
198
  /* Subcoding */
199
0
  sink->subcoding = uint8_fromregion(&sr);
200
0
  isc_region_consume(&sr, 1);
201
202
  /* Data */
203
0
  sink->datalen = sr.length;
204
0
  sink->data = mem_maybedup(mctx, sr.base, sink->datalen);
205
0
  sink->mctx = mctx;
206
0
  return ISC_R_SUCCESS;
207
0
}
208
209
static void
210
0
freestruct_sink(ARGS_FREESTRUCT) {
211
0
  dns_rdata_sink_t *sink = (dns_rdata_sink_t *)source;
212
213
0
  REQUIRE(sink != NULL);
214
0
  REQUIRE(sink->common.rdtype == dns_rdatatype_sink);
215
216
0
  if (sink->mctx == NULL) {
217
0
    return;
218
0
  }
219
220
0
  if (sink->data != NULL) {
221
0
    isc_mem_free(sink->mctx, sink->data);
222
0
  }
223
0
  sink->mctx = NULL;
224
0
}
225
226
static isc_result_t
227
0
additionaldata_sink(ARGS_ADDLDATA) {
228
0
  REQUIRE(rdata->type == dns_rdatatype_sink);
229
230
0
  UNUSED(rdata);
231
0
  UNUSED(owner);
232
0
  UNUSED(add);
233
0
  UNUSED(arg);
234
235
0
  return ISC_R_SUCCESS;
236
0
}
237
238
static isc_result_t
239
0
digest_sink(ARGS_DIGEST) {
240
0
  isc_region_t r;
241
242
0
  REQUIRE(rdata->type == dns_rdatatype_sink);
243
244
0
  dns_rdata_toregion(rdata, &r);
245
246
0
  return (digest)(arg, &r);
247
0
}
248
249
static bool
250
0
checkowner_sink(ARGS_CHECKOWNER) {
251
0
  REQUIRE(type == dns_rdatatype_sink);
252
253
0
  UNUSED(name);
254
0
  UNUSED(type);
255
0
  UNUSED(rdclass);
256
0
  UNUSED(wildcard);
257
258
0
  return true;
259
0
}
260
261
static bool
262
0
checknames_sink(ARGS_CHECKNAMES) {
263
0
  REQUIRE(rdata->type == dns_rdatatype_sink);
264
265
0
  UNUSED(rdata);
266
0
  UNUSED(owner);
267
0
  UNUSED(bad);
268
269
0
  return true;
270
0
}
271
272
static int
273
0
casecompare_sink(ARGS_COMPARE) {
274
0
  return compare_sink(rdata1, rdata2);
275
0
}
276
#endif /* RDATA_GENERIC_SINK_40_C */