Coverage Report

Created: 2023-06-07 06:23

/src/bind9/lib/dns/rdata/generic/l64_106.c
Line
Count
Source (jump to first uncovered line)
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_L64_106_C
15
#define RDATA_GENERIC_L64_106_C
16
17
#include <string.h>
18
19
#include <isc/net.h>
20
21
12.8k
#define RRTYPE_L64_ATTRIBUTES (0)
22
23
static isc_result_t
24
417
fromtext_l64(ARGS_FROMTEXT) {
25
417
  isc_token_t token;
26
417
  unsigned char locator[NS_LOCATORSZ];
27
28
417
  REQUIRE(type == dns_rdatatype_l64);
29
30
417
  UNUSED(type);
31
417
  UNUSED(rdclass);
32
417
  UNUSED(origin);
33
417
  UNUSED(options);
34
417
  UNUSED(callbacks);
35
36
417
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
37
417
              false));
38
410
  if (token.value.as_ulong > 0xffffU) {
39
24
    RETTOK(ISC_R_RANGE);
40
24
  }
41
386
  RETERR(uint16_tobuffer(token.value.as_ulong, target));
42
43
386
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
44
386
              false));
45
46
354
  if (locator_pton(DNS_AS_STR(token), locator) != 1) {
47
35
    RETTOK(DNS_R_SYNTAX);
48
35
  }
49
319
  return (mem_tobuffer(target, locator, NS_LOCATORSZ));
