px_26.c 8.5 KB
Newer Older
1
/*
Brian Wellington's avatar
Brian Wellington committed
2
 * Copyright (C) 1999-2001  Internet Software Consortium.
3
 *
4
5
6
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
7
 *
8
9
10
11
12
13
14
15
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17
 */

18
/* $Id: px_26.c,v 1.38 2004/03/02 01:40:44 marka Exp $ */
19

20
21
22
/* Reviewed: Mon Mar 20 10:44:27 PST 2000 */

/* RFC 2163 */
23

24
25
#ifndef RDATA_IN_1_PX_26_C
#define RDATA_IN_1_PX_26_C
26

27
28
#define RRTYPE_PX_ATTRIBUTES (0)

29
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
30
fromtext_in_px(ARGS_FROMTEXT) {
31
32
33
34
35
	isc_token_t token;
	dns_name_t name;
	isc_buffer_t buffer;

	REQUIRE(type == 26);
36
	REQUIRE(rdclass == 1);
37

38
	UNUSED(type);
39
	UNUSED(rdclass);
40
	UNUSED(callbacks);
41

David Lawrence's avatar
David Lawrence committed
42
43
44
	/*
	 * Preference.
	 */
45
46
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
				      ISC_FALSE));
47
	if (token.value.as_ulong > 0xffffU)
48
		RETTOK(ISC_R_RANGE);
49
50
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
51
52
53
	/*
	 * MAP822.
	 */
54
55
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
				      ISC_FALSE));
56
	dns_name_init(&name, NULL);
57
	buffer_fromregion(&buffer, &token.value.as_region);
58
	origin = (origin != NULL) ? origin : dns_rootname;
59
	RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
60

David Lawrence's avatar
David Lawrence committed
61
62
63
	/*
	 * MAPX400.
	 */
64
65
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
				      ISC_FALSE));
66
	dns_name_init(&name, NULL);
67
	buffer_fromregion(&buffer, &token.value.as_region);
68
	origin = (origin != NULL) ? origin : dns_rootname;
69
	RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
70
	return (ISC_R_SUCCESS);
71
72
}

73
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
74
totext_in_px(ARGS_TOTEXT) {
75
76
77
78
	isc_region_t region;
	dns_name_t name;
	dns_name_t prefix;
	isc_boolean_t sub;
Andreas Gustafsson's avatar
Andreas Gustafsson committed
79
	char buf[sizeof("64000")];
80
81
82
	unsigned short num;

	REQUIRE(rdata->type == 26);
83
	REQUIRE(rdata->rdclass == 1);
84
	REQUIRE(rdata->length != 0);
85
86
87
88

	dns_name_init(&name, NULL);
	dns_name_init(&prefix, NULL);

David Lawrence's avatar
David Lawrence committed
89
90
91
	/*
	 * Preference.
	 */
92
93
94
95
96
97
98
	dns_rdata_toregion(rdata, &region);
	num = uint16_fromregion(&region);
	isc_region_consume(&region, 2);
	sprintf(buf, "%u", num);
	RETERR(str_totext(buf, target));
	RETERR(str_totext(" ", target));

David Lawrence's avatar
David Lawrence committed
99
100
101
	/*
	 * MAP822.
	 */
102
	dns_name_fromregion(&name, &region);
103
	sub = name_prefix(&name, tctx->origin, &prefix);
104
105
106
107
	isc_region_consume(&region, name_length(&name));
	RETERR(dns_name_totext(&prefix, sub, target));
	RETERR(str_totext(" ", target));

David Lawrence's avatar
David Lawrence committed
108
109
110
	/*
	 * MAPX400.
	 */
111
	dns_name_fromregion(&name, &region);
112
	sub = name_prefix(&name, tctx->origin, &prefix);
113
114
115
	return(dns_name_totext(&prefix, sub, target));
}

