Coverage Report

Created: 2026-01-10 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/lib/dns/rdata/generic/l32_105.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_L32_105_C
15
#define RDATA_GENERIC_L32_105_C
16
17
#include <string.h>
18
19
#include <isc/net.h>
20
21
11.2k
#define RRTYPE_L32_ATTRIBUTES (0)
22
23
static isc_result_t
24
96
fromtext_l32(ARGS_FROMTEXT) {
25
96
  isc_token_t token;
26
96
  struct in_addr addr;
27
96
  isc_region_t region;
28
29
96
  REQUIRE(type == dns_rdatatype_l32);
30
31
96
  UNUSED(type);
32
96
  UNUSED(rdclass);
33
96
  UNUSED(origin);
34
96
  UNUSED(options);
35
96
  UNUSED(callbacks);
36
37
96
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
38
96
              false));
39
94
  if (token.value.as_ulong > 0xffffU) {
40
17
    RETTOK(ISC_R_RANGE);
41
17
  }
42
77
  RETERR(uint16_tobuffer(token.value.as_ulong, target));
43
44
77
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
45
77
              false));
46
47
47
  if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) {
48
3
    RETTOK(DNS_R_BADDOTTEDQUAD);
49
3
  }
50
44
  isc_buffer_availableregion(target, &region);
51
44
  if (region.length < 4) {
52
0
    return ISC_R_NOSPACE;
53
0
  }
54
44
  memmove(region.base, &addr, 4);
55
44
  isc_buffer_add(target, 4);
56
44
  return ISC_R_SUCCESS;
