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