Example #1
0
static inline isc_result_t
totext_rt(ARGS_TOTEXT) {
	isc_region_t region;
	dns_name_t name;
	dns_name_t prefix;
	isc_boolean_t sub;
	char buf[sizeof("64000")];
	unsigned short num;

	REQUIRE(rdata->type == dns_rdatatype_rt);
	REQUIRE(rdata->length != 0);

	dns_name_init(&name, NULL);
	dns_name_init(&prefix, NULL);

	dns_rdata_toregion(rdata, &region);
	num = uint16_fromregion(&region);
	isc_region_consume(&region, 2);
	snprintf(buf, sizeof(buf), "%u", num);
	RETERR(str_totext(buf, target));
	RETERR(str_totext(" ", target));
	dns_name_fromregion(&name, &region);
	sub = name_prefix(&name, tctx->origin, &prefix);
	return (dns_name_totext(&prefix, sub, target));
}
Example #2
0
static inline isc_result_t
tostruct_keydata(ARGS_TOSTRUCT) {
	dns_rdata_keydata_t *keydata = target;
	isc_region_t sr;

	REQUIRE(rdata->type == 65533);
	REQUIRE(target != NULL);
	REQUIRE(rdata->length != 0);

	keydata->common.rdclass = rdata->rdclass;
	keydata->common.rdtype = rdata->type;
	ISC_LINK_INIT(&keydata->common, link);

	dns_rdata_toregion(rdata, &sr);

	/* Refresh timer */
	if (sr.length < 4)
		return (ISC_R_UNEXPECTEDEND);
	keydata->refresh = uint32_fromregion(&sr);
	isc_region_consume(&sr, 4);

	/* Add hold-down */
	if (sr.length < 4)
		return (ISC_R_UNEXPECTEDEND);
	keydata->addhd = uint32_fromregion(&sr);
	isc_region_consume(&sr, 4);

	/* Remove hold-down */
	if (sr.length < 4)
		return (ISC_R_UNEXPECTEDEND);
	keydata->removehd = uint32_fromregion(&sr);
	isc_region_consume(&sr, 4);

	/* Flags */
	if (sr.length < 2)
		return (ISC_R_UNEXPECTEDEND);
	keydata->flags = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

	/* Protocol */
	if (sr.length < 1)
		return (ISC_R_UNEXPECTEDEND);
	keydata->protocol = uint8_fromregion(&sr);
	isc_region_consume(&sr, 1);

	/* Algorithm */
	if (sr.length < 1)
		return (ISC_R_UNEXPECTEDEND);
	keydata->algorithm = uint8_fromregion(&sr);
	isc_region_consume(&sr, 1);

	/* Data */
	keydata->datalen = sr.length;
	keydata->data = mem_maybedup(mctx, sr.base, keydata->datalen);
	if (keydata->data == NULL)
		return (ISC_R_NOMEMORY);

	keydata->mctx = mctx;
	return (ISC_R_SUCCESS);
}
Example #3
0
static inline isc_result_t
tostruct_rt(ARGS_TOSTRUCT) {
	isc_region_t region;
	dns_rdata_rt_t *rt = target;
	dns_name_t name;

	REQUIRE(rdata->type == dns_rdatatype_rt);
	REQUIRE(target != NULL);
	REQUIRE(rdata->length != 0);

	rt->common.rdclass = rdata->rdclass;
	rt->common.rdtype = rdata->type;
	ISC_LINK_INIT(&rt->common, link);

	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &region);
	rt->preference = uint16_fromregion(&region);
	isc_region_consume(&region, 2);
	dns_name_fromregion(&name, &region);
	dns_name_init(&rt->host, NULL);
	RETERR(name_duporclone(&name, mctx, &rt->host));

	rt->mctx = mctx;
	return (ISC_R_SUCCESS);
}
Example #4
0
static inline isc_result_t
tostruct_cds(ARGS_TOSTRUCT) {
	dns_rdata_cds_t *ds = target;
	isc_region_t region;

	REQUIRE(rdata->type == 59);
	REQUIRE(target != NULL);
	REQUIRE(rdata->length != 0);

	ds->common.rdclass = rdata->rdclass;
	ds->common.rdtype = rdata->type;
	ISC_LINK_INIT(&ds->common, link);

	dns_rdata_toregion(rdata, &region);

	ds->key_tag = uint16_fromregion(&region);
	isc_region_consume(&region, 2);
	ds->algorithm = uint8_fromregion(&region);
	isc_region_consume(&region, 1);
	ds->digest_type = uint8_fromregion(&region);
	isc_region_consume(&region, 1);
	ds->length = region.length;

	ds->digest = mem_maybedup(mctx, region.base, region.length);
	if (ds->digest == NULL)
		return (ISC_R_NOMEMORY);

	ds->mctx = mctx;
	return (ISC_R_SUCCESS);
}
Example #5
0
static inline isc_result_t
totext_l64(ARGS_TOTEXT) {
	isc_region_t region;
	char buf[sizeof("xxxx:xxxx:xxxx:xxxx")];
	unsigned short num;

	REQUIRE(rdata->type == dns_rdatatype_l64);
	REQUIRE(rdata->length == 10);

	UNUSED(tctx);

	dns_rdata_toregion(rdata, &region);
	num = uint16_fromregion(&region);
	isc_region_consume(&region, 2);
	sprintf(buf, "%u", num);
	RETERR(str_totext(buf, target));

	RETERR(str_totext(" ", target));

	sprintf(buf, "%x:%x:%x:%x",
		region.base[0]<<8 | region.base[1],
		region.base[2]<<8 | region.base[3],
		region.base[4]<<8 | region.base[5],
		region.base[6]<<8 | region.base[7]);
	return (str_totext(buf, target));
}
Example #6
0
static inline isc_result_t
fromstruct_opt(ARGS_FROMSTRUCT) {
	dns_rdata_opt_t *opt = source;
	isc_region_t region;
	isc_uint16_t length;

	REQUIRE(type == 41);
	REQUIRE(source != NULL);
	REQUIRE(opt->common.rdtype == type);
	REQUIRE(opt->common.rdclass == rdclass);
	REQUIRE(opt->options != NULL || opt->length == 0);

	UNUSED(type);
	UNUSED(rdclass);

	region.base = opt->options;
	region.length = opt->length;
	while (region.length >= 4) {
		isc_region_consume(&region, 2);	/* opt */
		length = uint16_fromregion(&region);
		isc_region_consume(&region, 2);
		if (region.length < length)
			return (ISC_R_UNEXPECTEDEND);
		isc_region_consume(&region, length);
	}
	if (region.length != 0)
		return (ISC_R_UNEXPECTEDEND);

	return (mem_tobuffer(target, opt->options, opt->length));
}
Example #7
0
static inline isc_result_t
tostruct_afsdb(ARGS_TOSTRUCT) {
	isc_region_t region;
	dns_rdata_afsdb_t *afsdb = target;
	dns_name_t name;

	REQUIRE(rdata->type == 18);
	REQUIRE(target != NULL);
	REQUIRE(rdata->length != 0);

	afsdb->common.rdclass = rdata->rdclass;
	afsdb->common.rdtype = rdata->type;
	ISC_LINK_INIT(&afsdb->common, link);

	dns_name_init(&afsdb->server, NULL);

	dns_rdata_toregion(rdata, &region);

	afsdb->subtype = uint16_fromregion(&region);
	isc_region_consume(&region, 2);

	dns_name_init(&name, NULL);
	dns_name_fromregion(&name, &region);

	RETERR(name_duporclone(&name, mctx, &afsdb->server));
	afsdb->mctx = mctx;
	return (ISC_R_SUCCESS);
}
Example #8
0
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 == 1);
	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);
}
Example #9
0
static inline isc_result_t
totext_key(ARGS_TOTEXT) {
	isc_region_t sr;
	char buf[sizeof("64000")];
	unsigned int flags;
	unsigned char algorithm;

	REQUIRE(rdata->type == 25);
	REQUIRE(rdata->length != 0);

	dns_rdata_toregion(rdata, &sr);

	/* flags */
	flags = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
	snprintf(buf, sizeof(buf), "%u", flags);
	RETERR(str_totext(buf, target));
	RETERR(str_totext(" ", target));

	/* protocol */
	snprintf(buf, sizeof(buf), "%u", sr.base[0]);
	isc_region_consume(&sr, 1);
	RETERR(str_totext(buf, target));
	RETERR(str_totext(" ", target));

	/* algorithm */
	algorithm = sr.base[0];
	snprintf(buf, sizeof(buf), "%u", algorithm);
	isc_region_consume(&sr, 1);
	RETERR(str_totext(buf, target));

	/* No Key? */
	if ((flags & 0xc000) == 0xc000)
		return (ISC_R_SUCCESS);

	/* key */
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" (", target));
	RETERR(str_totext(tctx->linebreak, target));
	RETERR(isc_base64_totext(&sr, tctx->width - 2,
				 tctx->linebreak, target));

	if ((tctx->flags & DNS_STYLEFLAG_COMMENT) != 0)
		RETERR(str_totext(tctx->linebreak, target));
	else if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" ", target));

	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(")", target));

	if ((tctx->flags & DNS_STYLEFLAG_COMMENT) != 0) {
		isc_region_t tmpr;

		RETERR(str_totext(" ; key id = ", target));
		dns_rdata_toregion(rdata, &tmpr);
		snprintf(buf, sizeof(buf), "%u", dst_region_computeid(&tmpr, algorithm));
		RETERR(str_totext(buf, target));
	}
	return (ISC_R_SUCCESS);
}
Example #10
0
static inline isc_result_t
totext_ch_a(ARGS_TOTEXT) {
	isc_region_t region;
	dns_name_t name;
	dns_name_t prefix;
	isc_boolean_t sub;
	char buf[sizeof("0177777")];
	isc_uint16_t addr;

	REQUIRE(rdata->type == 1);
	REQUIRE(rdata->rdclass == dns_rdataclass_ch); /* 3 */
	REQUIRE(rdata->length != 0);

	dns_name_init(&name, NULL);
	dns_name_init(&prefix, NULL);

	dns_rdata_toregion(rdata, &region);
	dns_name_fromregion(&name, &region);
	isc_region_consume(&region, name_length(&name));
	addr = uint16_fromregion(&region);

	sub = name_prefix(&name, tctx->origin, &prefix);
	RETERR(dns_name_totext(&prefix, sub, target));

	sprintf(buf, "%o", addr); /* note octal */
	RETERR(str_totext(" ", target));
	return (str_totext(buf, target));
}
Example #11
0
static inline isc_result_t
totext_cert(ARGS_TOTEXT) {
	isc_region_t sr;
	char buf[sizeof("64000 ")];
	unsigned int n;

	REQUIRE(rdata->type == 37);
	REQUIRE(rdata->length != 0);

	UNUSED(tctx);

	dns_rdata_toregion(rdata, &sr);

	/*
	 * Type.
	 */
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
	RETERR(dns_cert_totext((dns_cert_t)n, target));
	RETERR(str_totext(" ", target));

	/*
	 * Key tag.
	 */
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
	sprintf(buf, "%u ", n);
	RETERR(str_totext(buf, target));

	/*
	 * Algorithm.
	 */
	RETERR(dns_secalg_totext(sr.base[0], target));
	isc_region_consume(&sr, 1);

	/*
	 * Cert.
	 */
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" (", target));
	RETERR(str_totext(tctx->linebreak, target));
	RETERR(isc_base64_totext(&sr, tctx->width - 2,
				 tctx->linebreak, target));
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" )", target));
	return (ISC_R_SUCCESS);
}
Example #12
0
static inline isc_result_t
tostruct_hip(ARGS_TOSTRUCT) {
	isc_region_t region;
	dns_rdata_hip_t *hip = target;

	REQUIRE(rdata->type == dns_rdatatype_hip);
	REQUIRE(target != NULL);
	REQUIRE(rdata->length != 0);

	hip->common.rdclass = rdata->rdclass;
	hip->common.rdtype = rdata->type;
	ISC_LINK_INIT(&hip->common, link);

	dns_rdata_toregion(rdata, &region);

	hip->hit_len = uint8_fromregion(&region);
	isc_region_consume(&region, 1);

	hip->algorithm = uint8_fromregion(&region);
	isc_region_consume(&region, 1);

	hip->key_len = uint16_fromregion(&region);
	isc_region_consume(&region, 2);

	hip->hit = hip->key = hip->servers = NULL;

	hip->hit = mem_maybedup(mctx, region.base, hip->hit_len);
	if (hip->hit == NULL)
		goto cleanup;
	isc_region_consume(&region, hip->hit_len);

	INSIST(hip->key_len <= region.length);

	hip->key = mem_maybedup(mctx, region.base, hip->key_len);
	if (hip->key == NULL)
		goto cleanup;
	isc_region_consume(&region, hip->key_len);

	hip->servers_len = region.length;
	if (hip->servers_len != 0) {
		hip->servers = mem_maybedup(mctx, region.base, region.length);
		if (hip->servers == NULL)
			goto cleanup;
	}

	hip->offset = hip->servers_len;
	hip->mctx = mctx;
	return (ISC_R_SUCCESS);

 cleanup:
	if (hip->hit != NULL)
		isc_mem_free(mctx, hip->hit);
	if (hip->key != NULL)
		isc_mem_free(mctx, hip->key);
	if (hip->servers != NULL)
		isc_mem_free(mctx, hip->servers);
	return (ISC_R_NOMEMORY);

}
Example #13
0
static inline isc_result_t
totext_opt(ARGS_TOTEXT) {
	isc_region_t r;
	isc_region_t or;
	isc_uint16_t option;
	isc_uint16_t length;
	char buf[sizeof("64000 64000")];

	/*
	 * OPT records do not have a text format.
	 */

	REQUIRE(rdata->type == 41);

	dns_rdata_toregion(rdata, &r);
	while (r.length > 0) {
		option = uint16_fromregion(&r);
		isc_region_consume(&r, 2);
		length = uint16_fromregion(&r);
		isc_region_consume(&r, 2);
		sprintf(buf, "%u %u", option, length);
		RETERR(str_totext(buf, target));
		INSIST(r.length >= length);
		if (length > 0) {
			if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
				RETERR(str_totext(" (", target));
			RETERR(str_totext(tctx->linebreak, target));
			or = r;
			or.length = length;
			if (tctx->width == 0)   /* No splitting */
				RETERR(isc_base64_totext(&or, 60, "", target));
			else
				RETERR(isc_base64_totext(&or, tctx->width - 2,
							 tctx->linebreak,
							 target));
			isc_region_consume(&r, length);
			if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
				RETERR(str_totext(" )", target));
		}
		if (r.length > 0)
			RETERR(str_totext(" ", target));
	}

	return (ISC_R_SUCCESS);
}
Example #14
0
static inline int
casecompare_hip(ARGS_COMPARE) {
	isc_region_t r1;
	isc_region_t r2;
	dns_name_t name1;
	dns_name_t name2;
	int order;
	isc_uint8_t hit_len;
	isc_uint16_t key_len;

	REQUIRE(rdata1->type == rdata2->type);
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
	REQUIRE(rdata1->type == 55);
	REQUIRE(rdata1->length != 0);
	REQUIRE(rdata2->length != 0);

	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);

	INSIST(r1.length > 4);
	INSIST(r2.length > 4);
	r1.length = 4;
	r2.length = 4;
	order = isc_region_compare(&r1, &r2);
	if (order != 0)
		return (order);

	hit_len = uint8_fromregion(&r1);
	isc_region_consume(&r1, 2);         /* hit length + algorithm */
	key_len = uint16_fromregion(&r1);

	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
	isc_region_consume(&r1, 4);
	isc_region_consume(&r2, 4);
	INSIST(r1.length >= (unsigned) (hit_len + key_len));
	INSIST(r2.length >= (unsigned) (hit_len + key_len));
	order = isc_region_compare(&r1, &r2);
	if (order != 0)
		return (order);
	isc_region_consume(&r1, hit_len + key_len);
	isc_region_consume(&r2, hit_len + key_len);

	dns_name_init(&name1, NULL);
	dns_name_init(&name2, NULL);
	while (r1.length != 0 && r2.length != 0) {
		dns_name_fromregion(&name1, &r1);
		dns_name_fromregion(&name2, &r2);
		order = dns_name_rdatacompare(&name1, &name2);
		if (order != 0)
			return (order);

		isc_region_consume(&r1, name_length(&name1));
		isc_region_consume(&r2, name_length(&name2));
	}
	return (isc_region_compare(&r1, &r2));
}
static inline isc_result_t
totext_ds(ARGS_TOTEXT) {
	isc_region_t sr;
	char buf[sizeof("64000 ")];
	unsigned int n;

	REQUIRE(rdata->type == 43);
	REQUIRE(rdata->length != 0);

	UNUSED(tctx);

	dns_rdata_toregion(rdata, &sr);

	/*
	 * Key tag.
	 */
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
	sprintf(buf, "%u ", n);
	RETERR(str_totext(buf, target));

	/*
	 * Algorithm.
	 */
	n = uint8_fromregion(&sr);
	isc_region_consume(&sr, 1);
	sprintf(buf, "%u ", n);
	RETERR(str_totext(buf, target));

	/*
	 * Digest type.
	 */
	n = uint8_fromregion(&sr);
	isc_region_consume(&sr, 1);
	sprintf(buf, "%u", n);
	RETERR(str_totext(buf, target));

	/*
	 * Digest.
	 */
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" (", target));
	RETERR(str_totext(tctx->linebreak, target));
	if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) {
		if (tctx->width == 0) /* No splitting */
			RETERR(isc_hex_totext(&sr, 0, "", target));
		else
			RETERR(isc_hex_totext(&sr, tctx->width - 2,
					      tctx->linebreak, target));
	} else
		RETERR(str_totext("[omitted]", target));
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" )", target));
	return (ISC_R_SUCCESS);
}
Example #16
0
static inline isc_result_t
tostruct_uri(ARGS_TOSTRUCT) {
	dns_rdata_uri_t *uri = target;
	isc_region_t sr;

	REQUIRE(rdata->type == 256);
	REQUIRE(target != NULL);
	REQUIRE(rdata->length != 0);

	uri->common.rdclass = rdata->rdclass;
	uri->common.rdtype = rdata->type;
	ISC_LINK_INIT(&uri->common, link);

	dns_rdata_toregion(rdata, &sr);

	/*
	 * Priority
	 */
	if (sr.length < 2)
		return (ISC_R_UNEXPECTEDEND);
	uri->priority = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

	/*
	 * Weight
	 */
	if (sr.length < 2)
		return (ISC_R_UNEXPECTEDEND);
	uri->weight = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

	/*
	 * Target URI
	 */
	uri->tgt_len = sr.length;
	uri->target = mem_maybedup(mctx, sr.base, sr.length);
	if (uri->target == NULL)
		return (ISC_R_NOMEMORY);

	uri->mctx = mctx;
	return (ISC_R_SUCCESS);
}
Example #17
0
static inline dns_rdatatype_t
covers_sig(dns_rdata_t *rdata) {
	dns_rdatatype_t type;
	isc_region_t r;

	REQUIRE(rdata->type == dns_rdatatype_sig);

	dns_rdata_toregion(rdata, &r);
	type = uint16_fromregion(&r);

	return (type);
}
Example #18
0
static inline isc_result_t
fromwire_in_apl(ARGS_FROMWIRE) {
	isc_region_t sr, sr2;
	isc_region_t tr;
	isc_uint16_t afi;
	isc_uint8_t prefix;
	isc_uint8_t len;

	REQUIRE(type == dns_rdatatype_apl);
	REQUIRE(rdclass == dns_rdataclass_in);

	UNUSED(type);
	UNUSED(dctx);
	UNUSED(rdclass);
	UNUSED(options);

	isc_buffer_activeregion(source, &sr);
	isc_buffer_availableregion(target, &tr);
	if (sr.length > tr.length)
		return (ISC_R_NOSPACE);
	sr2 = sr;

	/* Zero or more items */
	while (sr.length > 0) {
		if (sr.length < 4)
			return (ISC_R_UNEXPECTEDEND);
		afi = uint16_fromregion(&sr);
		isc_region_consume(&sr, 2);
		prefix = *sr.base;
		isc_region_consume(&sr, 1);
		len = (*sr.base & 0x7f);
		isc_region_consume(&sr, 1);
		if (len > sr.length)
			return (ISC_R_UNEXPECTEDEND);
		switch (afi) {
		case 1:
			if (prefix > 32 || len > 4)
				return (ISC_R_RANGE);
			break;
		case 2:
			if (prefix > 128 || len > 16)
				return (ISC_R_RANGE);
		}
		if (len > 0 && sr.base[len - 1] == 0)
			return (DNS_R_FORMERR);
		isc_region_consume(&sr, len);
	}
	isc_buffer_forward(source, sr2.length);
	return (mem_tobuffer(target, sr2.base, sr2.length));
}
Example #19
0
isc_result_t
dns_rdata_opt_current(dns_rdata_opt_t *opt, dns_rdata_opt_opcode_t *opcode) {
	isc_region_t r;

	REQUIRE(opt != NULL);
	REQUIRE(opcode != NULL);
	REQUIRE(opt->common.rdtype == 41);
	REQUIRE(opt->options != NULL);
	REQUIRE(opt->offset < opt->length);

	INSIST(opt->offset + 4 <= opt->length);
	r.base = opt->options + opt->offset;
	r.length = opt->length - opt->offset;

	opcode->opcode = uint16_fromregion(&r);
	isc_region_consume(&r, 2);
	opcode->length = uint16_fromregion(&r);
	isc_region_consume(&r, 2);
	opcode->data = r.base;
	INSIST(opt->offset + 4 + opcode->length <= opt->length);

	return (ISC_R_SUCCESS);
}
Example #20
0
static inline isc_result_t
totext_nsec3param(ARGS_TOTEXT) {
	isc_region_t sr;
	unsigned int i, j;
	unsigned char hash;
	unsigned char flags;
	char buf[sizeof("65535 ")];
	isc_uint32_t iterations;

	REQUIRE(rdata->type == dns_rdatatype_nsec3param);
	REQUIRE(rdata->length != 0);

	UNUSED(tctx);

	dns_rdata_toregion(rdata, &sr);

	hash = uint8_fromregion(&sr);
	isc_region_consume(&sr, 1);

	flags = uint8_fromregion(&sr);
	isc_region_consume(&sr, 1);

	iterations = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

	sprintf(buf, "%u ", hash);
	RETERR(str_totext(buf, target));

	sprintf(buf, "%u ", flags);
	RETERR(str_totext(buf, target));

	sprintf(buf, "%u ", iterations);
	RETERR(str_totext(buf, target));

	j = uint8_fromregion(&sr);
	isc_region_consume(&sr, 1);
	INSIST(j <= sr.length);

	if (j != 0) {
		i = sr.length;
		sr.length = j;
		RETERR(isc_hex_totext(&sr, 1, "", target));
		sr.length = i - j;
	} else
		RETERR(str_totext("-", target));

	return (ISC_R_SUCCESS);
}
Example #21
0
static inline isc_result_t
fromwire_opt(ARGS_FROMWIRE) {
	isc_region_t sregion;
	isc_region_t tregion;
	isc_uint16_t length;
	unsigned int total;

	REQUIRE(type == 41);

	UNUSED(type);
	UNUSED(rdclass);
	UNUSED(dctx);
	UNUSED(options);

	isc_buffer_activeregion(source, &sregion);
	total = 0;
	while (sregion.length != 0) {
		if (sregion.length < 4)
			return (ISC_R_UNEXPECTEDEND);
		/*
		 * Eat the 16bit option code.  There is nothing to
		 * be done with it currently.
		 */
		isc_region_consume(&sregion, 2);
		length = uint16_fromregion(&sregion);
		isc_region_consume(&sregion, 2);
		total += 4;
		if (sregion.length < length)
			return (ISC_R_UNEXPECTEDEND);
		isc_region_consume(&sregion, length);
		total += length;
	}

	isc_buffer_activeregion(source, &sregion);
	isc_buffer_availableregion(target, &tregion);
	if (tregion.length < total)
		return (ISC_R_NOSPACE);
	memcpy(tregion.base, sregion.base, total);
	isc_buffer_forward(source, total);
	isc_buffer_add(target, total);

	return (ISC_R_SUCCESS);
}
Example #22
0
static inline isc_result_t
tostruct_dnskey(ARGS_TOSTRUCT) {
	dns_rdata_dnskey_t *dnskey = target;
	isc_region_t sr;

	REQUIRE(rdata->type == 48);
	REQUIRE(target != NULL);
	REQUIRE(rdata->length != 0);

	dnskey->common.rdclass = rdata->rdclass;
	dnskey->common.rdtype = rdata->type;
	ISC_LINK_INIT(&dnskey->common, link);

	dns_rdata_toregion(rdata, &sr);

	/* Flags */
	if (sr.length < 2)
		return (ISC_R_UNEXPECTEDEND);
	dnskey->flags = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

	/* Protocol */
	if (sr.length < 1)
		return (ISC_R_UNEXPECTEDEND);
	dnskey->protocol = uint8_fromregion(&sr);
	isc_region_consume(&sr, 1);

	/* Algorithm */
	if (sr.length < 1)
		return (ISC_R_UNEXPECTEDEND);
	dnskey->algorithm = uint8_fromregion(&sr);
	isc_region_consume(&sr, 1);

	/* Data */
	dnskey->datalen = sr.length;
	dnskey->data = mem_maybedup(mctx, sr.base, dnskey->datalen);
	if (dnskey->data == NULL)
		return (ISC_R_NOMEMORY);

	dnskey->mctx = mctx;
	return (ISC_R_SUCCESS);
}
Example #23
0
static inline isc_result_t
totext_in_px(ARGS_TOTEXT) {
	isc_region_t region;
	dns_name_t name;
	dns_name_t prefix;
	isc_boolean_t sub;
	char buf[sizeof("64000")];
	unsigned short num;

	REQUIRE(rdata->type == 26);
	REQUIRE(rdata->rdclass == 1);
	REQUIRE(rdata->length != 0);

	dns_name_init(&name, NULL);
	dns_name_init(&prefix, NULL);

	/*
	 * Preference.
	 */
	dns_rdata_toregion(rdata, &region);
	num = uint16_fromregion(&region);
	isc_region_consume(&region, 2);
	sprintf(buf, "%u", num);
	RETERR(str_totext(buf, target));
	RETERR(str_totext(" ", target));

	/*
	 * MAP822.
	 */
	dns_name_fromregion(&name, &region);
	sub = name_prefix(&name, tctx->origin, &prefix);
	isc_region_consume(&region, name_length(&name));
	RETERR(dns_name_totext(&prefix, sub, target));
	RETERR(str_totext(" ", target));

	/*
	 * MAPX400.
	 */
	dns_name_fromregion(&name, &region);
	sub = name_prefix(&name, tctx->origin, &prefix);
	return(dns_name_totext(&prefix, sub, target));
}
Example #24
0
isc_result_t
dns_rdata_opt_next(dns_rdata_opt_t *opt) {
	isc_region_t r;
	isc_uint16_t length;

	REQUIRE(opt != NULL);
	REQUIRE(opt->common.rdtype == 41);
	REQUIRE(opt->options != NULL && opt->length != 0);
	REQUIRE(opt->offset < opt->length);

	INSIST(opt->offset + 4 <= opt->length);
	r.base = opt->options + opt->offset + 2;
	r.length = opt->length - opt->offset - 2;
	length = uint16_fromregion(&r);
	INSIST(opt->offset + 4 + length <= opt->length);
	opt->offset = opt->offset + 4 + length;
	if (opt->offset == opt->length)
		return (ISC_R_NOMORE);
	return (ISC_R_SUCCESS);
}
static inline isc_result_t
tostruct_nid(ARGS_TOSTRUCT) {
	isc_region_t region;
	dns_rdata_nid_t *nid = target;

	REQUIRE(rdata->type == 104);
	REQUIRE(target != NULL);
	REQUIRE(rdata->length == 10);

	UNUSED(mctx);

	nid->common.rdclass = rdata->rdclass;
	nid->common.rdtype = rdata->type;
	ISC_LINK_INIT(&nid->common, link);

	dns_rdata_toregion(rdata, &region);
	nid->pref = uint16_fromregion(&region);
	memmove(nid->nid, region.base, region.length);
	return (ISC_R_SUCCESS);
}
Example #26
0
static inline isc_result_t
tostruct_l64(ARGS_TOSTRUCT) {
	isc_region_t region;
	dns_rdata_l64_t *l64 = target;

	REQUIRE(rdata->type == 106);
	REQUIRE(target != NULL);
	REQUIRE(rdata->length == 10);

	UNUSED(mctx);

	l64->common.rdclass = rdata->rdclass;
	l64->common.rdtype = rdata->type;
	ISC_LINK_INIT(&l64->common, link);

	dns_rdata_toregion(rdata, &region);
	l64->pref = uint16_fromregion(&region);
	memcpy(l64->l64, region.base, region.length);
	return (ISC_R_SUCCESS);
}
Example #27
0
static inline isc_result_t
totext_l32(ARGS_TOTEXT) {
	isc_region_t region;
	char buf[sizeof("65000")];
	unsigned short num;

	REQUIRE(rdata->type == 105);
	REQUIRE(rdata->length == 6);

	UNUSED(tctx);

	dns_rdata_toregion(rdata, &region);
	num = uint16_fromregion(&region);
	isc_region_consume(&region, 2);
	sprintf(buf, "%u", num);
	RETERR(str_totext(buf, target));

	RETERR(str_totext(" ", target));

	return (inet_totext(AF_INET, &region, target));
}
Example #28
0
static inline isc_result_t
tostruct_in_px(ARGS_TOSTRUCT) {
	dns_rdata_in_px_t *px = target;
	dns_name_t name;
	isc_region_t region;
	isc_result_t result;

	REQUIRE(rdata->type == dns_rdatatype_px);
	REQUIRE(rdata->rdclass == dns_rdataclass_in);
	REQUIRE(target != NULL);
	REQUIRE(rdata->length != 0);

	px->common.rdclass = rdata->rdclass;
	px->common.rdtype = rdata->type;
	ISC_LINK_INIT(&px->common, link);

	dns_name_init(&name, NULL);
	dns_rdata_toregion(rdata, &region);

	px->preference = uint16_fromregion(&region);
	isc_region_consume(&region, 2);

	dns_name_fromregion(&name, &region);

	dns_name_init(&px->map822, NULL);
	RETERR(name_duporclone(&name, mctx, &px->map822));
	isc_region_consume(&region, name_length(&px->map822));

	dns_name_init(&px->mapx400, NULL);
	result = name_duporclone(&name, mctx, &px->mapx400);
	if (result != ISC_R_SUCCESS)
		goto cleanup;

	px->mctx = mctx;
	return (result);

 cleanup:
	dns_name_free(&px->map822, mctx);
	return (ISC_R_NOMEMORY);
}
Example #29
0
static inline isc_result_t
tostruct_l32(ARGS_TOSTRUCT) {
	isc_region_t region;
	dns_rdata_l32_t *l32 = target;
	isc_uint32_t n;

	REQUIRE(rdata->type == 105);
	REQUIRE(target != NULL);
	REQUIRE(rdata->length == 6);

	UNUSED(mctx);

	l32->common.rdclass = rdata->rdclass;
	l32->common.rdtype = rdata->type;
	ISC_LINK_INIT(&l32->common, link);

	dns_rdata_toregion(rdata, &region);
	l32->pref = uint16_fromregion(&region);
	n = uint32_fromregion(&region);
	l32->l32.s_addr = htonl(n);
	return (ISC_R_SUCCESS);
}
Example #30
0
static inline isc_result_t
fromwire_hip(ARGS_FROMWIRE) {
	isc_region_t region, rr;
	dns_name_t name;
	isc_uint8_t hit_len;
	isc_uint16_t key_len;

	REQUIRE(type == dns_rdatatype_hip);

	UNUSED(type);
	UNUSED(rdclass);

	isc_buffer_activeregion(source, &region);
	if (region.length < 4U)
		RETERR(DNS_R_FORMERR);

	rr = region;
	hit_len = uint8_fromregion(&region);
	if (hit_len == 0)
		RETERR(DNS_R_FORMERR);
	isc_region_consume(&region, 2);  	/* hit length + algorithm */
	key_len = uint16_fromregion(&region);
	if (key_len == 0)
		RETERR(DNS_R_FORMERR);
	isc_region_consume(&region, 2);
	if (region.length < (unsigned) (hit_len + key_len))
		RETERR(DNS_R_FORMERR);

	RETERR(mem_tobuffer(target, rr.base, 4 + hit_len + key_len));
	isc_buffer_forward(source, 4 + hit_len + key_len);

	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
	while (isc_buffer_activelength(source) > 0) {
		dns_name_init(&name, NULL);
		RETERR(dns_name_fromwire(&name, source, dctx, options, target));
	}
	return (ISC_R_SUCCESS);
}