57
44
}
58
59
static isc_result_t
60
2.03k
totext_l32(ARGS_TOTEXT) {
61
2.03k
  isc_region_t region;
62
2.03k
  char buf[sizeof("65000")];
63
2.03k
  unsigned short num;
64
65
2.03k
  REQUIRE(rdata->type == dns_rdatatype_l32);
66
2.03k
  REQUIRE(rdata->length == 6);
67
68
2.03k
  UNUSED(tctx);
69
70
2.03k
  dns_rdata_toregion(rdata, &region);
71
2.03k
  num = uint16_fromregion(&region);
72
2.03k
  isc_region_consume(&region, 2);
73
2.03k
  snprintf(buf, sizeof(buf), "%u", num);
74
2.03k
  RETERR(str_totext(buf, target));
75
76
2.03k
  RETERR(str_totext(" ", target));
77
78
2.03k
  return inet_totext(AF_INET, tctx->flags, &region, target);
79
2.03k
}
80
81
static isc_result_t
82
2.54k
fromwire_l32(ARGS_FROMWIRE) {
83
2.54k
  isc_region_t sregion;
84
85
2.54k
  REQUIRE(type == dns_rdatatype_l32);
86
87
2.54k
  UNUSED(type);
88
2.54k
  UNUSED(rdclass);
89
2.54k
  UNUSED(dctx);
90
91
2.54k
  isc_buffer_activeregion(source, &sregion);
92
2.54k
  if (sregion.length != 6) {
93
20
    return DNS_R_FORMERR;
94
20
  }
95
2.52k
  isc_buffer_forward(source, sregion.length);
96
2.52k
  return mem_tobuffer(target, sregion.base, sregion.length);
97
2.54k
}
98
99
static isc_result_t
100
1.03k
towire_l32(ARGS_TOWIRE) {
101
1.03k
  REQUIRE(rdata->type == dns_rdatatype_l32);
102
1.03k
  REQUIRE(rdata->length == 6);
103
104
1.03k
  UNUSED(cctx);
105
106
1.03k
  return mem_tobuffer(target, rdata->data, rdata->length);
107
1.03k
}
108
109
static int
110
1.28k
compare_l32(ARGS_COMPARE) {
111
1.28k
  isc_region_t region1;
112
1.28k
  isc_region_t region2;
113
114
1.28k
  REQUIRE(rdata1->type == rdata2->type);
115
1.28k
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
116
1.28k
  REQUIRE(rdata1->type == dns_rdatatype_l32);
117
1.28k
  REQUIRE(rdata1->length == 6);
118
1.28k
  REQUIRE(rdata2->length == 6);
119
120
1.28k
  dns_rdata_toregion(rdata1, &region1);
121
1.28k
  dns_rdata_toregion(rdata2, &region2);
122
1.28k
  return isc_region_compare(&region1, &region2);
123
1.28k
}
124
125
static isc_result_t
126
0
fromstruct_l32(ARGS_FROMSTRUCT) {
127
0
  dns_rdata_l32_t *l32 = source;
128
0
  uint32_t n;
129
130
0
  REQUIRE(type == dns_rdatatype_l32);
131
0
  REQUIRE(l32 != NULL);
132
0
  REQUIRE(l32->common.rdtype == type);
133
0
  REQUIRE(l32->common.rdclass == rdclass);
134
135
0
  UNUSED(type);
136
0
  UNUSED(rdclass);
137
138
0
  RETERR(uint16_tobuffer(l32->pref, target));
139
0
  n = ntohl(l32->l32.s_addr);
140
0
  return uint32_tobuffer(n, target);
141
0
}
142
143
static isc_result_t
144
0
tostruct_l32(ARGS_TOSTRUCT) {
145
0
  isc_region_t region;
146
0
  dns_rdata_l32_t *l32 = target;
147
0
  uint32_t n;
148
149
0
  REQUIRE(rdata->type == dns_rdatatype_l32);
150
0
  REQUIRE(l32 != NULL);
151
0
  REQUIRE(rdata->length == 6);
152
153
0
  UNUSED(mctx);
154
155
0
  DNS_RDATACOMMON_INIT(l32, rdata->type, rdata->rdclass);
156
157
0
  dns_rdata_toregion(rdata, &region);
158
0
  l32->pref = uint16_fromregion(&region);
159
0
  n = uint32_fromregion(&region);
160
0
  l32->l32.s_addr = htonl(n);
161
0
  return ISC_R_SUCCESS;
162
0
}
163
164
static void
165
0
freestruct_l32(ARGS_FREESTRUCT) {
166
0
  dns_rdata_l32_t *l32 = source;
167
168
0
  REQUIRE(l32 != NULL);
169
0
  REQUIRE(l32->common.rdtype == dns_rdatatype_l32);
170
171
0
  return;
172
0
}
173
174
static isc_result_t
175
0
additionaldata_l32(ARGS_ADDLDATA) {
176
0
  REQUIRE(rdata->type == dns_rdatatype_l32);
177
0
  REQUIRE(rdata->length == 6);
178
179
0
  UNUSED(rdata);
180
0
  UNUSED(owner);
181
0
  UNUSED(add);
182
0
  UNUSED(arg);
183
184
0
  return ISC_R_SUCCESS;
185
0
}
186
187
static isc_result_t
188
0
digest_l32(ARGS_DIGEST) {
189
0
  isc_region_t r;
190
191
0
  REQUIRE(rdata->type == dns_rdatatype_l32);
192
0
  REQUIRE(rdata->length == 6);
193
194
0
  dns_rdata_toregion(rdata, &r);
195
196
0
  return (digest)(arg, &r);
197
0
}
198
199
static bool
200
0
checkowner_l32(ARGS_CHECKOWNER) {
201
0
  REQUIRE(type == dns_rdatatype_l32);
202
203
0
  UNUSED(name);
204
0
  UNUSED(type);
205
0
  UNUSED(rdclass);
206
0
  UNUSED(wildcard);
207
208
0
  return true;
209
0
}
210
211
static bool
212
0
checknames_l32(ARGS_CHECKNAMES) {
213
0
  REQUIRE(rdata->type == dns_rdatatype_l32);
214
0
  REQUIRE(rdata->length == 6);
215
216
0
  UNUSED(rdata);
217
0
  UNUSED(owner);
218
0
  UNUSED(bad);
219
220
0
  return true;
221
0
}
222
223
static int
224
0
casecompare_l32(ARGS_COMPARE) {
225
0
  return compare_l32(rdata1, rdata2);
226
0
}
227
228
#endif /* RDATA_GENERIC_L32_105_C */