Coverage Report

Created: 2026-07-16 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/lib/dns/rdata/generic/eui48_108.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_EUI48_108_C
15
#define RDATA_GENERIC_EUI48_108_C
16
17
#include <string.h>
18
19
9.92k
#define RRTYPE_EUI48_ATTRIBUTES (0)
20
21
static isc_result_t
22
100
fromtext_eui48(ARGS_FROMTEXT) {
23
100
  isc_token_t token;
24
100
  unsigned char eui48[6];
25
100
  unsigned int l0, l1, l2, l3, l4, l5;
26
100
  int n;
27
28
100
  REQUIRE(type == dns_rdatatype_eui48);
29
30
100
  UNUSED(type);
31
100
  UNUSED(rdclass);
32
100
  UNUSED(origin);
33
100
  UNUSED(options);
34
100
  UNUSED(callbacks);
35
36
100
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
37
100
              false));
38
97
  n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x", &l0, &l1, &l2,
39
97
       &l3, &l4, &l5);
40
97
  if (n != 6 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U ||
41
81
      l4 > 255U || l5 > 255U)
42
25
  {
43
25
    return DNS_R_BADEUI;
44
25
  }
45
46
72
  eui48[0] = l0;
47
72
  eui48[1] = l1;
48
72
  eui48[2] = l2;
49
72
  eui48[3] = l3;
50
72
  eui48[4] = l4;
51
72
  eui48[5] = l5;
52
72
  return mem_tobuffer(target, eui48, sizeof(eui48));
53
97
}
54
55
static isc_result_t
56
777
totext_eui48(ARGS_TOTEXT) {
57
777
  char buf[sizeof("xx-xx-xx-xx-xx-xx")];
58
59
777
  REQUIRE(rdata->type == dns_rdatatype_eui48);
60
777
  REQUIRE(rdata->length == 6);
61
62
777
  UNUSED(tctx);
63
64
777
  (void)snprintf(buf, sizeof(buf), "%02x-%02x-%02x-%02x-%02x-%02x",
65
777
           rdata->data[0], rdata->data[1], rdata->data[2],
66
777
           rdata->data[3], rdata->data[4], rdata->data[5]);
67
777
  return str_totext(buf, target);
68
777
}
69
70
static isc_result_t
71
1.53k
fromwire_eui48(ARGS_FROMWIRE) {
72
1.53k
  isc_region_t sregion;
73
74
1.53k
  REQUIRE(type == dns_rdatatype_eui48);
75
76
1.53k
  UNUSED(type);
77
1.53k
  UNUSED(rdclass);
78
1.53k
  UNUSED(dctx);
79
80
1.53k
  isc_buffer_activeregion(source, &sregion);
81
1.53k
  if (sregion.length != 6) {
82
12
    return DNS_R_FORMERR;
83
12
  }
84
1.52k
  isc_buffer_forward(source, sregion.length);
85
1.52k
  return mem_tobuffer(target, sregion.base, sregion.length);
86
1.53k
}
87
88
static isc_result_t
89
394
towire_eui48(ARGS_TOWIRE) {
90
394
  REQUIRE(rdata->type == dns_rdatatype_eui48);
91
394
  REQUIRE(rdata->length == 6);
92
93
394
  UNUSED(cctx);
94
95
394
  return mem_tobuffer(target, rdata->data, rdata->length);
96
394
}
97
98
static int
99
609
compare_eui48(ARGS_COMPARE) {
100
609
  isc_region_t region1;
101
609
  isc_region_t region2;
102
103
609
  REQUIRE(rdata1->type == rdata2->type);
104
609
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
105
609
  REQUIRE(rdata1->type == dns_rdatatype_eui48);
106
609
  REQUIRE(rdata1->length == 6);
107
609
  REQUIRE(rdata2->length == 6);
108
109
609
  dns_rdata_toregion(rdata1, &region1);
110
609
  dns_rdata_toregion(rdata2, &region2);
111
609
  return isc_region_compare(&region1, &region2);
112
609
}
113
114
static isc_result_t
115
0
fromstruct_eui48(ARGS_FROMSTRUCT) {
116
0
  dns_rdata_eui48_t *eui48 = source;
117
118
0
  REQUIRE(type == dns_rdatatype_eui48);
119
0
  REQUIRE(eui48 != NULL);
120
0
  REQUIRE(eui48->common.rdtype == type);
121
0
  REQUIRE(eui48->common.rdclass == rdclass);
122
123
0
  UNUSED(type);
124
0
  UNUSED(rdclass);
125
126
0
  return mem_tobuffer(target, eui48->eui48, sizeof(eui48->eui48));
127
0
}
128
129
static isc_result_t
130
0
tostruct_eui48(ARGS_TOSTRUCT) {
131
0
  dns_rdata_eui48_t *eui48 = target;
132
133
0
  REQUIRE(rdata->type == dns_rdatatype_eui48);
134
0
  REQUIRE(eui48 != NULL);
135
0
  REQUIRE(rdata->length == 6);
136
137
0
  UNUSED(mctx);
138
139
0
  DNS_RDATACOMMON_INIT(eui48, rdata->type, rdata->rdclass);
140
141
0
  memmove(eui48->eui48, rdata->data, rdata->length);
142
0
  return ISC_R_SUCCESS;
143
0
}
144
145
static void
146
0
freestruct_eui48(ARGS_FREESTRUCT) {
147
0
  dns_rdata_eui48_t *eui48 = source;
148
149
0
  REQUIRE(eui48 != NULL);
150
0
  REQUIRE(eui48->common.rdtype == dns_rdatatype_eui48);
151
152
0
  return;
153
0
}
154
155
static isc_result_t
156
0
additionaldata_eui48(ARGS_ADDLDATA) {
157
0
  REQUIRE(rdata->type == dns_rdatatype_eui48);
158
0
  REQUIRE(rdata->length == 6);
159
160
0
  UNUSED(rdata);
161
0
  UNUSED(owner);
162
0
  UNUSED(add);
163
0
  UNUSED(arg);
164
165
0
  return ISC_R_SUCCESS;
166
0
}
167
168
static isc_result_t
169
0
digest_eui48(ARGS_DIGEST) {
170
0
  isc_region_t r;
171
172
0
  REQUIRE(rdata->type == dns_rdatatype_eui48);
173
0
  REQUIRE(rdata->length == 6);
174
175
0
  dns_rdata_toregion(rdata, &r);
176
177
0
  return (digest)(arg, &r);
178
0
}
179
180
static bool
181
0
checkowner_eui48(ARGS_CHECKOWNER) {
182
0
  REQUIRE(type == dns_rdatatype_eui48);
183
184
0
  UNUSED(name);
185
0
  UNUSED(type);
186
0
  UNUSED(rdclass);
187
0
  UNUSED(wildcard);
188
189
0
  return true;
190
0
}
191
192
static bool
193
0
checknames_eui48(ARGS_CHECKNAMES) {
194
0
  REQUIRE(rdata->type == dns_rdatatype_eui48);
195
0
  REQUIRE(rdata->length == 6);
196
197
0
  UNUSED(rdata);
198
0
  UNUSED(owner);
199
0
  UNUSED(bad);
200
201
0
  return true;
202
0
}
203
204
static int
205
0
casecompare_eui48(ARGS_COMPARE) {
206
0
  return compare_eui48(rdata1, rdata2);
207
0
}
208
209
#endif /* RDATA_GENERIC_EUI48_108_C */