ptr_12.c revision 373ce67419680a398ba3dc51a14a486caaf0afb0
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer/*
f3064bfd1b75f7408cff6dbdb864ad62390307d3Mark Andrews * Copyright (C) 1998, 1999, 2000 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * purpose with or without fee is hereby granted, provided that the above
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * copyright notice and this permission notice appear in all copies.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * SOFTWARE.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews/* $Id: ptr_12.c,v 1.27 2000/05/22 12:37:53 marka Exp $ */
47058d17266420179fa294de6b82d8fb5b918df4Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer/* Reviewed: Thu Mar 16 14:05:12 PST 2000 by explorer */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#ifndef RDATA_GENERIC_PTR_12_C
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#define RDATA_GENERIC_PTR_12_C
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#define RRTYPE_PTR_ATTRIBUTES (0)
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic inline isc_result_t
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafssonfromtext_ptr(dns_rdataclass_t rdclass, dns_rdatatype_t type,
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer isc_lex_t *lexer, dns_name_t *origin,
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer isc_boolean_t downcase, isc_buffer_t *target)
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer{
1893b56ef9f5f2bc2a0fbe80d3c6b69df1bdc7c2Michael Sawyer isc_token_t token;
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer dns_name_t name;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_buffer_t buffer;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer UNUSED(rdclass);
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer REQUIRE(type == 12);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer dns_name_init(&name, NULL);
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer buffer_fromregion(&buffer, &token.value.as_region);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer origin = (origin != NULL) ? origin : dns_rootname;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (dns_name_fromtext(&name, &buffer, origin, downcase, target));
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington
fb2c34419d268d36acb222e08e6f789b45a81306Mark Andrewsstatic inline isc_result_t
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellingtontotext_ptr(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_buffer_t *target)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer{
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_region_t region;
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews dns_name_t name;
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews dns_name_t prefix;
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington isc_boolean_t sub;
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington REQUIRE(rdata->type == 12);
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_name_init(&name, NULL);
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington dns_name_init(&prefix, NULL);
688a4c50c2025a683d8d2bf5bb53a591556df4fcAndreas Gustafsson
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyer dns_rdata_toregion(rdata, &region);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_name_fromregion(&name, &region);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer sub = name_prefix(&name, tctx->origin, &prefix);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
da5d1cf1b1aa29ae53a0427be49291b04bd60549Mark Andrews return (dns_name_totext(&prefix, sub, target));
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic inline isc_result_t
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerfromwire_ptr(dns_rdataclass_t rdclass, dns_rdatatype_t type,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_buffer_t *source, dns_decompress_t *dctx,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_boolean_t downcase, isc_buffer_t *target)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer{
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_name_t name;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer UNUSED(rdclass);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer REQUIRE(type == 12);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_init(&name, NULL);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return (dns_name_fromwire(&name, source, dctx, downcase, target));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic inline isc_result_t
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyertowire_ptr(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target)
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington{
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_name_t name;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington isc_region_t region;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington REQUIRE(rdata->type == 12);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_init(&name, NULL);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_rdata_toregion(rdata, &region);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_fromregion(&name, &region);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return (dns_name_towire(&name, cctx, target));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
e32394a2ac3466a2235f79ee32c247a11be42a8dAndreas Gustafssonstatic inline int
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyercompare_ptr(dns_rdata_t *rdata1, dns_rdata_t *rdata2)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer{
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_t name1;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_t name2;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington isc_region_t region1;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington isc_region_t region2;
36c754f274dd439e5a7ebf2401427c1d51b21302Brian Wellington
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington REQUIRE(rdata1->type == rdata2->type);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(rdata1->rdclass == rdata2->rdclass);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(rdata1->type == 12);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_name_init(&name1, NULL);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_init(&name2, NULL);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdata_toregion(rdata1, &region1);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdata_toregion(rdata2, &region2);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_fromregion(&name1, &region1);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_name_fromregion(&name2, &region2);
9a762177e6a0aff3ea5c00f87568c8ae3cd0e6c7Andreas Gustafsson
9a762177e6a0aff3ea5c00f87568c8ae3cd0e6c7Andreas Gustafsson return (dns_name_rdatacompare(&name1, &name2));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
066cb385cd8f801dd3757db2922c9b1f343e65edAndreas Gustafsson
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic inline isc_result_t
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonfromstruct_ptr(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington isc_buffer_t *target)
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington{
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_rdata_ptr_t *ptr = source;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_region_t region;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington REQUIRE(type == 12);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington REQUIRE(source != NULL);
cc48bb397fa6ba889f25157840492e68114dec8fBrian Wellington REQUIRE(ptr->common.rdtype == type);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington REQUIRE(ptr->common.rdclass == rdclass);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington dns_name_toregion(&ptr->ptr, &region);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington return (isc_buffer_copyregion(target, &region));
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington}
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic inline isc_result_t
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyertostruct_ptr(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
cc48bb397fa6ba889f25157840492e68114dec8fBrian Wellington{
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_region_t region;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_rdata_ptr_t *ptr = target;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_name_t name;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington REQUIRE(rdata->type == 12);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington REQUIRE(target != NULL);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington ptr->common.rdclass = rdata->rdclass;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington ptr->common.rdtype = rdata->type;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington ISC_LINK_INIT(&ptr->common, link);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
c38b92000c0f1a95daaad5468777e165b8047de9Mark Andrews dns_name_init(&name, NULL);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_rdata_toregion(rdata, &region);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_name_fromregion(&name, &region);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_name_init(&ptr->ptr, NULL);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington RETERR(name_duporclone(&name, mctx, &ptr->ptr));
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington ptr->mctx = mctx;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington return (ISC_R_SUCCESS);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington}
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellingtonstatic inline void
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellingtonfreestruct_ptr(void *source)
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington{
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_rdata_ptr_t *ptr = source;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington REQUIRE(source != NULL);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington REQUIRE(ptr->common.rdtype == 12);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington if (ptr->mctx == NULL)
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington return;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_name_free(&ptr->ptr, ptr->mctx);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington ptr->mctx = NULL;
2a23a625246acfbf6ff92b86a6b8b9df59dbeaa4Mark Andrews}
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrewsstatic inline isc_result_t
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrewsadditionaldata_ptr(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews void *arg)
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews{
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews REQUIRE(rdata->type == 12);
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews UNUSED(rdata);
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews UNUSED(add);
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews UNUSED(arg);
1ae75c1024eb0475c2be352b8707772e16332ad0Mark Andrews
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington return (ISC_R_SUCCESS);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington}
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellingtonstatic inline isc_result_t
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellingtondigest_ptr(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg)
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington{
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington isc_region_t r;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_name_t name;
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington REQUIRE(rdata->type == 12);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_rdata_toregion(rdata, &r);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_name_init(&name, NULL);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington dns_name_fromregion(&name, &r);
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington return (dns_name_digest(&name, digest, arg));
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington}
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington#endif /* RDATA_GENERIC_PTR_12_C */
e56101fa6876c876d9957c23784b6493cdb05e09Brian Wellington