ns_2.c 5.04 KB
Newer Older
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1998, 1999, 2000  Internet Software Consortium.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 * 
 * 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.
 * 
 * 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.
 */

18
/* $Id: ns_2.c,v 1.28 2000/05/05 17:24:21 gson Exp $ */
Brian Wellington's avatar
Brian Wellington committed
19
20

/* Reviewed: Wed Mar 15 18:15:00 PST 2000 by bwelling */
Mark Andrews's avatar
Mark Andrews committed
21

22
23
#ifndef RDATA_GENERIC_NS_2_C
#define RDATA_GENERIC_NS_2_C
24

25
26
#define RRTYPE_NS_ATTRIBUTES (DNS_RDATATYPEATTR_ZONECUTAUTH)

27
static inline isc_result_t
28
fromtext_ns(dns_rdataclass_t rdclass, dns_rdatatype_t type,
29
	    isc_lex_t *lexer, dns_name_t *origin,
Mark Andrews's avatar
Mark Andrews committed
30
31
	    isc_boolean_t downcase, isc_buffer_t *target)
{
32
33
34
35
	isc_token_t token;
	dns_name_t name;
	isc_buffer_t buffer;

36
	UNUSED(rdclass);
37

Brian Wellington's avatar
Brian Wellington committed
38
39
	REQUIRE(type == 2);

40
	RETERR(gettoken(lexer, &token,isc_tokentype_string, ISC_FALSE));
41
42

	dns_name_init(&name, NULL);
43
	buffer_fromregion(&buffer, &token.value.as_region);
44
45
46
47
	origin = (origin != NULL) ? origin : dns_rootname;
	return (dns_name_fromtext(&name, &buffer, origin, downcase, target));
}

48
static inline isc_result_t
49
50
51
totext_ns(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, 
	  isc_buffer_t *target) 
{
52
53
54
55
56
	isc_region_t region;
	dns_name_t name;
	dns_name_t prefix;
	isc_boolean_t sub;

Mark Andrews's avatar
Mark Andrews committed
57
	REQUIRE(rdata->type == 2);
58
59
60
61
62
63
64

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

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

65
	sub = name_prefix(&name, tctx->origin, &prefix);
66
67
68
69

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

70
static inline isc_result_t
71
fromwire_ns(dns_rdataclass_t rdclass, dns_rdatatype_t type,
72
	    isc_buffer_t *source, dns_decompress_t *dctx,
Mark Andrews's avatar
Mark Andrews committed
73
74
	    isc_boolean_t downcase, isc_buffer_t *target)
{
75
76
        dns_name_t name;

77
	UNUSED(rdclass);
Mark Andrews's avatar
Mark Andrews committed
78

Brian Wellington's avatar
Brian Wellington committed
79
80
	REQUIRE(type == 2);

81
	dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
Brian Wellington's avatar
Brian Wellington committed
82

83
84
85
86
        dns_name_init(&name, NULL);
        return (dns_name_fromwire(&name, source, dctx, downcase, target));
}

87
static inline isc_result_t
88
89
90
91
towire_ns(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
	dns_name_t name;
	isc_region_t region;

Mark Andrews's avatar
Mark Andrews committed
92
	REQUIRE(rdata->type == 2);
93

94
	dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
Mark Andrews's avatar
Mark Andrews committed
95

96
97
98
99
100
101
102
	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);

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

103
static inline int
104
105
106
107
108
109
compare_ns(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
	dns_name_t name1;
	dns_name_t name2;
	isc_region_t region1;
	isc_region_t region2;

Mark Andrews's avatar
Mark Andrews committed
110
	REQUIRE(rdata1->type == rdata2->type);
111
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
112
	REQUIRE(rdata1->type == 2);
Mark Andrews's avatar
Mark Andrews committed
113

114
115
116
117
118
119
120
121
122
	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);

123
	return (dns_name_rdatacompare(&name1, &name2));
124
125
}

126
static inline isc_result_t
127
fromstruct_ns(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
Mark Andrews's avatar
Mark Andrews committed
128
129
	      isc_buffer_t *target)
{
Brian Wellington's avatar
Brian Wellington committed
130
131
132
	UNUSED(rdclass);
	UNUSED(source);
	UNUSED(target);
Mark Andrews's avatar
Mark Andrews committed
133

Mark Andrews's avatar
Mark Andrews committed
134
	REQUIRE(type == 2);
Mark Andrews's avatar
Mark Andrews committed
135

136
	return (ISC_R_NOTIMPLEMENTED);
137
138
}

139
static inline isc_result_t
140
141
142
tostruct_ns(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
	isc_region_t region;
	dns_rdata_ns_t *ns = target;
143
	dns_name_t name;
Mark Andrews's avatar
Mark Andrews committed
144

Mark Andrews's avatar
Mark Andrews committed
145
	REQUIRE(rdata->type == 2);
146
	REQUIRE(target != NULL);
147
	REQUIRE(mctx != NULL);
148

149
	ns->common.rdclass = rdata->rdclass;
150
151
152
	ns->common.rdtype = rdata->type;
	ISC_LINK_INIT(&ns->common, link);

153
	dns_name_init(&name, NULL);
154
	dns_rdata_toregion(rdata, &region);
155
156
	dns_name_fromregion(&name, &region);
	dns_name_init(&ns->name, NULL);
157
	RETERR(name_duporclone(&name, mctx, &ns->name));
158
159
	ns->mctx = mctx;
	return (ISC_R_SUCCESS);
160
161
}

162
static inline void
163
freestruct_ns(void *source) {
164
165
	dns_rdata_ns_t *ns = source;

166
	REQUIRE(source != NULL);
167

168
169
170
	if (ns->mctx == NULL)
		return;

171
172
	dns_name_free(&ns->name, ns->mctx);
	ns->mctx = NULL;
173
}
174

175
static inline isc_result_t
176
177
178
additionaldata_ns(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
		  void *arg)
{
Bob Halley's avatar
Bob Halley committed
179
180
181
	dns_name_t name;
	isc_region_t region;

182
183
	REQUIRE(rdata->type == 2);

Bob Halley's avatar
Bob Halley committed
184
185
186
	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);
187

Bob Halley's avatar
Bob Halley committed
188
	return ((add)(arg, &name, dns_rdatatype_a));
189
190
}

191
static inline isc_result_t
Bob Halley's avatar
Bob Halley committed
192
193
194
195
196
197
198
199
200
201
202
203
204
digest_ns(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
	isc_region_t r;
	dns_name_t name;

	REQUIRE(rdata->type == 2);

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

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

205
#endif	/* RDATA_GENERIC_NS_2_C */