1 /* $NetBSD: x25_19.c,v 1.10 2025/01/26 16:25:34 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 75 isc_buffer_activeregion(source, &sr); 76 if (sr.length < 5 || sr.base[0] != (sr.length - 1)) { 77 return DNS_R_FORMERR; 78 } 79 for (i = 1; i < sr.length; i++) { 80 if (sr.base[i] < 0x30 || sr.base[i] > 0x39) { 81 return DNS_R_FORMERR; 82 } 83 } 84 return txt_fromwire(source, target); 85 } 86 87 static isc_result_t 88 towire_x25(ARGS_TOWIRE) { 89 UNUSED(cctx); 90 91 REQUIRE(rdata->type == dns_rdatatype_x25); 92 REQUIRE(rdata->length != 0); 93 94 return mem_tobuffer(target, rdata->data, rdata->length); 95 } 96 97 static int 98 compare_x25(ARGS_COMPARE) { 99 isc_region_t r1; 100 isc_region_t r2; 101 102 REQUIRE(rdata1->type == rdata2->type); 103 REQUIRE(rdata1->rdclass == rdata2->rdclass); 104 REQUIRE(rdata1->type == dns_rdatatype_x25); 105 REQUIRE(rdata1->length != 0); 106 REQUIRE(rdata2->length != 0); 107 108 dns_rdata_toregion(rdata1, &r1); 109 dns_rdata_toregion(rdata2, &r2); 110 return isc_region_compare(&r1, &r2); 111 } 112 113 static isc_result_t 114 fromstruct_x25(ARGS_FROMSTRUCT) { 115 dns_rdata_x25_t *x25 = source; 116 uint8_t i; 117 118 REQUIRE(type == dns_rdatatype_x25); 119 REQUIRE(x25 != NULL); 120 REQUIRE(x25->common.rdtype == type); 121 REQUIRE(x25->common.rdclass == rdclass); 122 REQUIRE(x25->x25 != NULL && x25->x25_len != 0); 123 124 UNUSED(type); 125 UNUSED(rdclass); 126 127 if (x25->x25_len < 4) { 128 return ISC_R_RANGE; 129 } 130 131 for (i = 0; i < x25->x25_len; i++) { 132 if (!isdigit((unsigned char)x25->x25[i])) { 133 return ISC_R_RANGE; 134 } 135 } 136 137 RETERR(uint8_tobuffer(x25->x25_len, target)); 138 return mem_tobuffer(target, x25->x25, x25->x25_len); 139 } 140 141 static isc_result_t 142 tostruct_x25(ARGS_TOSTRUCT) { 143 dns_rdata_x25_t *x25 = target; 144 isc_region_t r; 145 146 REQUIRE(rdata->type == dns_rdatatype_x25); 147 REQUIRE(x25 != NULL); 148 REQUIRE(rdata->length != 0); 149 150 x25->common.rdclass = rdata->rdclass; 151 x25->common.rdtype = rdata->type; 152 ISC_LINK_INIT(&x25->common, link); 153 154 dns_rdata_toregion(rdata, &r); 155 x25->x25_len = uint8_fromregion(&r); 156 isc_region_consume(&r, 1); 157 x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len); 158 x25->mctx = mctx; 159 return ISC_R_SUCCESS; 160 } 161 162 static void 163 freestruct_x25(ARGS_FREESTRUCT) { 164 dns_rdata_x25_t *x25 = source; 165 166 REQUIRE(x25 != NULL); 167 REQUIRE(x25->common.rdtype == dns_rdatatype_x25); 168 169 if (x25->mctx == NULL) { 170 return; 171 } 172 173 if (x25->x25 != NULL) { 174 isc_mem_free(x25->mctx, x25->x25); 175 } 176 x25->mctx = NULL; 177 } 178 179 static isc_result_t 180 additionaldata_x25(ARGS_ADDLDATA) { 181 REQUIRE(rdata->type == dns_rdatatype_x25); 182 183 UNUSED(rdata); 184 UNUSED(owner); 185 UNUSED(add); 186 UNUSED(arg); 187 188 return ISC_R_SUCCESS; 189 } 190 191 static isc_result_t 192 digest_x25(ARGS_DIGEST) { 193 isc_region_t r; 194 195 REQUIRE(rdata->type == dns_rdatatype_x25); 196 197 dns_rdata_toregion(rdata, &r); 198 199 return (digest)(arg, &r); 200 } 201 202 static bool 203 checkowner_x25(ARGS_CHECKOWNER) { 204 REQUIRE(type == dns_rdatatype_x25); 205 206 UNUSED(name); 207 UNUSED(type); 208 UNUSED(rdclass); 209 UNUSED(wildcard); 210 211 return true; 212 } 213 214 static bool 215 checknames_x25(ARGS_CHECKNAMES) { 216 REQUIRE(rdata->type == dns_rdatatype_x25); 217 218 UNUSED(rdata); 219 UNUSED(owner); 220 UNUSED(bad); 221 222 return true; 223 } 224 225 static int 226 casecompare_x25(ARGS_COMPARE) { 227 return compare_x25(rdata1, rdata2); 228 } 229 230 #endif /* RDATA_GENERIC_X25_19_C */ 231