Coverage Report

Created: 2022-03-10 07:56

/src/bind9/lib/dns/rdata/generic/lp_107.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_LP_107_C
15
#define RDATA_GENERIC_LP_107_C
16
17
#include <string.h>
18
19
#include <isc/net.h>
20
21
15.3k
#define RRTYPE_LP_ATTRIBUTES (0)
22
23
static inline isc_result_t
24
611
fromtext_lp(ARGS_FROMTEXT) {
25
611
  isc_token_t token;
26
611
  dns_name_t name;
27
611
  isc_buffer_t buffer;
28
29
611
  REQUIRE(type == dns_rdatatype_lp);
30
31
611
  UNUSED(type);
32
611
  UNUSED(rdclass);
33
611
  UNUSED(callbacks);
34
35
611
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
36
611
              false));
37
604
  if (token.value.as_ulong > 0xffffU) {
38
7
    RETTOK(ISC_R_RANGE);
39
7
  }
40
597
  RETERR(uint16_tobuffer(token.value.as_ulong, target));
41
42
597
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
43
597
              false));
44
45
575
  dns_name_init(&name, NULL);
46
575
  buffer_fromregion(&buffer, &token.value.as_region);
47
575
  if (origin == NULL) {
48
1
    origin = dns_rootname;
49
1
  }
50
575
  return (dns_name_fromtext(&name, &buffer, origin, options, target));
