ptr_12.c revision 419590499823ce15b5d2ad4fe71eaf04bd5a86c0
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley/*
5fec28507abad910acf4afa3efa1e634acab6d9eAutomatic Updater * Copyright (C) 1998, 1999, 2000 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley * copyright notice and this permission notice appear in all copies.
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley *
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.
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley */
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halley
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id: ptr_12.c,v 1.21 2000/04/06 22:03:08 explorer Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
e419f613d8591885df608cb73065921be07dd12eBob Halley/* Reviewed: Thu Mar 16 14:05:12 PST 2000 by explorer */
e419f613d8591885df608cb73065921be07dd12eBob Halley
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#ifndef RDATA_GENERIC_PTR_12_C
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#define RDATA_GENERIC_PTR_12_C
fca5f81ad69098ea8abba130c7f841c951ef91c2Bob Halley
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic inline isc_result_t
519b239fc4ef1e070e2da182a4ea559ae0152151Mark Andrewsfromtext_ptr(dns_rdataclass_t rdclass, dns_rdatatype_t type,
e419f613d8591885df608cb73065921be07dd12eBob Halley isc_lex_t *lexer, dns_name_t *origin,
e419f613d8591885df608cb73065921be07dd12eBob Halley isc_boolean_t downcase, isc_buffer_t *target)
9695ae1c24b168996e3a267855dc754971ccb32cBob Halley{
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley isc_token_t token;
1c776a2909632bc755f3fddd3b53addd792ab4d0Brian Wellington dns_name_t name;
44f175a90a855326725439b2f1178f0dcca8f67dMark Andrews isc_buffer_t buffer;
e419f613d8591885df608cb73065921be07dd12eBob Halley
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley UNUSED(rdclass);
44f175a90a855326725439b2f1178f0dcca8f67dMark Andrews
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson REQUIRE(type == 12);
e83cae7fa837e4757c687035d6f6c0900f152749Brian Wellington
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_name_init(&name, NULL);
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley buffer_fromregion(&buffer, &token.value.as_region,
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley ISC_BUFFERTYPE_TEXT);
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence origin = (origin != NULL) ? origin : dns_rootname;
b5debbe212097d1c573a2ba3bd9a3d526d86b0aeBrian Wellington return (dns_name_fromtext(&name, &buffer, origin, downcase, target));
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence}
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence
e419f613d8591885df608cb73065921be07dd12eBob Halleystatic inline isc_result_t
e419f613d8591885df608cb73065921be07dd12eBob Halleytotext_ptr(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews isc_buffer_t *target)
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews{
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews isc_region_t region;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_name_t name;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_name_t prefix;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews isc_boolean_t sub;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews REQUIRE(rdata->type == 12);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater dns_name_init(&name, NULL);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_name_init(&prefix, NULL);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_rdata_toregion(rdata, &region);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_name_fromregion(&name, &region);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews sub = name_prefix(&name, tctx->origin, &prefix);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews return (dns_name_totext(&prefix, sub, target));
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews}
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrewsstatic inline isc_result_t
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrewsfromwire_ptr(dns_rdataclass_t rdclass, dns_rdatatype_t type,
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews isc_buffer_t *source, dns_decompress_t *dctx,
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews isc_boolean_t downcase, isc_buffer_t *target)
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews{
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_name_t name;
d2ef84e07b67e72a4bd9c729c6b8228067d17584Mark Andrews
d2ef84e07b67e72a4bd9c729c6b8228067d17584Mark Andrews UNUSED(rdclass);
d2ef84e07b67e72a4bd9c729c6b8228067d17584Mark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews REQUIRE(type == 12);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews if (dns_decompress_edns(dctx) >= 1 || !dns_decompress_strict(dctx))
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_decompress_setmethods(dctx, DNS_COMPRESS_ALL);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews else
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_name_init(&name, NULL);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews return (dns_name_fromwire(&name, source, dctx, downcase, target));
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews}
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence
ff30cdeb783ca7ffe69b222c56197828e882c229Mark Andrewsstatic inline isc_result_t
bf43fdafa3bff9e84cb03f1a19aca74514d2516eBob Halleytowire_ptr(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target)
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews{
708383382ff1d3fdd27527e5d63120a3c6c6d3b3Francis Dupont dns_name_t name;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews isc_region_t region;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews REQUIRE(rdata->type == 12);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews if (dns_compress_getedns(cctx) >= 1)
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_compress_setmethods(cctx, DNS_COMPRESS_ALL);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews else
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_name_init(&name, NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdata_toregion(rdata, &region);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews dns_name_fromregion(&name, &region);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews return (dns_name_towire(&name, cctx, target));
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic inline int
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewscompare_ptr(dns_rdata_t *rdata1, dns_rdata_t *rdata2)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews{
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_name_t name1;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_name_t name2;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_region_t region1;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_region_t region2;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews REQUIRE(rdata1->type == rdata2->type);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews REQUIRE(rdata1->rdclass == rdata2->rdclass);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews REQUIRE(rdata1->type == 12);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews dns_name_init(&name1, NULL);
50105afc551903541608b11851d73278b23579a3Mark Andrews dns_name_init(&name2, NULL);
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews dns_rdata_toregion(rdata1, &region1);
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews dns_rdata_toregion(rdata2, &region2);
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews dns_name_fromregion(&name1, &region1);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews dns_name_fromregion(&name2, &region2);
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley
e2c3f8059e77a8e11c4378d22e5d8e78b423a28fMark Andrews return (dns_name_rdatacompare(&name1, &name2));
0ec4b862c9abd11c82c88ed62438f0cf06fed25dBob Halley}
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Huntstatic inline isc_result_t
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrencefromstruct_ptr(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews isc_buffer_t *target)
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence{
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington UNUSED(rdclass);
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews UNUSED(source);
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence UNUSED(target);
ca9af3aaf798f98624fc1dc69d8c7d51bf01334dBrian Wellington
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington REQUIRE(type == 12);
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence return (ISC_R_NOTIMPLEMENTED);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews}
50105afc551903541608b11851d73278b23579a3Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrewsstatic inline isc_result_t
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellingtontostruct_ptr(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews{
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence UNUSED(target);
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington UNUSED(mctx);
664e11f0b14c78cef7cf6b8c70323a1da494e351Mark Andrews
664e11f0b14c78cef7cf6b8c70323a1da494e351Mark Andrews REQUIRE(rdata->type == 12);
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington return (ISC_R_NOTIMPLEMENTED);
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington}
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellington
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellingtonstatic inline void
23e4260821eefa5019808e18e14e2b366461aad7Brian Wellingtonfreestruct_ptr(void *source)
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence{
8462dfb880040cde3a60f047ec18808737fd7e85Mark Andrews REQUIRE(source != NULL);
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson REQUIRE(ISC_FALSE);
1b1e1fda4638334b484aa38c15f53a131c0b0fdfAndreas Gustafsson}
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrewsstatic inline isc_result_t
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrewsadditionaldata_ptr(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews void *arg)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews{
50105afc551903541608b11851d73278b23579a3Mark Andrews UNUSED(add);
50105afc551903541608b11851d73278b23579a3Mark Andrews UNUSED(arg);
50105afc551903541608b11851d73278b23579a3Mark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews REQUIRE(rdata->type == 12);
5be3685b0e57677c0cc03113099cb8f99f9a070bMark Andrews
5be3685b0e57677c0cc03113099cb8f99f9a070bMark Andrews return (ISC_R_SUCCESS);
6fac7ff1f9ec9c3873d3b55c5079fa79aba1f146Mark Andrews}
6fac7ff1f9ec9c3873d3b55c5079fa79aba1f146Mark Andrews
6fac7ff1f9ec9c3873d3b55c5079fa79aba1f146Mark Andrewsstatic inline isc_result_t
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrewsdigest_ptr(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg)
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews{
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews isc_region_t r;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_name_t name;
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews REQUIRE(rdata->type == 12);
5be3685b0e57677c0cc03113099cb8f99f9a070bMark Andrews
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews dns_rdata_toregion(rdata, &r);
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews dns_name_init(&name, NULL);
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews dns_name_fromregion(&name, &r);
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews
60ab03125c137c48a6b2ed6df1d2c8657757e09dMark Andrews return (dns_name_digest(&name, digest, arg));
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews}
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews#endif /* RDATA_GENERIC_PTR_12_C */
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews