1 /* $NetBSD: l64_106.c,v 1.5 2020/05/24 19:46:24 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * This Source Code Form is subject to the terms of the Mozilla Public 7 * License, v. 2.0. If a copy of the MPL was not distributed with this 8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 * 10 * See the COPYRIGHT file distributed with this work for additional 11 * information regarding copyright ownership. 12 */ 13 14 #ifndef RDATA_GENERIC_L64_106_C 15 #define RDATA_GENERIC_L64_106_C 16 17 #include <string.h> 18 19 #include <isc/net.h> 20 21 #define RRTYPE_L64_ATTRIBUTES (0) 22 23 static inline isc_result_t 24 fromtext_l64(ARGS_FROMTEXT) { 25 isc_token_t token; 26 unsigned char locator[NS_LOCATORSZ]; 27 28 REQUIRE(type == dns_rdatatype_l64); 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_number, 37 false)); 38 if (token.value.as_ulong > 0xffffU) { 39 RETTOK(ISC_R_RANGE); 40 } 41 RETERR(uint16_tobuffer(token.value.as_ulong, target)); 42 43 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, 44 false)); 45 46 if (locator_pton(DNS_AS_STR(token), locator) != 1) { 47 RETTOK(DNS_R_SYNTAX); 48 } 49 return (mem_tobuffer(target, locator, NS_LOCATORSZ)); 50 } 51 52 static inline isc_result_t 53 totext_l64(ARGS_TOTEXT) { 54 isc_region_t region; 55 char buf[sizeof("xxxx:xxxx:xxxx:xxxx")]; 56 unsigned short num; 57 58 REQUIRE(rdata->type == dns_rdatatype_l64); 59 REQUIRE(rdata->length == 10); 60 61 UNUSED(tctx); 62 63 dns_rdata_toregion(rdata, ®ion); 64 num = uint16_fromregion(®ion); 65 isc_region_consume(®ion, 2); 66 snprintf(buf, sizeof(buf), "%u", num); 67 RETERR(str_totext(buf, target)); 68 69 RETERR(str_totext(" ", target)); 70 71 snprintf(buf, sizeof(buf), "%x:%x:%x:%x", 72 region.base[0] << 8 | region.base[1], 73 region.base[2] << 8 | region.base[3], 74 region.base[4] << 8 | region.base[5], 75 region.base[6] << 8 | region.base[7]); 76 return (str_totext(buf, target)); 77 } 78 79 static inline isc_result_t 80 fromwire_l64(ARGS_FROMWIRE) { 81 isc_region_t sregion; 82 83 REQUIRE(type == dns_rdatatype_l64); 84 85 UNUSED(type); 86 UNUSED(options); 87 UNUSED(rdclass); 88 UNUSED(dctx); 89 90 isc_buffer_activeregion(source, &sregion); 91 if (sregion.length != 10) { 92 return (DNS_R_FORMERR); 93 } 94 isc_buffer_forward(source, sregion.length); 95 return (mem_tobuffer(target, sregion.base, sregion.length)); 96 } 97 98 static inline isc_result_t 99 towire_l64(ARGS_TOWIRE) { 100 REQUIRE(rdata->type == dns_rdatatype_l64); 101 REQUIRE(rdata->length == 10); 102 103 UNUSED(cctx); 104 105 return (mem_tobuffer(target, rdata->data, rdata->length)); 106 } 107 108 static inline int 109 compare_l64(ARGS_COMPARE) { 110 isc_region_t region1; 111 isc_region_t region2; 112 113 REQUIRE(rdata1->type == rdata2->type); 114 REQUIRE(rdata1->rdclass == rdata2->rdclass); 115 REQUIRE(rdata1->type == dns_rdatatype_l64); 116 REQUIRE(rdata1->length == 10); 117 REQUIRE(rdata2->length == 10); 118 119 dns_rdata_toregion(rdata1, ®ion1); 120 dns_rdata_toregion(rdata2, ®ion2); 121 return (isc_region_compare(®ion1, ®ion2)); 122 } 123 124 static inline isc_result_t 125 fromstruct_l64(ARGS_FROMSTRUCT) { 126 dns_rdata_l64_t *l64 = source; 127 128 REQUIRE(type == dns_rdatatype_l64); 129 REQUIRE(l64 != NULL); 130 REQUIRE(l64->common.rdtype == type); 131 REQUIRE(l64->common.rdclass == rdclass); 132 133 UNUSED(type); 134 UNUSED(rdclass); 135 136 RETERR(uint16_tobuffer(l64->pref, target)); 137 return (mem_tobuffer(target, l64->l64, sizeof(l64->l64))); 138 } 139 140 static inline isc_result_t 141 tostruct_l64(ARGS_TOSTRUCT) { 142 isc_region_t region; 143 dns_rdata_l64_t *l64 = target; 144 145 REQUIRE(rdata->type == dns_rdatatype_l64); 146 REQUIRE(l64 != NULL); 147 REQUIRE(rdata->length == 10); 148 149 UNUSED(mctx); 150 151 l64->common.rdclass = rdata->rdclass; 152 l64->common.rdtype = rdata->type; 153 ISC_LINK_INIT(&l64->common, link); 154 155 dns_rdata_toregion(rdata, ®ion); 156 l64->pref = uint16_fromregion(®ion); 157 memmove(l64->l64, region.base, region.length); 158 return (ISC_R_SUCCESS); 159 } 160 161 static inline void 162 freestruct_l64(ARGS_FREESTRUCT) { 163 dns_rdata_l64_t *l64 = source; 164 165 REQUIRE(l64 != NULL); 166 REQUIRE(l64->common.rdtype == dns_rdatatype_l64); 167 168 return; 169 } 170 171 static inline isc_result_t 172 additionaldata_l64(ARGS_ADDLDATA) { 173 REQUIRE(rdata->type == dns_rdatatype_l64); 174 REQUIRE(rdata->length == 10); 175 176 UNUSED(rdata); 177 UNUSED(add); 178 UNUSED(arg); 179 180 return (ISC_R_SUCCESS); 181 } 182 183 static inline isc_result_t 184 digest_l64(ARGS_DIGEST) { 185 isc_region_t r; 186 187 REQUIRE(rdata->type == dns_rdatatype_l64); 188 REQUIRE(rdata->length == 10); 189 190 dns_rdata_toregion(rdata, &r); 191 192 return ((digest)(arg, &r)); 193 } 194 195 static inline bool 196 checkowner_l64(ARGS_CHECKOWNER) { 197 REQUIRE(type == dns_rdatatype_l64); 198 199 UNUSED(name); 200 UNUSED(type); 201 UNUSED(rdclass); 202 UNUSED(wildcard); 203 204 return (true); 205 } 206 207 static inline bool 208 checknames_l64(ARGS_CHECKNAMES) { 209 REQUIRE(rdata->type == dns_rdatatype_l64); 210 REQUIRE(rdata->length == 10); 211 212 UNUSED(rdata); 213 UNUSED(owner); 214 UNUSED(bad); 215 216 return (true); 217 } 218 219 static inline int 220 casecompare_l64(ARGS_COMPARE) { 221 return (compare_l64(rdata1, rdata2)); 222 } 223 224 #endif /* RDATA_GENERIC_L64_106_C */ 225