116
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
117
fromwire_in_px(ARGS_FROMWIRE) {
118
119
120
121
        dns_name_t name;
	isc_region_t sregion;

	REQUIRE(type == 26);
122
	REQUIRE(rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
123

124
	UNUSED(type);
125
126
	UNUSED(rdclass);

127
	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
128

129
130
        dns_name_init(&name, NULL);

David Lawrence's avatar
David Lawrence committed
131
132
133
	/*
	 * Preference.
	 */
134
	isc_buffer_activeregion(source, &sregion);
135
	if (sregion.length < 2)
136
		return (ISC_R_UNEXPECTEDEND);
137
138
139
	RETERR(mem_tobuffer(target, sregion.base, 2));
	isc_buffer_forward(source, 2);

David Lawrence's avatar
David Lawrence committed
140
141
142
	/*
	 * MAP822.
	 */
143
	RETERR(dns_name_fromwire(&name, source, dctx, options, target));
144

David Lawrence's avatar
David Lawrence committed
145
146
147
	/*
	 * MAPX400.
	 */
148
	return (dns_name_fromwire(&name, source, dctx, options, target));
149
150
}

151
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
152
towire_in_px(ARGS_TOWIRE) {
153
	dns_name_t name;
154
	dns_offsets_t offsets;
155
156
157
	isc_region_t region;

	REQUIRE(rdata->type == 26);
158
	REQUIRE(rdata->rdclass == 1);
159
	REQUIRE(rdata->length != 0);
160

161
	dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
David Lawrence's avatar
David Lawrence committed
162
163
164
	/*
	 * Preference.
	 */
165
166
167
168
	dns_rdata_toregion(rdata, &region);
	RETERR(mem_tobuffer(target, region.base, 2));
	isc_region_consume(&region, 2);

David Lawrence's avatar
David Lawrence committed
169
170
171
	/*
	 * MAP822.
	 */
172
	dns_name_init(&name, offsets);
173
174
175
176
	dns_name_fromregion(&name, &region);
	RETERR(dns_name_towire(&name, cctx, target));
	isc_region_consume(&region, name_length(&name));

David Lawrence's avatar
David Lawrence committed
177
178
179
	/*
	 * MAPX400.
	 */
180
	dns_name_init(&name, offsets);
181
182
183
184
	dns_name_fromregion(&name, &region);
	return (dns_name_towire(&name, cctx, target));
}

185
static inline int
David Lawrence's avatar
David Lawrence committed
186
compare_in_px(ARGS_COMPARE) {
187
188
189
190
	dns_name_t name1;
	dns_name_t name2;
	isc_region_t region1;
	isc_region_t region2;
191
	int order;
192
193

	REQUIRE(rdata1->type == rdata2->type);
194
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
195
	REQUIRE(rdata1->type == 26);
196
	REQUIRE(rdata1->rdclass == 1);
197
198
	REQUIRE(rdata1->length != 0);
	REQUIRE(rdata2->length != 0);
199

200
201
202
	order = memcmp(rdata1->data, rdata2->data, 2);
	if (order != 0)
		return (order < 0 ? -1 : 1);
203
204
205
206
207
208
209
210
211
212
213
214
215

	dns_name_init(&name1, NULL);
	dns_name_init(&name2, NULL);

	dns_rdata_toregion(rdata1, &region1);
	dns_rdata_toregion(rdata2, &region2);

	isc_region_consume(&region1, 2);
	isc_region_consume(&region2, 2);

	dns_name_fromregion(&name1, &region1);
	dns_name_fromregion(&name2, &region2);

216
217
218
	order = dns_name_rdatacompare(&name1, &name2);
	if (order != 0)
		return (order);
219
220
221
222
223
224
225

	isc_region_consume(&region1, name_length(&name1));
	isc_region_consume(&region2, name_length(&name2));

	dns_name_fromregion(&name1, &region1);
	dns_name_fromregion(&name2, &region2);

226
	return (dns_name_rdatacompare(&name1, &name2));
227
228
}

229
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
230
fromstruct_in_px(ARGS_FROMSTRUCT) {
231
232
	dns_rdata_in_px_t *px = source;
	isc_region_t region;
233
234

	REQUIRE(type == 26);
235
	REQUIRE(rdclass == 1);
236
237
238
239
	REQUIRE(source != NULL);
	REQUIRE(px->common.rdtype == type);
	REQUIRE(px->common.rdclass == rdclass);

240
	UNUSED(type);
241
242
	UNUSED(rdclass);

243
244
245
246
247
	RETERR(uint16_tobuffer(px->preference, target));
	dns_name_toregion(&px->map822, &region);
	RETERR(isc_buffer_copyregion(target, &region));
	dns_name_toregion(&px->mapx400, &region);
	return (isc_buffer_copyregion(target, &region));
248
249
}

250
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
251
tostruct_in_px(ARGS_TOSTRUCT) {
252
253
	dns_rdata_in_px_t *px = target;
	dns_name_t name;
254
	isc_region_t region;
255
	isc_result_t result;
256
257

	REQUIRE(rdata->type == 26);
258
	REQUIRE(rdata->rdclass == 1);
259
	REQUIRE(target != NULL);
260
	REQUIRE(rdata->length != 0);
261
262
263
264

	px->common.rdclass = rdata->rdclass;
	px->common.rdtype = rdata->type;
	ISC_LINK_INIT(&px->common, link);
265

266
267
268
269
270
	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &region);

	px->preference = uint16_fromregion(&region);
	isc_region_consume(&region, 2);
271

272
	dns_name_fromregion(&name, &region);
273

274
	dns_name_init(&px->map822, NULL);
275
276
	RETERR(name_duporclone(&name, mctx, &px->map822));
	isc_region_consume(&region, name_length(&px->map822));
277
278

	dns_name_init(&px->mapx400, NULL);
279
280
281
282
283
	result = name_duporclone(&name, mctx, &px->mapx400);
	if (result != ISC_R_SUCCESS)
		goto cleanup;

	px->mctx = mctx;
284
	return (result);
285
286
287
288

 cleanup:
	dns_name_free(&px->map822, mctx);
	return (ISC_R_NOMEMORY);
289
}
290