50
354
}
51
52
static isc_result_t
53
775
totext_l64(ARGS_TOTEXT) {
54
775
  isc_region_t region;
55
775
  char buf[sizeof("xxxx:xxxx:xxxx:xxxx")];
56
775
  unsigned short num;
57
58
775
  REQUIRE(rdata->type == dns_rdatatype_l64);
59
775
  REQUIRE(rdata->length == 10);
60
61
775
  UNUSED(tctx);
62
63
775
  dns_rdata_toregion(rdata, &region);
64
775
  num = uint16_fromregion(&region);
65
775
  isc_region_consume(&region, 2);
66
775
  snprintf(buf, sizeof(buf), "%u", num);
67
775
  RETERR(str_totext(buf, target));
68
69
775
  RETERR(str_totext(" ", target));
70
71
775
  snprintf(buf, sizeof(buf), "%x:%x:%x:%x",
72
775
     region.base[0] << 8 | region.base[1],
73
775
     region.base[2] << 8 | region.base[3],
74
775
     region.base[4] << 8 | region.base[5],
75
775
     region.base[6] << 8 | region.base[7]);
76
775
  return (str_totext(buf, target));
77
775
}
78
79
static isc_result_t
80
971
fromwire_l64(ARGS_FROMWIRE) {
81
971
  isc_region_t sregion;
82
83
971
  REQUIRE(type == dns_rdatatype_l64);
84
85
971
  UNUSED(type);
86
971
  UNUSED(rdclass);
87
971
  UNUSED(dctx);
88
89
971
  isc_buffer_activeregion(source, &sregion);
90
971
  if (sregion.length != 10) {
91
53
    return (DNS_R_FORMERR);
92
53
  }
93
918
  isc_buffer_forward(source, sregion.length);
94
918
  return (mem_tobuffer(target, sregion.base, sregion.length));
95
971
}
96
97
static isc_result_t
98
399
towire_l64(ARGS_TOWIRE) {
99
399
  REQUIRE(rdata->type == dns_rdatatype_l64);
100
399
  REQUIRE(rdata->length == 10);
101
102
399
  UNUSED(cctx);
103
104
399
  return (mem_tobuffer(target, rdata->data, rdata->length));
105
399
}
106
107
static int
108
382
compare_l64(ARGS_COMPARE) {
109
382
  isc_region_t region1;
110
382
  isc_region_t region2;
111
112
382
  REQUIRE(rdata1->type == rdata2->type);
113
382
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
114
382
  REQUIRE(rdata1->type == dns_rdatatype_l64);
115
382
  REQUIRE(rdata1->length == 10);
116
382
  REQUIRE(rdata2->length == 10);
117
118
382
  dns_rdata_toregion(rdata1, &region1);
119
382
  dns_rdata_toregion(rdata2, &region2);
120
382
  return (isc_region_compare(&region1, &region2));
121
382
}
122
123
static isc_result_t
124
0
fromstruct_l64(ARGS_FROMSTRUCT) {
125
0
  dns_rdata_l64_t *l64 = source;
126
127
0
  REQUIRE(type == dns_rdatatype_l64);
128
0
  REQUIRE(l64 != NULL);
129
0
  REQUIRE(l64->common.rdtype == type);
130
0
  REQUIRE(l64->common.rdclass == rdclass);
131
132
0
  UNUSED(type);
133
0
  UNUSED(rdclass);
134
135
0
  RETERR(uint16_tobuffer(l64->pref, target));
136
0
  return (mem_tobuffer(target, l64->l64, sizeof(l64->l64)));
137
0
}
138
139
static isc_result_t
140
0
tostruct_l64(ARGS_TOSTRUCT) {
141
0
  isc_region_t region;
142
0
  dns_rdata_l64_t *l64 = target;
143
144
0
  REQUIRE(rdata->type == dns_rdatatype_l64);
145
0
  REQUIRE(l64 != NULL);
146
0
  REQUIRE(rdata->length == 10);
147
148
0
  UNUSED(mctx);
149
150
0
  l64->common.rdclass = rdata->rdclass;
151
0
  l64->common.rdtype = rdata->type;
152
0
  ISC_LINK_INIT(&l64->common, link);
153
154
0
  dns_rdata_toregion(rdata, &region);
155
0
  l64->pref = uint16_fromregion(&region);
156
0
  memmove(l64->l64, region.base, region.length);
157
0
  return (ISC_R_SUCCESS);
158
0
}
159
160
static void
161
0
freestruct_l64(ARGS_FREESTRUCT) {
162
0
  dns_rdata_l64_t *l64 = source;
163
164
0
  REQUIRE(l64 != NULL);
165
0
  REQUIRE(l64->common.rdtype == dns_rdatatype_l64);
166
167
0
  return;
168
0
}
169
170
static isc_result_t
171
0
additionaldata_l64(ARGS_ADDLDATA) {
172
0
  REQUIRE(rdata->type == dns_rdatatype_l64);
173
0
  REQUIRE(rdata->length == 10);
174
175
0
  UNUSED(rdata);
176
0
  UNUSED(owner);
177
0
  UNUSED(add);
178
0
  UNUSED(arg);
179
180
0
  return (ISC_R_SUCCESS);
181
0
}
182
183
static isc_result_t
184
0
digest_l64(ARGS_DIGEST) {
185
0
  isc_region_t r;
186
187
0
  REQUIRE(rdata->type == dns_rdatatype_l64);
188
0
  REQUIRE(rdata->length == 10);
189
190
0
  dns_rdata_toregion(rdata, &r);
191
192
0
  return ((digest)(arg, &r));
193
0
}
194
195
static bool
196
0
checkowner_l64(ARGS_CHECKOWNER) {
197
0
  REQUIRE(type == dns_rdatatype_l64);
198
199
0
  UNUSED(name);
200
0
  UNUSED(type);
201
0
  UNUSED(rdclass);
202
0
  UNUSED(wildcard);
203
204
0
  return (true);
205
0
}
206
207
static bool
208
0
checknames_l64(ARGS_CHECKNAMES) {
209
0
  REQUIRE(rdata->type == dns_rdatatype_l64);
210
0
  REQUIRE(rdata->length == 10);
211
212
0
  UNUSED(rdata);
213
0
  UNUSED(owner);
214
0
  UNUSED(bad);
215
216
0
  return (true);
217
0
}
218
219
static int
220
0
casecompare_l64(ARGS_COMPARE) {
221
0
  return (compare_l64(rdata1, rdata2));
222
0
}
223
224
#endif /* RDATA_GENERIC_L64_106_C */