dname_39.c 4.62 KB
Newer Older
Mark Andrews's avatar
Mark Andrews committed
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1999, 2000  Internet Software Consortium.
3
 *
Mark Andrews's avatar
Mark Andrews committed
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.
Mark Andrews's avatar
Mark Andrews committed
16
17
 */

18
/* $Id: dname_39.c,v 1.25 2000/08/01 01:25:13 tale Exp $ */
Mark Andrews's avatar
Mark Andrews committed
19

20
21
22
/* Reviewed: Wed Mar 15 16:52:38 PST 2000 by explorer */

/* draft-ietf-dnsind-dname-02.txt */
Mark Andrews's avatar
Mark Andrews committed
23

24
25
#ifndef RDATA_GENERIC_DNAME_39_C
#define RDATA_GENERIC_DNAME_39_C
Mark Andrews's avatar
Mark Andrews committed
26

27
28
#define RRTYPE_DNAME_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)

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

35
36
	UNUSED(rdclass);

Mark Andrews's avatar
Mark Andrews committed
37
	REQUIRE(type == 39);
38

Mark Andrews's avatar
Mark Andrews committed
39
	RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
40

Mark Andrews's avatar
Mark Andrews committed
41
	dns_name_init(&name, NULL);
42
	buffer_fromregion(&buffer, &token.value.as_region);
Mark Andrews's avatar
Mark Andrews committed
43
44
45
46
	origin = (origin != NULL) ? origin : dns_rootname;
	return (dns_name_fromtext(&name, &buffer, origin, downcase, target));
}

47
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
48
totext_dname(ARGS_TOTEXT) {
Mark Andrews's avatar
Mark Andrews committed
49
50
51
52
53
54
55
56
57
58
59
60
61
	isc_region_t region;
	dns_name_t name;
	dns_name_t prefix;
	isc_boolean_t sub;

	REQUIRE(rdata->type == 39);

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

	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);

62
	sub = name_prefix(&name, tctx->origin, &prefix);
Mark Andrews's avatar
Mark Andrews committed
63
64
65
66

	return (dns_name_totext(&prefix, sub, target));
}

67
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
68
fromwire_dname(ARGS_FROMWIRE) {
Mark Andrews's avatar
Mark Andrews committed
69
70
	dns_name_t name;

71
72
	UNUSED(rdclass);

Mark Andrews's avatar
Mark Andrews committed
73
74
	REQUIRE(type == 39);

75
	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
76

Mark Andrews's avatar
Mark Andrews committed
77
78
79
80
	dns_name_init(&name, NULL);
	return(dns_name_fromwire(&name, source, dctx, downcase, target));
}

81
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
82
towire_dname(ARGS_TOWIRE) {
Mark Andrews's avatar
Mark Andrews committed
83
84
85
86
87
	dns_name_t name;
	isc_region_t region;

	REQUIRE(rdata->type == 39);

88
	dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
89
90
91
92
93
94
95
	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);

	return (dns_name_towire(&name, cctx, target));
}

96
static inline int
David Lawrence's avatar
David Lawrence committed
97
compare_dname(ARGS_COMPARE) {
Mark Andrews's avatar
Mark Andrews committed
98
99
100
101
102
103
	dns_name_t name1;
	dns_name_t name2;
	isc_region_t region1;
	isc_region_t region2;

	REQUIRE(rdata1->type == rdata2->type);
104
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
105
106
107
108
109
110
111
112
113
114
115
	REQUIRE(rdata1->type == 39);

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

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

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

116
	return (dns_name_rdatacompare(&name1, &name2));
Mark Andrews's avatar
Mark Andrews committed
117
118
}

119
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
120
fromstruct_dname(ARGS_FROMSTRUCT) {
121
122
	dns_rdata_dname_t *dname = source;
	isc_region_t region;
Mark Andrews's avatar
Mark Andrews committed
123
124

	REQUIRE(type == 39);
125
126
127
	REQUIRE(source != NULL);
	REQUIRE(dname->common.rdtype == type);
	REQUIRE(dname->common.rdclass == rdclass);
Mark Andrews's avatar
Mark Andrews committed
128

129
130
	dns_name_toregion(&dname->dname, &region);
	return (isc_buffer_copyregion(target, &region));
Mark Andrews's avatar
Mark Andrews committed
131
132
}

133
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
134
tostruct_dname(ARGS_TOSTRUCT) {
135
136
137
	isc_region_t region;
	dns_rdata_dname_t *dname = target;
	dns_name_t name;
Mark Andrews's avatar
Mark Andrews committed
138

139
140
	REQUIRE(rdata->type == 39);
	REQUIRE(target != NULL);
Mark Andrews's avatar
Mark Andrews committed
141

142
143
144
145
146
147
148
149
150
151
152
	dname->common.rdclass = rdata->rdclass;
	dname->common.rdtype = rdata->type;
	ISC_LINK_INIT(&dname->common, link);

	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);
	dns_name_init(&dname->dname, NULL);
	RETERR(name_duporclone(&name, mctx, &dname->dname));
	dname->mctx = mctx;
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
153
}
154

155
static inline void
David Lawrence's avatar
David Lawrence committed
156
freestruct_dname(ARGS_FREESTRUCT) {
157
158
	dns_rdata_dname_t *dname = source;

159
	REQUIRE(source != NULL);
160
	REQUIRE(dname->common.rdtype == 39);
161

162
163
	if (dname->mctx == NULL)
		return;
164

165
166
	dns_name_free(&dname->dname, dname->mctx);
	dname->mctx = NULL;
167
}
168

169
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
170
additionaldata_dname(ARGS_ADDLDATA) {
171
	UNUSED(rdata);
172
173
	UNUSED(add);
	UNUSED(arg);
174

175
	REQUIRE(rdata->type == 39);
176

177
	return (ISC_R_SUCCESS);
178
179
}

180
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
181
digest_dname(ARGS_DIGEST) {
Bob Halley's avatar
Bob Halley committed
182
183
184
185
186
187
188
189
190
191
192
193
	isc_region_t r;
	dns_name_t name;

	REQUIRE(rdata->type == 39);

	dns_rdata_toregion(rdata, &r);
	dns_name_init(&name, NULL);
	dns_name_fromregion(&name, &r);

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

194
#endif	/* RDATA_GENERIC_DNAME_39_C */