291
static inline void
David Lawrence's avatar
David Lawrence committed
292
freestruct_in_px(ARGS_FREESTRUCT) {
293
294
295
	dns_rdata_in_px_t *px = source;

	REQUIRE(source != NULL);
296
297
298
299
300
	REQUIRE(px->common.rdclass == 1);
	REQUIRE(px->common.rdtype == 26);

	if (px->mctx == NULL)
		return;
301

302
303
304
	dns_name_free(&px->map822, px->mctx);
	dns_name_free(&px->mapx400, px->mctx);
	px->mctx = NULL;
305
}
306

307
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
308
additionaldata_in_px(ARGS_ADDLDATA) {
309
310
311
	REQUIRE(rdata->type == 26);
	REQUIRE(rdata->rdclass == 1);

312
	UNUSED(rdata);
313
314
	UNUSED(add);
	UNUSED(arg);
315

316
	return (ISC_R_SUCCESS);
317
318
}

319
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
320
digest_in_px(ARGS_DIGEST) {
321
322
	isc_region_t r1, r2;
	dns_name_t name;
323
	isc_result_t result;
324
325
326
327
328
329
330
331
332

	REQUIRE(rdata->type == 26);
	REQUIRE(rdata->rdclass == 1);

	dns_rdata_toregion(rdata, &r1);
	r2 = r1;
	isc_region_consume(&r2, 2);
	r1.length = 2;
	result = (digest)(arg, &r1);
333
	if (result != ISC_R_SUCCESS)
334
335
336
337
		return (result);
	dns_name_init(&name, NULL);
	dns_name_fromregion(&name, &r2);
	result = dns_name_digest(&name, digest, arg);
338
	if (result != ISC_R_SUCCESS)
339
340
341
342
343
344
345
346
		return (result);
	isc_region_consume(&r2, name_length(&name));
	dns_name_init(&name, NULL);
	dns_name_fromregion(&name, &r2);

	return (dns_name_digest(&name, digest, arg));
}

347
348
349
static inline isc_boolean_t
checkowner_in_px(ARGS_CHECKOWNER) {

350
351
	REQUIRE(type == 26);
	REQUIRE(rdclass == 1);
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373

	UNUSED(name);
	UNUSED(type);
	UNUSED(rdclass);
	UNUSED(wildcard);

	return (ISC_TRUE);
}

static inline isc_boolean_t
checknames_in_px(ARGS_CHECKNAMES) {

	REQUIRE(rdata->type == 26);
	REQUIRE(rdata->rdclass == 1);

	UNUSED(rdata);
	UNUSED(owner);
	UNUSED(bad);

	return (ISC_TRUE);
}

374
#endif	/* RDATA_IN_1_PX_26_C */