51
597
}
52
53
static inline isc_result_t
54
2.47k
totext_lp(ARGS_TOTEXT) {
55
2.47k
  isc_region_t region;
56
2.47k
  dns_name_t name;
57
2.47k
  dns_name_t prefix;
58
2.47k
  bool sub;
59
2.47k
  char buf[sizeof("64000")];
60
2.47k
  unsigned short num;
61
62
2.47k
  REQUIRE(rdata->type == dns_rdatatype_lp);
63
2.47k
  REQUIRE(rdata->length != 0);
64
65
0
  dns_name_init(&name, NULL);
66
2.47k
  dns_name_init(&prefix, NULL);
67
68
2.47k
  dns_rdata_toregion(rdata, &region);
69
2.47k
  num = uint16_fromregion(&region);
70
2.47k
  isc_region_consume(&region, 2);
71
0
  snprintf(buf, sizeof(buf), "%u", num);
72
2.47k
  RETERR(str_totext(buf, target));
73
74
2.47k
  RETERR(str_totext(" ", target));
75
76
2.47k
  dns_name_fromregion(&name, &region);
77
2.47k
  sub = name_prefix(&name, tctx->origin, &prefix);
78
2.47k
  return (dns_name_totext(&prefix, sub, target));
79
2.47k
}
80
81
static inline isc_result_t
82
2.67k
fromwire_lp(ARGS_FROMWIRE) {
83
2.67k
  dns_name_t name;
84
2.67k
  isc_region_t sregion;
85
86
2.67k
  REQUIRE(type == dns_rdatatype_lp);
87
88
2.67k
  UNUSED(type);
89
2.67k
  UNUSED(rdclass);
90
91
2.67k
  dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
92
93
2.67k
  dns_name_init(&name, NULL);
94
95
2.67k
  isc_buffer_activeregion(source, &sregion);
96
2.67k
  if (sregion.length < 2) {
97
11
    return (ISC_R_UNEXPECTEDEND);
98
11
  }
99
2.66k
  RETERR(mem_tobuffer(target, sregion.base, 2));
100
2.59k
  isc_buffer_forward(source, 2);
101
2.59k
  return (dns_name_fromwire(&name, source, dctx, options, target));
102
2.66k
}
103
104
static inline isc_result_t
105
1.11k
towire_lp(ARGS_TOWIRE) {
106
1.11k
  REQUIRE(rdata->type == dns_rdatatype_lp);
107
1.11k
  REQUIRE(rdata->length != 0);
108
109
1.11k
  UNUSED(cctx);
110
111
1.11k
  return (mem_tobuffer(target, rdata->data, rdata->length));
112
1.11k
}
113
114
static inline int
115
2.01k
compare_lp(ARGS_COMPARE) {
116
2.01k
  isc_region_t region1;
117
2.01k
  isc_region_t region2;
118
119
2.01k
  REQUIRE(rdata1->type == rdata2->type);
120
2.01k
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
121
2.01k
  REQUIRE(rdata1->type == dns_rdatatype_lp);
122
2.01k
  REQUIRE(rdata1->length != 0);
123
2.01k
  REQUIRE(rdata2->length != 0);
124
125
0
  dns_rdata_toregion(rdata1, &region1);
126
2.01k
  dns_rdata_toregion(rdata2, &region2);
127
128
2.01k
  return (isc_region_compare(&region1, &region2));
129
2.01k
}
130
131
static inline isc_result_t
132
0
fromstruct_lp(ARGS_FROMSTRUCT) {
133
0
  dns_rdata_lp_t *lp = source;
134
0
  isc_region_t region;
135
136
0
  REQUIRE(type == dns_rdatatype_lp);
137
0
  REQUIRE(lp != NULL);
138
0
  REQUIRE(lp->common.rdtype == type);
139
0
  REQUIRE(lp->common.rdclass == rdclass);
140
141
0
  UNUSED(type);
142
0
  UNUSED(rdclass);
143
144
0
  RETERR(uint16_tobuffer(lp->pref, target));
145
0
  dns_name_toregion(&lp->lp, &region);
146
0
  return (isc_buffer_copyregion(target, &region));
147
0
}
148
149
static inline isc_result_t
150
0
tostruct_lp(ARGS_TOSTRUCT) {
151
0
  isc_region_t region;
152
0
  dns_rdata_lp_t *lp = target;
153
0
  dns_name_t name;
154
155
0
  REQUIRE(rdata->type == dns_rdatatype_lp);
156
0
  REQUIRE(lp != NULL);
157
0
  REQUIRE(rdata->length != 0);
158
159
0
  lp->common.rdclass = rdata->rdclass;
160
0
  lp->common.rdtype = rdata->type;
161
0
  ISC_LINK_INIT(&lp->common, link);
162
163
0
  dns_name_init(&name, NULL);
164
0
  dns_rdata_toregion(rdata, &region);
165
0
  lp->pref = uint16_fromregion(&region);
166
0
  isc_region_consume(&region, 2);
167
0
  dns_name_fromregion(&name, &region);
168
0
  dns_name_init(&lp->lp, NULL);
169
0
  name_duporclone(&name, mctx, &lp->lp);
170
0
  lp->mctx = mctx;
171
0
  return (ISC_R_SUCCESS);
172
0
}
173
174
static inline void
175
0
freestruct_lp(ARGS_FREESTRUCT) {
176
0
  dns_rdata_lp_t *lp = source;
177
178
0
  REQUIRE(lp != NULL);
179
0
  REQUIRE(lp->common.rdtype == dns_rdatatype_lp);
180
181
0
  if (lp->mctx == NULL) {
182
0
    return;
183
0
  }
184
185
0
  dns_name_free(&lp->lp, lp->mctx);
186
0
  lp->mctx = NULL;
187
0
}
188
189
static inline isc_result_t
190
0
additionaldata_lp(ARGS_ADDLDATA) {
191
0
  dns_name_t name;
192
0
  dns_offsets_t offsets;
193
0
  isc_region_t region;
194
0
  isc_result_t result;
195
196
0
  REQUIRE(rdata->type == dns_rdatatype_lp);
197
198
0
  UNUSED(owner);
199
200
0
  dns_name_init(&name, offsets);
201
0
  dns_rdata_toregion(rdata, &region);
202
0
  isc_region_consume(&region, 2);
203
0
  dns_name_fromregion(&name, &region);
204
205
0
  result = (add)(arg, &name, dns_rdatatype_l32, NULL);
206
0
  if (result != ISC_R_SUCCESS) {
207
0
    return (result);
208
0
  }
209
0
  return ((add)(arg, &name, dns_rdatatype_l64, NULL));
210
0
}
211
212
static inline isc_result_t
213
0
digest_lp(ARGS_DIGEST) {
214
0
  isc_region_t region;
215
216
0
  REQUIRE(rdata->type == dns_rdatatype_lp);
217
218
0
  dns_rdata_toregion(rdata, &region);
219
0
  return ((digest)(arg, &region));
220
0
}
221
222
static inline bool
223
0
checkowner_lp(ARGS_CHECKOWNER) {
224
0
  REQUIRE(type == dns_rdatatype_lp);
225
226
0
  UNUSED(type);
227
0
  UNUSED(rdclass);
228
0
  UNUSED(name);
229
0
  UNUSED(wildcard);
230
231
0
  return (true);
232
0
}
233
234
static inline bool
235
0
checknames_lp(ARGS_CHECKNAMES) {
236
0
  REQUIRE(rdata->type == dns_rdatatype_lp);
237
238
0
  UNUSED(bad);
239
0
  UNUSED(owner);
240
241
0
  return (true);
242
0
}
243
244
static inline int
245
0
casecompare_lp(ARGS_COMPARE) {
246
0
  dns_name_t name1;
247
0
  dns_name_t name2;
248
0
  isc_region_t region1;
249
0
  isc_region_t region2;
250
0
  int order;
251
252
0
  REQUIRE(rdata1->type == rdata2->type);
253
0
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
254
0
  REQUIRE(rdata1->type == dns_rdatatype_lp);
255
0
  REQUIRE(rdata1->length != 0);
256
0
  REQUIRE(rdata2->length != 0);
257
258
0
  order = memcmp(rdata1->data, rdata2->data, 2);
259
0
  if (order != 0) {
260
0
    return (order < 0 ? -1 : 1);
261
0
  }
262
263
0
  dns_name_init(&name1, NULL);
264
0
  dns_name_init(&name2, NULL);
265
266
0
  dns_rdata_toregion(rdata1, &region1);
267
0
  dns_rdata_toregion(rdata2, &region2);
268
269
0
  isc_region_consume(&region1, 2);
270
0
  isc_region_consume(&region2, 2);
271
272
0
  dns_name_fromregion(&name1, &region1);
273
0
  dns_name_fromregion(&name2, &region2);
274
275
0
  return (dns_name_rdatacompare(&name1, &name2));
276
0
}
277
278
#endif /* RDATA_GENERIC_LP_107_C */