1 /* $NetBSD: dhcid_49.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2006, 2007, 2009, 2011, 2012 Internet Systems Consortium, Inc. ("ISC") 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /* Id */ 20 21 /* RFC 4701 */ 22 23 #ifndef RDATA_IN_1_DHCID_49_C 24 #define RDATA_IN_1_DHCID_49_C 1 25 26 #define RRTYPE_DHCID_ATTRIBUTES 0 27 28 static inline isc_result_t 29 fromtext_in_dhcid(ARGS_FROMTEXT) { 30 31 REQUIRE(type == 49); 32 REQUIRE(rdclass == 1); 33 34 UNUSED(type); 35 UNUSED(rdclass); 36 UNUSED(origin); 37 UNUSED(options); 38 UNUSED(callbacks); 39 40 return (isc_base64_tobuffer(lexer, target, -1)); 41 } 42 43 static inline isc_result_t 44 totext_in_dhcid(ARGS_TOTEXT) { 45 isc_region_t sr; 46 char buf[sizeof(" ; 64000 255 64000")]; 47 size_t n; 48 49 REQUIRE(rdata->type == 49); 50 REQUIRE(rdata->rdclass == 1); 51 REQUIRE(rdata->length != 0); 52 53 dns_rdata_toregion(rdata, &sr); 54 55 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) 56 RETERR(str_totext("( " /*)*/, target)); 57 if (tctx->width == 0) /* No splitting */ 58 RETERR(isc_base64_totext(&sr, 60, "", target)); 59 else 60 RETERR(isc_base64_totext(&sr, tctx->width - 2, 61 tctx->linebreak, target)); 62 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { 63 RETERR(str_totext(/* ( */ " )", target)); 64 if (rdata->length > 2) { 65 n = snprintf(buf, sizeof(buf), " ; %u %u %u", 66 sr.base[0] * 256 + sr.base[1], 67 sr.base[2], rdata->length - 3); 68 INSIST(n < sizeof(buf)); 69 RETERR(str_totext(buf, target)); 70 } 71 } 72 return (ISC_R_SUCCESS); 73 } 74 75 static inline isc_result_t 76 fromwire_in_dhcid(ARGS_FROMWIRE) { 77 isc_region_t sr; 78 79 REQUIRE(type == 49); 80 REQUIRE(rdclass == 1); 81 82 UNUSED(type); 83 UNUSED(rdclass); 84 UNUSED(dctx); 85 UNUSED(options); 86 87 isc_buffer_activeregion(source, &sr); 88 if (sr.length == 0) 89 return (ISC_R_UNEXPECTEDEND); 90 91 isc_buffer_forward(source, sr.length); 92 return (mem_tobuffer(target, sr.base, sr.length)); 93 } 94 95 static inline isc_result_t 96 towire_in_dhcid(ARGS_TOWIRE) { 97 isc_region_t sr; 98 99 REQUIRE(rdata->type == 49); 100 REQUIRE(rdata->rdclass == 1); 101 REQUIRE(rdata->length != 0); 102 103 UNUSED(cctx); 104 105 dns_rdata_toregion(rdata, &sr); 106 return (mem_tobuffer(target, sr.base, sr.length)); 107 } 108 109 static inline int 110 compare_in_dhcid(ARGS_COMPARE) { 111 isc_region_t r1; 112 isc_region_t r2; 113 114 REQUIRE(rdata1->type == rdata2->type); 115 REQUIRE(rdata1->rdclass == rdata2->rdclass); 116 REQUIRE(rdata1->type == 49); 117 REQUIRE(rdata1->rdclass == 1); 118 REQUIRE(rdata1->length != 0); 119 REQUIRE(rdata2->length != 0); 120 121 dns_rdata_toregion(rdata1, &r1); 122 dns_rdata_toregion(rdata2, &r2); 123 return (isc_region_compare(&r1, &r2)); 124 } 125 126 static inline isc_result_t 127 fromstruct_in_dhcid(ARGS_FROMSTRUCT) { 128 dns_rdata_in_dhcid_t *dhcid = source; 129 130 REQUIRE(type == 49); 131 REQUIRE(rdclass == 1); 132 REQUIRE(source != NULL); 133 REQUIRE(dhcid->common.rdtype == type); 134 REQUIRE(dhcid->common.rdclass == rdclass); 135 REQUIRE(dhcid->length != 0); 136 137 UNUSED(type); 138 UNUSED(rdclass); 139 140 return (mem_tobuffer(target, dhcid->dhcid, dhcid->length)); 141 } 142 143 static inline isc_result_t 144 tostruct_in_dhcid(ARGS_TOSTRUCT) { 145 dns_rdata_in_dhcid_t *dhcid = target; 146 isc_region_t region; 147 148 REQUIRE(rdata->type == 49); 149 REQUIRE(rdata->rdclass == 1); 150 REQUIRE(target != NULL); 151 REQUIRE(rdata->length != 0); 152 153 dhcid->common.rdclass = rdata->rdclass; 154 dhcid->common.rdtype = rdata->type; 155 ISC_LINK_INIT(&dhcid->common, link); 156 157 dns_rdata_toregion(rdata, ®ion); 158 159 dhcid->dhcid = mem_maybedup(mctx, region.base, region.length); 160 if (dhcid->dhcid == NULL) 161 return (ISC_R_NOMEMORY); 162 163 dhcid->mctx = mctx; 164 return (ISC_R_SUCCESS); 165 } 166 167 static inline void 168 freestruct_in_dhcid(ARGS_FREESTRUCT) { 169 dns_rdata_in_dhcid_t *dhcid = source; 170 171 REQUIRE(dhcid != NULL); 172 REQUIRE(dhcid->common.rdtype == 49); 173 REQUIRE(dhcid->common.rdclass == 1); 174 175 if (dhcid->mctx == NULL) 176 return; 177 178 if (dhcid->dhcid != NULL) 179 isc_mem_free(dhcid->mctx, dhcid->dhcid); 180 dhcid->mctx = NULL; 181 } 182 183 static inline isc_result_t 184 additionaldata_in_dhcid(ARGS_ADDLDATA) { 185 REQUIRE(rdata->type == 49); 186 REQUIRE(rdata->rdclass == 1); 187 188 UNUSED(rdata); 189 UNUSED(add); 190 UNUSED(arg); 191 192 return (ISC_R_SUCCESS); 193 } 194 195 static inline isc_result_t 196 digest_in_dhcid(ARGS_DIGEST) { 197 isc_region_t r; 198 199 REQUIRE(rdata->type == 49); 200 REQUIRE(rdata->rdclass == 1); 201 202 dns_rdata_toregion(rdata, &r); 203 204 return ((digest)(arg, &r)); 205 } 206 207 static inline isc_boolean_t 208 checkowner_in_dhcid(ARGS_CHECKOWNER) { 209 210 REQUIRE(type == 49); 211 REQUIRE(rdclass == 1); 212 213 UNUSED(name); 214 UNUSED(type); 215 UNUSED(rdclass); 216 UNUSED(wildcard); 217 218 return (ISC_TRUE); 219 } 220 221 static inline isc_boolean_t 222 checknames_in_dhcid(ARGS_CHECKNAMES) { 223 224 REQUIRE(rdata->type == 49); 225 REQUIRE(rdata->rdclass == 1); 226 227 UNUSED(rdata); 228 UNUSED(owner); 229 UNUSED(bad); 230 231 return (ISC_TRUE); 232 } 233 234 static inline int 235 casecompare_in_dhcid(ARGS_COMPARE) { 236 return (compare_in_dhcid(rdata1, rdata2)); 237 } 238 239 #endif /* RDATA_IN_1_DHCID_49_C */ 240