Coverage Report

Created: 2025-11-09 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/lib/dns/rdata/generic/csync_62.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
/* RFC 7477 */
15
16
#ifndef RDATA_GENERIC_CSYNC_62_C
17
#define RDATA_GENERIC_CSYNC_62_C
18
19
14.2k
#define RRTYPE_CSYNC_ATTRIBUTES 0
20
21
static isc_result_t
22
4.96k
fromtext_csync(ARGS_FROMTEXT) {
23
4.96k
  isc_token_t token;
24
25
4.96k
  REQUIRE(type == dns_rdatatype_csync);
26
27
4.96k
  UNUSED(type);
28
4.96k
  UNUSED(rdclass);
29
4.96k
  UNUSED(origin);
30
4.96k
  UNUSED(options);
31
4.96k
  UNUSED(callbacks);
32
33
  /* Serial. */
34
4.96k
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
35
4.96k
              false));
36
4.96k
  RETERR(uint32_tobuffer(token.value.as_ulong, target));
37
38
  /* Flags. */
39
4.96k
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
40
4.96k
              false));
41
4.95k
  if (token.value.as_ulong > 0xffffU) {
42
28
    RETTOK(ISC_R_RANGE);
43
28
  }
44
4.93k
  RETERR(uint16_tobuffer(token.value.as_ulong, target));
45
46
  /* Type Map */
47
4.93k
  return typemap_fromtext(lexer, target, true);
48
4.93k
}
49
50
static isc_result_t
51
2.02k
totext_csync(ARGS_TOTEXT) {
52
2.02k
  unsigned long num;
53
2.02k
  char buf[sizeof("0123456789")]; /* Also TYPE65535 */
54
2.02k
  isc_region_t sr;
55
56
2.02k
  REQUIRE(rdata->type == dns_rdatatype_csync);
57
2.02k
  REQUIRE(rdata->length >= 6);
58
59
2.02k
  UNUSED(tctx);
60
61
2.02k
  dns_rdata_toregion(rdata, &sr);
62
63
2.02k
  num = uint32_fromregion(&sr);
64
2.02k
  isc_region_consume(&sr, 4);
65
2.02k
  snprintf(buf, sizeof(buf), "%lu", num);
66
2.02k
  RETERR(str_totext(buf, target));
67
68
2.02k
  RETERR(str_totext(" ", target));
69
70
2.02k
  num = uint16_fromregion(&sr);
71
2.02k
  isc_region_consume(&sr, 2);
72
2.02k
  snprintf(buf, sizeof(buf), "%lu", num);
73
2.02k
  RETERR(str_totext(buf, target));
74
75
  /*
76
   * Don't leave a trailing space when there's no typemap present.
77
   */
78
2.02k
  if (sr.length > 0) {
79
519
    RETERR(str_totext(" ", target));
80
519
  }
81
2.02k
  return typemap_totext(&sr, NULL, target);
82
2.02k
}
83
84
static isc_result_t
85
3.21k
fromwire_csync(ARGS_FROMWIRE) {
86
3.21k
  isc_region_t sr;
87
88
3.21k
  REQUIRE(type == dns_rdatatype_csync);
89
90
3.21k
  UNUSED(type);
91
3.21k
  UNUSED(rdclass);
92
3.21k
  UNUSED(dctx);
93
94
  /*
95
   * Serial + Flags
96
   */
97
3.21k
  isc_buffer_activeregion(source, &sr);
98
3.21k
  if (sr.length < 6) {
99
14
    return ISC_R_UNEXPECTEDEND;
100
14
  }
101
102
3.19k
  RETERR(mem_tobuffer(target, sr.base, 6));
103
3.00k
  isc_buffer_forward(source, 6);
104
3.00k
  isc_region_consume(&sr, 6);
105
106
3.00k
  RETERR(typemap_test(&sr, true));
107
108
2.89k
  RETERR(mem_tobuffer(target, sr.base, sr.length));
109
2.69k
  isc_buffer_forward(source, sr.length);
110
2.69k
  return ISC_R_SUCCESS;
111
2.89k
}
112
113
static isc_result_t
114
1.02k
towire_csync(ARGS_TOWIRE) {
115
1.02k
  REQUIRE(rdata->type == dns_rdatatype_csync);
116
1.02k
  REQUIRE(rdata->length >= 6);
117
118
1.02k
  UNUSED(cctx);
119
120
1.02k
  return mem_tobuffer(target, rdata->data, rdata->length);
121
1.02k
}
122
123
static int
124
4.94M
compare_csync(ARGS_COMPARE) {
125
4.94M
  isc_region_t r1;
126
4.94M
  isc_region_t r2;
127
128
4.94M
  REQUIRE(rdata1->type == rdata2->type);
129
4.94M
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
130
4.94M
  REQUIRE(rdata1->type == dns_rdatatype_csync);
131
4.94M
  REQUIRE(rdata1->length >= 6);
132
4.94M
  REQUIRE(rdata2->length >= 6);
133
134
4.94M
  dns_rdata_toregion(rdata1, &r1);
135
4.94M
  dns_rdata_toregion(rdata2, &r2);
136
4.94M
  return isc_region_compare(&r1, &r2);
137
4.94M
}
138
139
static isc_result_t
140
0
fromstruct_csync(ARGS_FROMSTRUCT) {
141
0
  dns_rdata_csync_t *csync = source;
142
0
  isc_region_t region;
143
144
0
  REQUIRE(type == dns_rdatatype_csync);
145
0
  REQUIRE(csync != NULL);
146
0
  REQUIRE(csync->common.rdtype == type);
147
0
  REQUIRE(csync->common.rdclass == rdclass);
148
0
  REQUIRE(csync->typebits != NULL || csync->len == 0);
149
150
0
  UNUSED(type);
151
0
  UNUSED(rdclass);
152
153
0
  RETERR(uint32_tobuffer(csync->serial, target));
154
0
  RETERR(uint16_tobuffer(csync->flags, target));
155
156
0
  region.base = csync->typebits;
157
0
  region.length = csync->len;
158
0
  RETERR(typemap_test(&region, true));
159
0
  return mem_tobuffer(target, csync->typebits, csync->len);
160
0
}
161
162
static isc_result_t
163
0
tostruct_csync(ARGS_TOSTRUCT) {
164
0
  isc_region_t region;
165
0
  dns_rdata_csync_t *csync = target;
166
167
0
  REQUIRE(rdata->type == dns_rdatatype_csync);
168
0
  REQUIRE(csync != NULL);
169
0
  REQUIRE(rdata->length != 0);
170
171
0
  DNS_RDATACOMMON_INIT(csync, rdata->type, rdata->rdclass);
172
173
0
  dns_rdata_toregion(rdata, &region);
174
175
0
  csync->serial = uint32_fromregion(&region);
176
0
  isc_region_consume(&region, 4);
177
178
0
  csync->flags = uint16_fromregion(&region);
179
0
  isc_region_consume(&region, 2);
180
181
0
  csync->len = region.length;
182
0
  csync->typebits = mem_maybedup(mctx, region.base, region.length);
183
0
  csync->mctx = mctx;
184
0
  return ISC_R_SUCCESS;
185
0
}
186
187
static void
188
0
freestruct_csync(ARGS_FREESTRUCT) {
189
0
  dns_rdata_csync_t *csync = source;
190
191
0
  REQUIRE(csync != NULL);
192
0
  REQUIRE(csync->common.rdtype == dns_rdatatype_csync);
193
194
0
  if (csync->mctx == NULL) {
195
0
    return;
196
0
  }
197
198
0
  if (csync->typebits != NULL) {
199
0
    isc_mem_free(csync->mctx, csync->typebits);
200
0
  }
201
0
  csync->mctx = NULL;
202
0
}
203
204
static isc_result_t
205
0
additionaldata_csync(ARGS_ADDLDATA) {
206
0
  REQUIRE(rdata->type == dns_rdatatype_csync);
207
208
0
  UNUSED(rdata);
209
0
  UNUSED(owner);
210
0
  UNUSED(add);
211
0
  UNUSED(arg);
212
213
0
  return ISC_R_SUCCESS;
214
0
}
215
216
static isc_result_t
217
0
digest_csync(ARGS_DIGEST) {
218
0
  isc_region_t r;
219
220
0
  REQUIRE(rdata->type == dns_rdatatype_csync);
221
222
0
  dns_rdata_toregion(rdata, &r);
223
0
  return (digest)(arg, &r);
224
0
}
225
226
static bool
227
0
checkowner_csync(ARGS_CHECKOWNER) {
228
0
  REQUIRE(type == dns_rdatatype_csync);
229
230
0
  UNUSED(name);
231
0
  UNUSED(type);
232
0
  UNUSED(rdclass);
233
0
  UNUSED(wildcard);
234
235
0
  return true;
236
0
}
237
238
static bool
239
0
checknames_csync(ARGS_CHECKNAMES) {
240
0
  REQUIRE(rdata->type == dns_rdatatype_csync);
241
242
0
  UNUSED(rdata);
243
0
  UNUSED(owner);
244
0
  UNUSED(bad);
245
246
0
  return true;
247
0
}
248
249
static int
250
0
casecompare_csync(ARGS_COMPARE) {
251
0
  isc_region_t region1;
252
0
  isc_region_t region2;
253
254
0
  REQUIRE(rdata1->type == rdata2->type);
255
0
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
256
0
  REQUIRE(rdata1->type == dns_rdatatype_csync);
257
0
  REQUIRE(rdata1->length >= 6);
258
0
  REQUIRE(rdata2->length >= 6);
259
260
0
  dns_rdata_toregion(rdata1, &region1);
261
0
  dns_rdata_toregion(rdata2, &region2);
262
0
  return isc_region_compare(&region1, &region2);
263
0
}
264
#endif /* RDATA_GENERIC_CSYNC_62_C */