Coverage Report

Created: 2026-12-01 07:04

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