1 /* $NetBSD: x25_19.c,v 1.9 2024/02/21 22:52:14 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 /* RFC1183 */ 17 18 #ifndef RDATA_GENERIC_X25_19_C 19 #define RDATA_GENERIC_X25_19_C 20 21 #define RRTYPE_X25_ATTRIBUTES (0) 22 23 static isc_result_t 24 fromtext_x25(ARGS_FROMTEXT) { 25 isc_token_t token; 26 unsigned int i; 27 28 REQUIRE(type == dns_rdatatype_x25); 29 30 UNUSED(type); 31 UNUSED(rdclass); 32 UNUSED(origin); 33 UNUSED(options); 34 UNUSED(callbacks); 35 36 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, 37 false)); 38 if (token.value.as_textregion.length < 4) { 39 RETTOK(DNS_R_SYNTAX); 40 } 41 for (i = 0; i < token.value.as_textregion.length; i++) { 42 if (!isdigit((unsigned char)token.value.as_textregion.base[i])) 43 { 44 RETTOK(ISC_R_RANGE); 45 } 46 } 47 RETTOK(txt_fromtext(&token.value.as_textregion, target)); 48 return (ISC_R_SUCCESS); 49 } 50 51 static isc_result_t 52 totext_x25(ARGS_TOTEXT) { 53 isc_region_t region; 54 55 UNUSED(tctx); 56 57 REQUIRE(rdata->type == dns_rdatatype_x25); 58 REQUIRE(rdata->length != 0); 59 60 dns_rdata_toregion(rdata, ®ion); 61 return (txt_totext(®ion, true, target)); 62 } 63 64 static isc_result_t 65 fromwire_x25(ARGS_FROMWIRE) { 66 isc_region_t sr; 67 unsigned int i; 68 69 REQUIRE(type == dns_rdatatype_x25); 70 71 UNUSED(type); 72 UNUSED(dctx); 73 UNUSED(rdclass); 74 UNUSED(options); 75 76 isc_buffer_activeregion(source, &sr); 77 if (sr.length < 5 || sr.base[0] != (sr.length - 1)) { 78 return (DNS_R_FORMERR); 79 } 80 for (i = 1; i < sr.length; i++) { 81 if (sr.base[i] < 0x30 || sr.base[i] > 0x39) { 82 return (DNS_R_FORMERR); 83 } 84 } 85 return (txt_fromwire(source, target)); 86 } 87 88 static isc_result_t 89 towire_x25(ARGS_TOWIRE) { 90 UNUSED(cctx); 91 92 REQUIRE(rdata->type == dns_rdatatype_x25); 93 REQUIRE(rdata->length != 0); 94 95 return (mem_tobuffer(target, rdata->data, rdata->length)); 96 } 97 98 static int 99 compare_x25(ARGS_COMPARE) { 100 isc_region_t r1; 101 isc_region_t r2; 102 103 REQUIRE(rdata1->type == rdata2->type); 104 REQUIRE(rdata1->rdclass == rdata2->rdclass); 105 REQUIRE(rdata1->type == dns_rdatatype_x25); 106 REQUIRE(rdata1->length != 0); 107 REQUIRE(rdata2->length != 0); 108 109 dns_rdata_toregion(rdata1, &r1); 110 dns_rdata_toregion(rdata2, &r2); 111 return (isc_region_compare(&r1, &r2)); 112 } 113 114 static isc_result_t 115 fromstruct_x25(ARGS_FROMSTRUCT) { 116 dns_rdata_x25_t *x25 = source; 117 uint8_t i; 118 119 REQUIRE(type == dns_rdatatype_x25); 120 REQUIRE(x25 != NULL); 121 REQUIRE(x25->common.rdtype == type); 122 REQUIRE(x25->common.rdclass == rdclass); 123 REQUIRE(x25->x25 != NULL && x25->x25_len != 0); 124 125 UNUSED(type); 126 UNUSED(rdclass); 127 128 if (x25->x25_len < 4) { 129 return (ISC_R_RANGE); 130 } 131 132 for (i = 0; i < x25->x25_len; i++) { 133 if (!isdigit((unsigned char)x25->x25[i])) { 134 return (ISC_R_RANGE); 135 } 136 } 137 138 RETERR(uint8_tobuffer(x25->x25_len, target)); 139 return (mem_tobuffer(target, x25->x25, x25->x25_len)); 140 } 141 142 static isc_result_t 143 tostruct_x25(ARGS_TOSTRUCT) { 144 dns_rdata_x25_t *x25 = target; 145 isc_region_t r; 146 147 REQUIRE(rdata->type == dns_rdatatype_x25); 148 REQUIRE(x25 != NULL); 149 REQUIRE(rdata->length != 0); 150 151 x25->common.rdclass = rdata->rdclass; 152 x25->common.rdtype = rdata->type; 153 ISC_LINK_INIT(&x25->common, link); 154 155 dns_rdata_toregion(rdata, &r); 156 x25->x25_len = uint8_fromregion(&r); 157 isc_region_consume(&r, 1); 158 x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len); 159 if (x25->x25 == NULL) { 160 return (ISC_R_NOMEMORY); 161 } 162 163 x25->mctx = mctx; 164 return (ISC_R_SUCCESS); 165 } 166 167 static void 168 freestruct_x25(ARGS_FREESTRUCT) { 169 dns_rdata_x25_t *x25 = source; 170 171 REQUIRE(x25 != NULL); 172 REQUIRE(x25->common.rdtype == dns_rdatatype_x25); 173 174 if (x25->mctx == NULL) { 175 return; 176 } 177 178 if (x25->x25 != NULL) { 179 isc_mem_free(x25->mctx, x25->x25); 180 } 181 x25->mctx = NULL; 182 } 183 184 static isc_result_t 185 additionaldata_x25(ARGS_ADDLDATA) { 186 REQUIRE(rdata->type == dns_rdatatype_x25); 187 188 UNUSED(rdata); 189 UNUSED(owner); 190 UNUSED(add); 191 UNUSED(arg); 192 193 return (ISC_R_SUCCESS); 194 } 195 196 static isc_result_t 197 digest_x25(ARGS_DIGEST) { 198 isc_region_t r; 199 200 REQUIRE(rdata->type == dns_rdatatype_x25); 201 202 dns_rdata_toregion(rdata, &r); 203 204 return ((digest)(arg, &r)); 205 } 206 207 static bool 208 checkowner_x25(ARGS_CHECKOWNER) { 209 REQUIRE(type == dns_rdatatype_x25); 210 211 UNUSED(name); 212 UNUSED(type); 213 UNUSED(rdclass); 214 UNUSED(wildcard); 215 216 return (true); 217 } 218 219 static bool 220 checknames_x25(ARGS_CHECKNAMES) { 221 REQUIRE(rdata->type == dns_rdatatype_x25); 222 223 UNUSED(rdata); 224 UNUSED(owner); 225 UNUSED(bad); 226 227 return (true); 228 } 229 230 static int 231 casecompare_x25(ARGS_COMPARE) { 232 return (compare_x25(rdata1, rdata2)); 233 } 234 235 #endif /* RDATA_GENERIC_X25_19_C */ 236