rt_21.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2009, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1999-2001, 2003  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: rt_21.c,v 1.48 2009/12/04 22:06:37 tbox Exp $ */
00019 
00020 /* reviewed: Thu Mar 16 15:02:31 PST 2000 by brister */
00021 
00022 /* RFC1183 */
00023 
00024 #ifndef RDATA_GENERIC_RT_21_C
00025 #define RDATA_GENERIC_RT_21_C
00026 
00027 #define RRTYPE_RT_ATTRIBUTES (0)
00028 
00029 static inline isc_result_t
00030 fromtext_rt(ARGS_FROMTEXT) {
00031         isc_token_t token;
00032         dns_name_t name;
00033         isc_buffer_t buffer;
00034         isc_boolean_t ok;
00035 
00036         REQUIRE(type == 21);
00037 
00038         UNUSED(type);
00039         UNUSED(rdclass);
00040         UNUSED(callbacks);
00041 
00042         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00043                                       ISC_FALSE));
00044         if (token.value.as_ulong > 0xffffU)
00045                 RETTOK(ISC_R_RANGE);
00046         RETERR(uint16_tobuffer(token.value.as_ulong, target));
00047 
00048         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00049                                       ISC_FALSE));
00050 
00051         dns_name_init(&name, NULL);
00052         buffer_fromregion(&buffer, &token.value.as_region);
00053         origin = (origin != NULL) ? origin : dns_rootname;
00054         RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
00055         ok = ISC_TRUE;
00056         if ((options & DNS_RDATA_CHECKNAMES) != 0)
00057                 ok = dns_name_ishostname(&name, ISC_FALSE);
00058         if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
00059                 RETTOK(DNS_R_BADNAME);
00060         if (!ok && callbacks != NULL)
00061                 warn_badname(&name, lexer, callbacks);
00062         return (ISC_R_SUCCESS);
00063 }
00064 
00065 static inline isc_result_t
00066 totext_rt(ARGS_TOTEXT) {
00067         isc_region_t region;
00068         dns_name_t name;
00069         dns_name_t prefix;
00070         isc_boolean_t sub;
00071         char buf[sizeof("64000")];
00072         unsigned short num;
00073 
00074         REQUIRE(rdata->type == 21);
00075         REQUIRE(rdata->length != 0);
00076 
00077         dns_name_init(&name, NULL);
00078         dns_name_init(&prefix, NULL);
00079 
00080         dns_rdata_toregion(rdata, &region);
00081         num = uint16_fromregion(&region);
00082         isc_region_consume(&region, 2);
00083         sprintf(buf, "%u", num);
00084         RETERR(str_totext(buf, target));
00085         RETERR(str_totext(" ", target));
00086         dns_name_fromregion(&name, &region);
00087         sub = name_prefix(&name, tctx->origin, &prefix);
00088         return (dns_name_totext(&prefix, sub, target));
00089 }
00090 
00091 static inline isc_result_t
00092 fromwire_rt(ARGS_FROMWIRE) {
00093         dns_name_t name;
00094         isc_region_t sregion;
00095         isc_region_t tregion;
00096 
00097         REQUIRE(type == 21);
00098 
00099         UNUSED(type);
00100         UNUSED(rdclass);
00101 
00102         dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
00103 
00104         dns_name_init(&name, NULL);
00105 
00106         isc_buffer_activeregion(source, &sregion);
00107         isc_buffer_availableregion(target, &tregion);
00108         if (tregion.length < 2)
00109                 return (ISC_R_NOSPACE);
00110         if (sregion.length < 2)
00111                 return (ISC_R_UNEXPECTEDEND);
00112         memmove(tregion.base, sregion.base, 2);
00113         isc_buffer_forward(source, 2);
00114         isc_buffer_add(target, 2);
00115         return (dns_name_fromwire(&name, source, dctx, options, target));
00116 }
00117 
00118 static inline isc_result_t
00119 towire_rt(ARGS_TOWIRE) {
00120         dns_name_t name;
00121         dns_offsets_t offsets;
00122         isc_region_t region;
00123         isc_region_t tr;
00124 
00125         REQUIRE(rdata->type == 21);
00126         REQUIRE(rdata->length != 0);
00127 
00128         dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
00129         isc_buffer_availableregion(target, &tr);
00130         dns_rdata_toregion(rdata, &region);
00131         if (tr.length < 2)
00132                 return (ISC_R_NOSPACE);
00133         memmove(tr.base, region.base, 2);
00134         isc_region_consume(&region, 2);
00135         isc_buffer_add(target, 2);
00136 
00137         dns_name_init(&name, offsets);
00138         dns_name_fromregion(&name, &region);
00139 
00140         return (dns_name_towire(&name, cctx, target));
00141 }
00142 
00143 static inline int
00144 compare_rt(ARGS_COMPARE) {
00145         dns_name_t name1;
00146         dns_name_t name2;
00147         isc_region_t region1;
00148         isc_region_t region2;
00149         int order;
00150 
00151         REQUIRE(rdata1->type == rdata2->type);
00152         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00153         REQUIRE(rdata1->type == 21);
00154         REQUIRE(rdata1->length != 0);
00155         REQUIRE(rdata2->length != 0);
00156 
00157         order = memcmp(rdata1->data, rdata2->data, 2);
00158         if (order != 0)
00159                 return (order < 0 ? -1 : 1);
00160 
00161         dns_name_init(&name1, NULL);
00162         dns_name_init(&name2, NULL);
00163 
00164         dns_rdata_toregion(rdata1, &region1);
00165         dns_rdata_toregion(rdata2, &region2);
00166 
00167         isc_region_consume(&region1, 2);
00168         isc_region_consume(&region2, 2);
00169 
00170         dns_name_fromregion(&name1, &region1);
00171         dns_name_fromregion(&name2, &region2);
00172 
00173         return (dns_name_rdatacompare(&name1, &name2));
00174 }
00175 
00176 static inline isc_result_t
00177 fromstruct_rt(ARGS_FROMSTRUCT) {
00178         dns_rdata_rt_t *rt = source;
00179         isc_region_t region;
00180 
00181         REQUIRE(type == 21);
00182         REQUIRE(source != NULL);
00183         REQUIRE(rt->common.rdtype == type);
00184         REQUIRE(rt->common.rdclass == rdclass);
00185 
00186         UNUSED(type);
00187         UNUSED(rdclass);
00188 
00189         RETERR(uint16_tobuffer(rt->preference, target));
00190         dns_name_toregion(&rt->host, &region);
00191         return (isc_buffer_copyregion(target, &region));
00192 }
00193 
00194 static inline isc_result_t
00195 tostruct_rt(ARGS_TOSTRUCT) {
00196         isc_region_t region;
00197         dns_rdata_rt_t *rt = target;
00198         dns_name_t name;
00199 
00200         REQUIRE(rdata->type == 21);
00201         REQUIRE(target != NULL);
00202         REQUIRE(rdata->length != 0);
00203 
00204         rt->common.rdclass = rdata->rdclass;
00205         rt->common.rdtype = rdata->type;
00206         ISC_LINK_INIT(&rt->common, link);
00207 
00208         dns_name_init(&name, NULL);
00209         dns_rdata_toregion(rdata, &region);
00210         rt->preference = uint16_fromregion(&region);
00211         isc_region_consume(&region, 2);
00212         dns_name_fromregion(&name, &region);
00213         dns_name_init(&rt->host, NULL);
00214         RETERR(name_duporclone(&name, mctx, &rt->host));
00215 
00216         rt->mctx = mctx;
00217         return (ISC_R_SUCCESS);
00218 }
00219 
00220 static inline void
00221 freestruct_rt(ARGS_FREESTRUCT) {
00222         dns_rdata_rt_t *rt = source;
00223 
00224         REQUIRE(source != NULL);
00225         REQUIRE(rt->common.rdtype == 21);
00226 
00227         if (rt->mctx == NULL)
00228                 return;
00229 
00230         dns_name_free(&rt->host, rt->mctx);
00231         rt->mctx = NULL;
00232 }
00233 
00234 static inline isc_result_t
00235 additionaldata_rt(ARGS_ADDLDATA) {
00236         dns_name_t name;
00237         dns_offsets_t offsets;
00238         isc_region_t region;
00239         isc_result_t result;
00240 
00241         REQUIRE(rdata->type == 21);
00242 
00243         dns_name_init(&name, offsets);
00244         dns_rdata_toregion(rdata, &region);
00245         isc_region_consume(&region, 2);
00246         dns_name_fromregion(&name, &region);
00247 
00248         result = (add)(arg, &name, dns_rdatatype_x25);
00249         if (result != ISC_R_SUCCESS)
00250                 return (result);
00251         result = (add)(arg, &name, dns_rdatatype_isdn);
00252         if (result != ISC_R_SUCCESS)
00253                 return (result);
00254         return ((add)(arg, &name, dns_rdatatype_a));
00255 }
00256 
00257 static inline isc_result_t
00258 digest_rt(ARGS_DIGEST) {
00259         isc_region_t r1, r2;
00260         isc_result_t result;
00261         dns_name_t name;
00262 
00263         REQUIRE(rdata->type == 21);
00264 
00265         dns_rdata_toregion(rdata, &r1);
00266         r2 = r1;
00267         isc_region_consume(&r2, 2);
00268         r1.length = 2;
00269         result = (digest)(arg, &r1);
00270         if (result != ISC_R_SUCCESS)
00271                 return (result);
00272         dns_name_init(&name, NULL);
00273         dns_name_fromregion(&name, &r2);
00274         return (dns_name_digest(&name, digest, arg));
00275 }
00276 
00277 static inline isc_boolean_t
00278 checkowner_rt(ARGS_CHECKOWNER) {
00279 
00280         REQUIRE(type == 21);
00281 
00282         UNUSED(name);
00283         UNUSED(type);
00284         UNUSED(rdclass);
00285         UNUSED(wildcard);
00286 
00287         return (ISC_TRUE);
00288 }
00289 
00290 static inline isc_boolean_t
00291 checknames_rt(ARGS_CHECKNAMES) {
00292         isc_region_t region;
00293         dns_name_t name;
00294 
00295         REQUIRE(rdata->type == 21);
00296 
00297         UNUSED(owner);
00298 
00299         dns_rdata_toregion(rdata, &region);
00300         isc_region_consume(&region, 2);
00301         dns_name_init(&name, NULL);
00302         dns_name_fromregion(&name, &region);
00303         if (!dns_name_ishostname(&name, ISC_FALSE)) {
00304                 if (bad != NULL)
00305                         dns_name_clone(&name, bad);
00306                 return (ISC_FALSE);
00307         }
00308         return (ISC_TRUE);
00309 }
00310 
00311 static inline int
00312 casecompare_rt(ARGS_COMPARE) {
00313         return (compare_rt(rdata1, rdata2));
00314 }
00315 
00316 #endif  /* RDATA_GENERIC_RT_21_C */

Generated on Tue Apr 28 17:41:00 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha