x25_19.c 4.37 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: x25_19.c,v 1.26 2000/12/01 01:40:46 gson Exp $ */
Mark Andrews's avatar
Mark Andrews committed
19

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

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

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

27 28
#define RRTYPE_X25_ATTRIBUTES (0)

29
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
30
fromtext_x25(ARGS_FROMTEXT) {
Mark Andrews's avatar
Mark Andrews committed
31 32 33
	isc_token_t token;
	unsigned int i;

Brian Wellington's avatar
Brian Wellington committed
34 35 36
	UNUSED(rdclass);
	UNUSED(origin);
	UNUSED(downcase);
Mark Andrews's avatar
Mark Andrews committed
37

Brian Wellington's avatar
Brian Wellington committed
38
	REQUIRE(type == 19);
Mark Andrews's avatar
Mark Andrews committed
39

40 41
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
				      ISC_FALSE));
Brian Wellington's avatar
Brian Wellington committed
42 43
	if (token.value.as_textregion.length < 4)
		return (DNS_R_SYNTAX);
Mark Andrews's avatar
Mark Andrews committed
44
	for (i = 0; i < token.value.as_textregion.length; i++)
Brian Wellington's avatar
Brian Wellington committed
45
		if (!isdigit(token.value.as_textregion.base[i] & 0xff))
David Lawrence's avatar
David Lawrence committed
46
			return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
47 48 49
	return (txt_fromtext(&token.value.as_textregion, target));
}

50
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
51
totext_x25(ARGS_TOTEXT) {
Mark Andrews's avatar
Mark Andrews committed
52 53
	isc_region_t region;

Brian Wellington's avatar
Brian Wellington committed
54
	UNUSED(tctx);
Mark Andrews's avatar
Mark Andrews committed
55

Brian Wellington's avatar
Brian Wellington committed
56
	REQUIRE(rdata->type == 19);
57
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
58 59 60 61 62

	dns_rdata_toregion(rdata, &region);
	return (txt_totext(&region, target));
}

63
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
64
fromwire_x25(ARGS_FROMWIRE) {
Brian Wellington's avatar
Brian Wellington committed
65
	isc_region_t sr;
Mark Andrews's avatar
Mark Andrews committed
66

Brian Wellington's avatar
Brian Wellington committed
67 68 69
	UNUSED(dctx);
	UNUSED(rdclass);
	UNUSED(downcase);
Mark Andrews's avatar
Mark Andrews committed
70

Brian Wellington's avatar
Brian Wellington committed
71
	REQUIRE(type == 19);
Mark Andrews's avatar
Mark Andrews committed
72

73
	isc_buffer_activeregion(source, &sr);
Brian Wellington's avatar
Brian Wellington committed
74 75
	if (sr.length < 5)
		return (DNS_R_FORMERR);
Mark Andrews's avatar
Mark Andrews committed
76 77 78
	return (txt_fromwire(source, target));
}

79
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
80
towire_x25(ARGS_TOWIRE) {
Brian Wellington's avatar
Brian Wellington committed
81
	UNUSED(cctx);
Mark Andrews's avatar
Mark Andrews committed
82 83

	REQUIRE(rdata->type == 19);
84
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
85 86 87 88

	return (mem_tobuffer(target, rdata->data, rdata->length));
}

89
static inline int
David Lawrence's avatar
David Lawrence committed
90
compare_x25(ARGS_COMPARE) {
Brian Wellington's avatar
Brian Wellington committed
91 92
	isc_region_t r1;
	isc_region_t r2;
93

Mark Andrews's avatar
Mark Andrews committed
94
	REQUIRE(rdata1->type == rdata2->type);
95
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
96
	REQUIRE(rdata1->type == 19);
97 98
	REQUIRE(rdata1->length != 0);
	REQUIRE(rdata2->length != 0);
Mark Andrews's avatar
Mark Andrews committed
99

Brian Wellington's avatar
Brian Wellington committed
100 101 102
	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
	return (compare_region(&r1, &r2));
Mark Andrews's avatar
Mark Andrews committed
103 104
}

105
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
106
fromstruct_x25(ARGS_FROMSTRUCT) {
107 108
	dns_rdata_x25_t *x25 = source;
	isc_uint8_t i;
Mark Andrews's avatar
Mark Andrews committed
109 110

	REQUIRE(type == 19);
111 112 113 114 115 116
	REQUIRE(source != NULL);
	REQUIRE(x25->common.rdtype == type);
	REQUIRE(x25->common.rdclass == rdclass);
	REQUIRE((x25->x25 == NULL && x25->x25_len == 0) ||
		(x25->x25 != NULL && x25->x25_len != 0));

117 118
	UNUSED(rdclass);

119 120 121
	for (i = 0; i < x25->x25_len; i++)
		if (!isdigit(x25->x25[i] & 0xff))
			return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
122

123 124
	RETERR(uint8_tobuffer(x25->x25_len, target));
	return (mem_tobuffer(target, x25->x25, x25->x25_len));
Mark Andrews's avatar
Mark Andrews committed
125 126
}

127
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
128
tostruct_x25(ARGS_TOSTRUCT) {
129 130
	dns_rdata_x25_t *x25 = target;
	isc_region_t r;
Mark Andrews's avatar
Mark Andrews committed
131 132

	REQUIRE(rdata->type == 19);
133
	REQUIRE(target != NULL);
134
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
135

136 137 138
	x25->common.rdclass = rdata->rdclass;
	x25->common.rdtype = rdata->type;
	ISC_LINK_INIT(&x25->common, link);
Mark Andrews's avatar
Mark Andrews committed
139

140 141 142 143 144 145 146 147 148 149 150 151
	dns_rdata_toregion(rdata, &r);
	x25->x25_len = uint8_fromregion(&r);
	isc_region_consume(&r, 1);
	if (x25->x25_len != 0) {
		x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len);
		if (x25->x25 == NULL)
			return (ISC_R_NOMEMORY);
	} else
		x25->x25 = NULL;

	x25->mctx = mctx;
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
152
}
153

154
static inline void
David Lawrence's avatar
David Lawrence committed
155
freestruct_x25(ARGS_FREESTRUCT) {
156
	dns_rdata_x25_t *x25 = source;
157
	REQUIRE(source != NULL);
158
	REQUIRE(x25->common.rdtype == 19);
159

160 161 162 163 164 165
	if (x25->mctx == NULL)
		return;

	if (x25->x25 != NULL)
		isc_mem_free(x25->mctx, x25->x25);
	x25->mctx = NULL;
166
}
167

168
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
169
additionaldata_x25(ARGS_ADDLDATA) {
170 171 172
	REQUIRE(rdata->type == 19);

	UNUSED(rdata);
Brian Wellington's avatar
Brian Wellington committed
173 174
	UNUSED(add);
	UNUSED(arg);
175

176
	return (ISC_R_SUCCESS);
177 178
}

179
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
180
digest_x25(ARGS_DIGEST) {
Bob Halley's avatar
Bob Halley committed
181 182 183 184 185 186 187 188 189
	isc_region_t r;

	REQUIRE(rdata->type == 19);

	dns_rdata_toregion(rdata, &r);

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

190
#endif	/* RDATA_GENERIC_X25_19_C */