aaaa_28.c 5.09 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.
Mark Andrews's avatar
Mark Andrews committed
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: aaaa_28.c,v 1.22 2000/05/05 23:20:01 marka Exp $ */
Mark Andrews's avatar
Mark Andrews committed
19

Brian Wellington's avatar
Brian Wellington committed
20 21 22
/* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */

/* RFC 1886 */
Mark Andrews's avatar
Mark Andrews committed
23

24 25
#ifndef RDATA_IN_1_AAAA_28_C
#define RDATA_IN_1_AAAA_28_C
Mark Andrews's avatar
Mark Andrews committed
26 27 28

#include <string.h>

29
#include <isc/net.h>
Mark Andrews's avatar
Mark Andrews committed
30

31 32
#define RRTYPE_AAAA_ATTRIBUTES (0)

33
static inline isc_result_t
34
fromtext_in_aaaa(dns_rdataclass_t rdclass, dns_rdatatype_t type,
Mark Andrews's avatar
Mark Andrews committed
35 36 37
		 isc_lex_t *lexer, dns_name_t *origin,
		 isc_boolean_t downcase, isc_buffer_t *target)
{
Mark Andrews's avatar
Mark Andrews committed
38 39 40 41
	isc_token_t token;
	unsigned char addr[16];
	isc_region_t region;

Brian Wellington's avatar
Brian Wellington committed
42 43 44
	UNUSED(origin);
	UNUSED(downcase);

Mark Andrews's avatar
Mark Andrews committed
45
	REQUIRE(type == 28);
46
	REQUIRE(rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
47 48 49

	RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));

50
	if (inet_pton(AF_INET6, token.value.as_pointer, addr) != 1)
51
		return (DNS_R_BADAAAA);
52
	isc_buffer_availableregion(target, &region);
Mark Andrews's avatar
Mark Andrews committed
53
	if (region.length < 16)
54
		return (ISC_R_NOSPACE);
Mark Andrews's avatar
Mark Andrews committed
55 56
	memcpy(region.base, addr, 16);
	isc_buffer_add(target, 16);
57
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
58 59
}

60
static inline isc_result_t
61 62 63
totext_in_aaaa(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, 
	       isc_buffer_t *target) 
{
Mark Andrews's avatar
Mark Andrews committed
64 65
	isc_region_t region;

Brian Wellington's avatar
Brian Wellington committed
66 67
	UNUSED(tctx);

Mark Andrews's avatar
Mark Andrews committed
68
	REQUIRE(rdata->type == 28);
69
	REQUIRE(rdata->rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
70 71
	REQUIRE(rdata->length == 16);

72
	isc_buffer_availableregion(target, &region);
73 74
	if (inet_ntop(AF_INET6, rdata->data,
		      (char *)region.base, region.length) == NULL)
75
		return (ISC_R_NOSPACE);
Mark Andrews's avatar
Mark Andrews committed
76

77
	isc_buffer_add(target, strlen((char *)region.base));
78
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
79 80
}

81
static inline isc_result_t
82
fromwire_in_aaaa(dns_rdataclass_t rdclass, dns_rdatatype_t type,
Mark Andrews's avatar
Mark Andrews committed
83 84 85
		 isc_buffer_t *source, dns_decompress_t *dctx,
		 isc_boolean_t downcase, isc_buffer_t *target)
{
Mark Andrews's avatar
Mark Andrews committed
86 87 88
	isc_region_t sregion;
	isc_region_t tregion;

Brian Wellington's avatar
Brian Wellington committed
89 90 91
	UNUSED(dctx);
	UNUSED(downcase);

Mark Andrews's avatar
Mark Andrews committed
92
	REQUIRE(type == 28);
93
	REQUIRE(rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
94

95 96
	isc_buffer_activeregion(source, &sregion);
	isc_buffer_availableregion(target, &tregion);
Mark Andrews's avatar
Mark Andrews committed
97
	if (sregion.length < 16)
98
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
99
	if (tregion.length < 16)
100
		return (ISC_R_NOSPACE);
Mark Andrews's avatar
Mark Andrews committed
101 102 103 104

	memcpy(tregion.base, sregion.base, 16);
	isc_buffer_forward(source, 16);
	isc_buffer_add(target, 16);
105
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
106 107
}

108
static inline isc_result_t
Mark Andrews's avatar
Mark Andrews committed
109 110 111
towire_in_aaaa(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
	isc_region_t region;

Brian Wellington's avatar
Brian Wellington committed
112 113
	UNUSED(cctx);

Mark Andrews's avatar
Mark Andrews committed
114
	REQUIRE(rdata->type == 28);
115
	REQUIRE(rdata->rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
116

117
	isc_buffer_availableregion(target, &region);
Mark Andrews's avatar
Mark Andrews committed
118
	if (region.length < rdata->length)
119
		return (ISC_R_NOSPACE);
Mark Andrews's avatar
Mark Andrews committed
120 121
	memcpy(region.base, rdata->data, rdata->length);
	isc_buffer_add(target, 16);
122
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
123 124
}

125
static inline int
Mark Andrews's avatar
Mark Andrews committed
126
compare_in_aaaa(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
Brian Wellington's avatar
Brian Wellington committed
127 128 129
	isc_region_t r1;
	isc_region_t r2;

Mark Andrews's avatar
Mark Andrews committed
130
	REQUIRE(rdata1->type == rdata2->type);
131
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
132
	REQUIRE(rdata1->type == 28);
133
	REQUIRE(rdata1->rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
134

Brian Wellington's avatar
Brian Wellington committed
135 136 137
	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
	return (compare_region(&r1, &r2));
Mark Andrews's avatar
Mark Andrews committed
138 139
}

140
static inline isc_result_t
141 142
fromstruct_in_aaaa(dns_rdataclass_t rdclass, dns_rdatatype_t type,
		   void *source, isc_buffer_t *target)
Mark Andrews's avatar
Mark Andrews committed
143
{
Brian Wellington's avatar
Brian Wellington committed
144 145
	UNUSED(source);
	UNUSED(target);
Mark Andrews's avatar
Mark Andrews committed
146 147

	REQUIRE(type == 1);
148
	REQUIRE(rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
149

150
	return (ISC_R_NOTIMPLEMENTED);
Mark Andrews's avatar
Mark Andrews committed
151 152
}

153
static inline isc_result_t
154
tostruct_in_aaaa(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
155 156 157
	dns_rdata_in_aaaa_t *aaaa = target;
	isc_region_t r;

Mark Andrews's avatar
Mark Andrews committed
158
	REQUIRE(rdata->type == 28);
159
	REQUIRE(rdata->rdclass == 1);
160
	REQUIRE(target != NULL);
Mark Andrews's avatar
Mark Andrews committed
161

162 163
	UNUSED(mctx);

164 165 166 167 168 169 170 171 172
	aaaa->common.rdclass = rdata->rdclass;
	aaaa->common.rdtype = rdata->type;
	ISC_LINK_INIT(&aaaa->common, link);

	dns_rdata_toregion(rdata, &r);
	INSIST(r.length == 16);
	memcpy(aaaa->in6_addr.s6_addr, r.base, 16);

	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
173
}
174

175
static inline void
176
freestruct_in_aaaa(void *source) {
177
	dns_rdata_in_aaaa_t *aaaa = source;
178

179 180 181
	REQUIRE(source != NULL);
	REQUIRE(aaaa->common.rdclass == 1);
	REQUIRE(aaaa->common.rdtype == 28);
182
}
183

184
static inline isc_result_t
185 186 187 188 189 190
additionaldata_in_aaaa(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
		       void *arg)
{
	REQUIRE(rdata->type == 28);
	REQUIRE(rdata->rdclass == 1);

191 192 193 194
	UNUSED(rdata);
	UNUSED(add);
	UNUSED(arg);

195
	return (ISC_R_SUCCESS);
196 197
}

198
static inline isc_result_t
199 200 201 202 203 204 205 206 207 208 209
digest_in_aaaa(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
	isc_region_t r;

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

	dns_rdata_toregion(rdata, &r);

	return ((digest)(arg, &r));
}

210
#endif	/* RDATA_IN_1_AAAA_28_C */