hinfo_13.c revision 90e303b114e56db5809fdd19805243457fa43cd9
012a352f4b26cfd874db8d06debc495c2303e8b2Bob Halley/*
178f6ad061e54bc5babfca3577f72058fa0797c1Bob Halley * Copyright (C) 1998-2001 Internet Software Consortium.
5c144477062a5df657acee41a82051d38537fd38Tinderbox User *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Permission to use, copy, modify, and distribute this software for any
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * purpose with or without fee is hereby granted, provided that the above
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * copyright notice and this permission notice appear in all copies.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews */
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User/* $Id: hinfo_13.c,v 1.39 2002/01/05 07:05:10 ogud Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt/*
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt * Reviewed: Wed Mar 15 16:47:10 PST 2000 by halley.
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt */
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt#ifndef RDATA_GENERIC_HINFO_13_C
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley#define RDATA_GENERIC_HINFO_13_C
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley#define RRTYPE_HINFO_ATTRIBUTES (0)
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntstatic inline isc_result_t
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyfromtext_hinfo(ARGS_FROMTEXT) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley isc_token_t token;
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley int i;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley UNUSED(type);
c7b785510e3f517a0c98c0b6b6e6ad8f359e9e4cMark Andrews UNUSED(rdclass);
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt UNUSED(origin);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley UNUSED(downcase);
b897c52f865b2fc4e220e2110b874e59c716456bBob Halley UNUSED(callbacks);
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley REQUIRE(type == 13);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt for (i = 0; i < 2; i++) {
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt RETERR(isc_lex_getmastertoken(lexer, &token,
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt isc_tokentype_qstring,
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt ISC_FALSE));
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt RETTOK(txt_fromtext(&token.value.as_textregion, target));
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt }
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt return (ISC_R_SUCCESS);
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt}
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntstatic inline isc_result_t
460b427411b72da26b1836b9424e2e70d65d9394David Lawrencetotext_hinfo(ARGS_TOTEXT) {
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence isc_region_t region;
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews UNUSED(tctx);
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews REQUIRE(rdata->type == 13);
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews REQUIRE(rdata->length != 0);
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews dns_rdata_toregion(rdata, &region);
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence RETERR(txt_totext(&region, target));
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley RETERR(str_totext(" ", target));
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence return (txt_totext(&region, target));
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence}
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrencestatic inline isc_result_t
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrencefromwire_hinfo(ARGS_FROMWIRE) {
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews REQUIRE(type == 13);
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews
12a3ab37fe6556406acdf92fc7c5f198d603ca2eMark Andrews UNUSED(type);
f5cfcbf2f7906fb59c2b8b9b8fc9c7a75ac44dabMark Andrews UNUSED(dctx);
2d46d268ccff30bb50e661b47c6496d23d9156c7Mark Andrews UNUSED(rdclass);
2d46d268ccff30bb50e661b47c6496d23d9156c7Mark Andrews UNUSED(downcase);
dabea86dac4c01f852b7aea728f73b4f55a89d44Mark Andrews
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley RETERR(txt_fromwire(source, target));
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews return (txt_fromwire(source, target));
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence}
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews
460b427411b72da26b1836b9424e2e70d65d9394David Lawrencestatic inline isc_result_t
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrewstowire_hinfo(ARGS_TOWIRE) {
2d9bd38ec3fbbfe920757b8972d94f664a9b354bMark Andrews
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews UNUSED(cctx);
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews REQUIRE(rdata->type == 13);
8319af16557b81eba3277ee67215285f0823b587Mark Andrews REQUIRE(rdata->length != 0);
8319af16557b81eba3277ee67215285f0823b587Mark Andrews
aee5e9cbacd8f88325840b8a498876f4319b0890Mark Andrews return (mem_tobuffer(target, rdata->data, rdata->length));
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews}
9e5854255178c04170bc98839282d4cf3fae7443Mark Andrews
f7a6d4f915ce622d988916397f313b33ae954afcMark Andrewsstatic inline int
f7a6d4f915ce622d988916397f313b33ae954afcMark Andrewscompare_hinfo(ARGS_COMPARE) {
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews isc_region_t r1;
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence isc_region_t r2;
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence REQUIRE(rdata1->type == rdata2->type);
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence REQUIRE(rdata1->rdclass == rdata2->rdclass);
c32b87bc54abacf95fb3b063d72b7d1855c1643bMichael Graff REQUIRE(rdata1->type == 13);
7f9f8c13c5e5e26e0ba2b82c0900d11ecf6269ceMark Andrews REQUIRE(rdata1->length != 0);
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence REQUIRE(rdata2->length != 0);
c3e6fbe4b7471d843d015e3f1737b7edb9d0c547Mark Andrews
c3e6fbe4b7471d843d015e3f1737b7edb9d0c547Mark Andrews dns_rdata_toregion(rdata1, &r1);
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence dns_rdata_toregion(rdata2, &r2);
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence return (isc_region_compare(&r1, &r2));
12e63bfe1d111ccb57f482b28d56c785cccc7cf7David Lawrence}
460b427411b72da26b1836b9424e2e70d65d9394David Lawrence
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrewsstatic inline isc_result_t
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrewsfromstruct_hinfo(ARGS_FROMSTRUCT) {
6376f6189950156cc1488c86f22b19dd4feec11cMark Andrews dns_rdata_hinfo_t *hinfo = source;
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews REQUIRE(type == 13);
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews REQUIRE(source != NULL);
5e47b4200ed81b8e18e165fe3a626d9992003db4Mark Andrews REQUIRE(hinfo->common.rdtype == type);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley REQUIRE(hinfo->common.rdclass == rdclass);
2320f230995995595438a9d9301d84931fd266ceMark Andrews
c427260a8678f2e99a2337fb95ec98d9c9ee8c05Mark Andrews UNUSED(type);
620a452ebe92fff63e85c5930a6e6dc8d9455918Mark Andrews UNUSED(rdclass);
620a452ebe92fff63e85c5930a6e6dc8d9455918Mark Andrews
6dcb47e37f9f0cdb94bdabc3fa157ff07983c590Mark Andrews RETERR(uint8_tobuffer(hinfo->cpu_len, target));
6dcb47e37f9f0cdb94bdabc3fa157ff07983c590Mark Andrews RETERR(mem_tobuffer(target, hinfo->cpu, hinfo->cpu_len));
43b3337ba58d70ca34f4d91e8c6c5e13a54af690Mark Andrews RETERR(uint8_tobuffer(hinfo->os_len, target));
43b3337ba58d70ca34f4d91e8c6c5e13a54af690Mark Andrews return (mem_tobuffer(target, hinfo->os, hinfo->os_len));
f10370fd44f05fecc808d89c01b2d50df2b232f3Mark Andrews}
f10370fd44f05fecc808d89c01b2d50df2b232f3Mark Andrews
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrewsstatic inline isc_result_t
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrewstostruct_hinfo(ARGS_TOSTRUCT) {
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrews dns_rdata_hinfo_t *hinfo = target;
693d70f96fc2b3c1830580edcc29146afd6a9f61Mark Andrews isc_region_t region;
d3347bd01baee56e476982a7443ba18cdbaeebe1Mark Andrews
d3347bd01baee56e476982a7443ba18cdbaeebe1Mark Andrews REQUIRE(rdata->type == 13);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley REQUIRE(target != NULL);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley REQUIRE(rdata->length != 0);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt hinfo->common.rdclass = rdata->rdclass;
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt hinfo->common.rdtype = rdata->type;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley ISC_LINK_INIT(&hinfo->common, link);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley dns_rdata_toregion(rdata, &region);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley hinfo->cpu_len = uint8_fromregion(&region);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley isc_region_consume(&region, 1);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley hinfo->cpu = mem_maybedup(mctx, region.base, hinfo->cpu_len);
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews if (hinfo->cpu == NULL)
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews return (ISC_R_NOMEMORY);
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence isc_region_consume(&region, hinfo->cpu_len);
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrews hinfo->os_len = uint8_fromregion(&region);
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence isc_region_consume(&region, 1);
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrews hinfo->os = mem_maybedup(mctx, region.base, hinfo->os_len);
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrews if (hinfo->os == NULL)
a9558a6c63d9c6dbb2f3800b39ccb008652fcde3Mark Andrews goto cleanup;
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews hinfo->mctx = mctx;
0014d6342b0d50ae37126ac16d5bf821d02ffff7David Lawrence return (ISC_R_SUCCESS);
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt cleanup:
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt if (mctx != NULL && hinfo->cpu != NULL)
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley isc_mem_free(mctx, hinfo->cpu);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley return (ISC_R_NOMEMORY);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley}
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleystatic inline void
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntfreestruct_hinfo(ARGS_FREESTRUCT) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley dns_rdata_hinfo_t *hinfo = source;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley REQUIRE(source != NULL);
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley if (hinfo->mctx == NULL)
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley return;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt if (hinfo->cpu != NULL)
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley isc_mem_free(hinfo->mctx, hinfo->cpu);
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt if (hinfo->os != NULL)
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt isc_mem_free(hinfo->mctx, hinfo->os);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley hinfo->mctx = NULL;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley}
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntstatic inline isc_result_t
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halleyadditionaldata_hinfo(ARGS_ADDLDATA) {
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley REQUIRE(rdata->type == 13);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley UNUSED(add);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley UNUSED(arg);
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt UNUSED(rdata);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley return (ISC_R_SUCCESS);
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley}
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Huntstatic inline isc_result_t
18483fce5b9d1e02748bdcb916014cedea654f78Mark Andrewsdigest_hinfo(ARGS_DIGEST) {
af9dbf1ccdd53933aaae9300d13ce0965d39b067Evan Hunt isc_region_t r;
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley
0b72c791466d0807bcf22522b5ddb7da902c2720Bob Halley REQUIRE(rdata->type == 13);
dns_rdata_toregion(rdata, &r);
return ((digest)(arg, &r));
}
#endif /* RDATA_GENERIC_HINFO_13_C */