a_1.c revision ad1317338af79edad878c9c3e4361798503310ba
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt/*
990d0e893f5b70e735cdf990af66e9ec6e91fa78Tinderbox User * Copyright (C) 2005, 2007, 2009, 2014-2016 Internet Systems Consortium, Inc. ("ISC")
3e02c9e33656dcd9c364633d42dd785d3e6fdd66Automatic Updater *
3e02c9e33656dcd9c364633d42dd785d3e6fdd66Automatic Updater * This Source Code Form is subject to the terms of the Mozilla Public
c6fb85f9500350e5ce58c9a24f5d264c8a8bd6f4Automatic Updater * License, v. 2.0. If a copy of the MPL was not distributed with this
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt * file, You can obtain one at http://mozilla.org/MPL/2.0/.
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt */
3e02c9e33656dcd9c364633d42dd785d3e6fdd66Automatic Updater
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt/* $Id: a_1.c,v 1.8 2009/12/04 22:06:37 tbox Exp $ */
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
3e02c9e33656dcd9c364633d42dd785d3e6fdd66Automatic Updater/* by Bjorn.Victor@it.uu.se, 2005-05-07 */
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt/* Based on generic/soa_6.c and generic/mx_15.c */
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt#ifndef RDATA_CH_3_A_1_C
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt#define RDATA_CH_3_A_1_C
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User#include <isc/net.h>
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt#define RRTYPE_A_ATTRIBUTES (0)
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntstatic inline isc_result_t
2cbb4ab75757fbb656997a82c14ca07db37d481aAutomatic Updaterfromtext_ch_a(ARGS_FROMTEXT) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt isc_token_t token;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_name_t name;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt isc_buffer_t buffer;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt REQUIRE(type == dns_rdatatype_a);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt REQUIRE(rdclass == dns_rdataclass_ch); /* 3 */
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt UNUSED(type);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt UNUSED(callbacks);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt ISC_FALSE));
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater /* get domain name */
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_name_init(&name, NULL);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt buffer_fromregion(&buffer, &token.value.as_region);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt if (origin == NULL)
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt origin = dns_rootname;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt if ((options & DNS_RDATA_CHECKNAMES) != 0 &&
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt (options & DNS_RDATA_CHECKREVERSE) != 0) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt isc_boolean_t ok;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt ok = dns_name_ishostname(&name, ISC_FALSE);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt RETTOK(DNS_R_BADNAME);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt if (!ok && callbacks != NULL)
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt warn_badname(&name, lexer, callbacks);
6f1205897504b8f50b1785975482c995888dd630Tinderbox User }
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt /* 16-bit octal address */
6f1205897504b8f50b1785975482c995888dd630Tinderbox User RETERR(isc_lex_getoctaltoken(lexer, &token, ISC_FALSE));
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt if (token.value.as_ulong > 0xffffU)
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt RETTOK(ISC_R_RANGE);
fd0b768f4c23d22c89f8a156a632831583b7fb68Automatic Updater return (uint16_tobuffer(token.value.as_ulong, target));
fd0b768f4c23d22c89f8a156a632831583b7fb68Automatic Updater}
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntstatic inline isc_result_t
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunttotext_ch_a(ARGS_TOTEXT) {
6f1205897504b8f50b1785975482c995888dd630Tinderbox User isc_region_t region;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_name_t name;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_name_t prefix;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt isc_boolean_t sub;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt char buf[sizeof("0177777")];
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt isc_uint16_t addr;
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt REQUIRE(rdata->type == dns_rdatatype_a);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt REQUIRE(rdata->rdclass == dns_rdataclass_ch); /* 3 */
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt REQUIRE(rdata->length != 0);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_name_init(&name, NULL);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_name_init(&prefix, NULL);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_rdata_toregion(rdata, &region);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_name_fromregion(&name, &region);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt isc_region_consume(&region, name_length(&name));
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt addr = uint16_fromregion(&region);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
6f1205897504b8f50b1785975482c995888dd630Tinderbox User sub = name_prefix(&name, tctx->origin, &prefix);
6f1205897504b8f50b1785975482c995888dd630Tinderbox User RETERR(dns_name_totext(&prefix, sub, target));
6f1205897504b8f50b1785975482c995888dd630Tinderbox User
6f1205897504b8f50b1785975482c995888dd630Tinderbox User snprintf(buf, sizeof(buf), "%o", addr); /* note octal */
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater RETERR(str_totext(" ", target));
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User return (str_totext(buf, target));
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User}
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox Userstatic inline isc_result_t
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox Userfromwire_ch_a(ARGS_FROMWIRE) {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User isc_region_t sregion;
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User isc_region_t tregion;
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User dns_name_t name;
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User REQUIRE(type == dns_rdatatype_a);
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User REQUIRE(rdclass == dns_rdataclass_ch);
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User UNUSED(type);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt UNUSED(rdclass);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_name_init(&name, NULL);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
12bfbed87cfffa65ac300b72c5665ab38a355c2fAutomatic Updater RETERR(dns_name_fromwire(&name, source, dctx, options, target));
12bfbed87cfffa65ac300b72c5665ab38a355c2fAutomatic Updater
12bfbed87cfffa65ac300b72c5665ab38a355c2fAutomatic Updater isc_buffer_activeregion(source, &sregion);
12bfbed87cfffa65ac300b72c5665ab38a355c2fAutomatic Updater isc_buffer_availableregion(target, &tregion);
12bfbed87cfffa65ac300b72c5665ab38a355c2fAutomatic Updater if (sregion.length < 2)
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt return (ISC_R_UNEXPECTEDEND);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt if (tregion.length < 2)
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt return (ISC_R_NOSPACE);
6f1205897504b8f50b1785975482c995888dd630Tinderbox User
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt memmove(tregion.base, sregion.base, 2);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt isc_buffer_forward(source, 2);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt isc_buffer_add(target, 2);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt return (ISC_R_SUCCESS);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt}
6f1205897504b8f50b1785975482c995888dd630Tinderbox User
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntstatic inline isc_result_t
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunttowire_ch_a(ARGS_TOWIRE) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_name_t name;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_offsets_t offsets;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt isc_region_t sregion;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt isc_region_t tregion;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt REQUIRE(rdata->type == dns_rdatatype_a);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt REQUIRE(rdata->rdclass == dns_rdataclass_ch);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt REQUIRE(rdata->length != 0);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_name_init(&name, offsets);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_rdata_toregion(rdata, &sregion);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt dns_name_fromregion(&name, &sregion);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater isc_region_consume(&sregion, name_length(&name));
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt RETERR(dns_name_towire(&name, cctx, target));
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt isc_buffer_availableregion(target, &tregion);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt if (tregion.length < 2)
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt return (ISC_R_NOSPACE);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
memmove(tregion.base, sregion.base, 2);
isc_buffer_add(target, 2);
return (ISC_R_SUCCESS);
}
static inline int
compare_ch_a(ARGS_COMPARE) {
dns_name_t name1;
dns_name_t name2;
isc_region_t region1;
isc_region_t region2;
int order;
REQUIRE(rdata1->type == rdata2->type);
REQUIRE(rdata1->rdclass == rdata2->rdclass);
REQUIRE(rdata1->type == dns_rdatatype_a);
REQUIRE(rdata1->rdclass == dns_rdataclass_ch);
REQUIRE(rdata1->length != 0);
REQUIRE(rdata2->length != 0);
dns_name_init(&name1, NULL);
dns_name_init(&name2, NULL);
dns_rdata_toregion(rdata1, &region1);
dns_rdata_toregion(rdata2, &region2);
dns_name_fromregion(&name1, &region1);
dns_name_fromregion(&name2, &region2);
isc_region_consume(&region1, name_length(&name1));
isc_region_consume(&region2, name_length(&name2));
order = dns_name_rdatacompare(&name1, &name2);
if (order != 0)
return (order);
order = memcmp(rdata1->data, rdata2->data, 2);
if (order != 0)
order = (order < 0) ? -1 : 1;
return (order);
}
static inline isc_result_t
fromstruct_ch_a(ARGS_FROMSTRUCT) {
dns_rdata_ch_a_t *a = source;
isc_region_t region;
REQUIRE(type == dns_rdatatype_a);
REQUIRE(source != NULL);
REQUIRE(a->common.rdtype == type);
REQUIRE(a->common.rdclass == rdclass);
UNUSED(type);
UNUSED(rdclass);
dns_name_toregion(&a->ch_addr_dom, &region);
RETERR(isc_buffer_copyregion(target, &region));
return (uint16_tobuffer(ntohs(a->ch_addr), target));
}
static inline isc_result_t
tostruct_ch_a(ARGS_TOSTRUCT) {
dns_rdata_ch_a_t *a = target;
isc_region_t region;
dns_name_t name;
REQUIRE(rdata->type == dns_rdatatype_a);
REQUIRE(rdata->rdclass == dns_rdataclass_ch);
REQUIRE(rdata->length != 0);
a->common.rdclass = rdata->rdclass;
a->common.rdtype = rdata->type;
ISC_LINK_INIT(&a->common, link);
dns_rdata_toregion(rdata, &region);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &region);
isc_region_consume(&region, name_length(&name));
dns_name_init(&a->ch_addr_dom, NULL);
RETERR(name_duporclone(&name, mctx, &a->ch_addr_dom));
a->ch_addr = htons(uint16_fromregion(&region));
a->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
freestruct_ch_a(ARGS_FREESTRUCT) {
dns_rdata_ch_a_t *a = source;
REQUIRE(source != NULL);
REQUIRE(a->common.rdtype == dns_rdatatype_a);
if (a->mctx == NULL)
return;
dns_name_free(&a->ch_addr_dom, a->mctx);
a->mctx = NULL;
}
static inline isc_result_t
additionaldata_ch_a(ARGS_ADDLDATA) {
REQUIRE(rdata->type == dns_rdatatype_a);
REQUIRE(rdata->rdclass == dns_rdataclass_ch);
UNUSED(rdata);
UNUSED(add);
UNUSED(arg);
return (ISC_R_SUCCESS);
}
static inline isc_result_t
digest_ch_a(ARGS_DIGEST) {
isc_region_t r;
dns_name_t name;
REQUIRE(rdata->type == dns_rdatatype_a);
REQUIRE(rdata->rdclass == dns_rdataclass_ch);
dns_rdata_toregion(rdata, &r);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &r);
isc_region_consume(&r, name_length(&name));
RETERR(dns_name_digest(&name, digest, arg));
return ((digest)(arg, &r));
}
static inline isc_boolean_t
checkowner_ch_a(ARGS_CHECKOWNER) {
REQUIRE(type == dns_rdatatype_a);
REQUIRE(rdclass == dns_rdataclass_ch);
UNUSED(type);
return (dns_name_ishostname(name, wildcard));
}
static inline isc_boolean_t
checknames_ch_a(ARGS_CHECKNAMES) {
isc_region_t region;
dns_name_t name;
REQUIRE(rdata->type == dns_rdatatype_a);
REQUIRE(rdata->rdclass == dns_rdataclass_ch);
UNUSED(owner);
dns_rdata_toregion(rdata, &region);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &region);
if (!dns_name_ishostname(&name, ISC_FALSE)) {
if (bad != NULL)
dns_name_clone(&name, bad);
return (ISC_FALSE);
}
return (ISC_TRUE);
}
static inline int
casecompare_ch_a(ARGS_COMPARE) {
return (compare_ch_a(rdata1, rdata2));
}
#endif /* RDATA_CH_3_A_1_C */