Home | History | Annotate | Line # | Download | only in generic
      1 /*	$NetBSD: x25_19.c,v 1.11 2026/01/29 18:37:53 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, &region);
     61 	return txt_totext(&region, 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 	DNS_RDATACOMMON_INIT(x25, rdata->type, rdata->rdclass);
    151 
    152 	dns_rdata_toregion(rdata, &r);
    153 	x25->x25_len = uint8_fromregion(&r);
    154 	isc_region_consume(&r, 1);
    155 	x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len);
    156 	x25->mctx = mctx;
    157 	return ISC_R_SUCCESS;
    158 }
    159 
    160 static void
    161 freestruct_x25(ARGS_FREESTRUCT) {
    162 	dns_rdata_x25_t *x25 = source;
    163 
    164 	REQUIRE(x25 != NULL);
    165 	REQUIRE(x25->common.rdtype == dns_rdatatype_x25);
    166 
    167 	if (x25->mctx == NULL) {
    168 		return;
    169 	}
    170 
    171 	if (x25->x25 != NULL) {
    172 		isc_mem_free(x25->mctx, x25->x25);
    173 	}
    174 	x25->mctx = NULL;
    175 }
    176 
    177 static isc_result_t
    178 additionaldata_x25(ARGS_ADDLDATA) {
    179 	REQUIRE(rdata->type == dns_rdatatype_x25);
    180 
    181 	UNUSED(rdata);
    182 	UNUSED(owner);
    183 	UNUSED(add);
    184 	UNUSED(arg);
    185 
    186 	return ISC_R_SUCCESS;
    187 }
    188 
    189 static isc_result_t
    190 digest_x25(ARGS_DIGEST) {
    191 	isc_region_t r;
    192 
    193 	REQUIRE(rdata->type == dns_rdatatype_x25);
    194 
    195 	dns_rdata_toregion(rdata, &r);
    196 
    197 	return (digest)(arg, &r);
    198 }
    199 
    200 static bool
    201 checkowner_x25(ARGS_CHECKOWNER) {
    202 	REQUIRE(type == dns_rdatatype_x25);
    203 
    204 	UNUSED(name);
    205 	UNUSED(type);
    206 	UNUSED(rdclass);
    207 	UNUSED(wildcard);
    208 
    209 	return true;
    210 }
    211 
    212 static bool
    213 checknames_x25(ARGS_CHECKNAMES) {
    214 	REQUIRE(rdata->type == dns_rdatatype_x25);
    215 
    216 	UNUSED(rdata);
    217 	UNUSED(owner);
    218 	UNUSED(bad);
    219 
    220 	return true;
    221 }
    222 
    223 static int
    224 casecompare_x25(ARGS_COMPARE) {
    225 	return compare_x25(rdata1, rdata2);
    226 }
    227 
    228 #endif /* RDATA_GENERIC_X25_19_C */
    229