a_1.c revision 330705066b03f6ce0bc08a4bbfc5d2418038c68d
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews/*
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 1999-2001 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews * Permission to use, copy, modify, and distribute this software for any
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews * purpose with or without fee is hereby granted, provided that the above
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
15a44745412679c30a6d022733925af70a38b715David Lawrence * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15a44745412679c30a6d022733925af70a38b715David Lawrence * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15a44745412679c30a6d022733925af70a38b715David Lawrence * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews */
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington/* $Id: a_1.c,v 1.22 2001/01/25 20:14:38 bwelling Exp $ */
cd30495b0ca83a04d4d8f56728e38f93769aee98James Brister
cd30495b0ca83a04d4d8f56728e38f93769aee98James Brister/* reviewed: Thu Mar 16 15:58:36 PST 2000 by brister */
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews#ifndef RDATA_HS_4_A_1_C
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews#define RDATA_HS_4_A_1_C
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews#include <isc/net.h>
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff#define RRTYPE_A_ATTRIBUTES (0)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromtext_hs_a(ARGS_FROMTEXT) {
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_token_t token;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews struct in_addr addr;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_region_t region;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(type == 1);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdclass == 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
cd30495b0ca83a04d4d8f56728e38f93769aee98James Brister UNUSED(origin);
cd30495b0ca83a04d4d8f56728e38f93769aee98James Brister UNUSED(downcase);
63cef8bde8b92aeb30ccdcf21d4e44c9be9cc6e3Andreas Gustafsson UNUSED(rdclass);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews if (inet_aton(token.value.as_pointer, &addr) != 1)
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews return (DNS_R_BADDOTTEDQUAD);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &region);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews if (region.length < 4)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews memcpy(region.base, &addr, 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_buffer_add(target, 4);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetotext_hs_a(ARGS_TOTEXT) {
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_region_t region;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata->type == 1);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata->rdclass == 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata->length == 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
cd30495b0ca83a04d4d8f56728e38f93769aee98James Brister UNUSED(tctx);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington dns_rdata_toregion(rdata, &region);
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington return (inet_totext(AF_INET, &region, target));
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromwire_hs_a(ARGS_FROMWIRE) {
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_region_t sregion;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_region_t tregion;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(type == 1);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdclass == 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
cd30495b0ca83a04d4d8f56728e38f93769aee98James Brister UNUSED(dctx);
cd30495b0ca83a04d4d8f56728e38f93769aee98James Brister UNUSED(downcase);
63cef8bde8b92aeb30ccdcf21d4e44c9be9cc6e3Andreas Gustafsson UNUSED(rdclass);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_activeregion(source, &sregion);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tregion);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews if (sregion.length < 4)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDEND);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews if (tregion.length < 4)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews memcpy(tregion.base, sregion.base, 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_buffer_forward(source, 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_buffer_add(target, 4);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetowire_hs_a(ARGS_TOWIRE) {
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_region_t region;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata->type == 1);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata->rdclass == 4);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata->length == 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
cd30495b0ca83a04d4d8f56728e38f93769aee98James Brister UNUSED(cctx);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &region);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews if (region.length < rdata->length)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews memcpy(region.base, rdata->data, rdata->length);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_buffer_add(target, 4);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewsstatic inline int
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencecompare_hs_a(ARGS_COMPARE) {
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson int order;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata1->type == rdata2->type);
37a8fbab3a1fe6d513b767118cba7515152c2b9bBrian Wellington REQUIRE(rdata1->rdclass == rdata2->rdclass);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata1->type == 1);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata1->rdclass == 4);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata1->length == 4);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata2->length == 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson order = memcmp(rdata1->data, rdata2->data, 4);
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson if (order != 0)
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson order = (order < 0) ? -1 : 1;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson return (order);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromstruct_hs_a(ARGS_FROMSTRUCT) {
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews dns_rdata_hs_a_t *a = source;
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews isc_uint32_t n;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(type == 1);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdclass == 4);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(source != NULL);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(a->common.rdtype == type);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(a->common.rdclass == rdclass);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
63cef8bde8b92aeb30ccdcf21d4e44c9be9cc6e3Andreas Gustafsson UNUSED(rdclass);
63cef8bde8b92aeb30ccdcf21d4e44c9be9cc6e3Andreas Gustafsson
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews n = ntohl(a->in_addr.s_addr);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews return (uint32_tobuffer(n, target));
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetostruct_hs_a(ARGS_TOSTRUCT) {
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews dns_rdata_hs_a_t *a = target;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_uint32_t n;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_region_t region;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata->type == 1);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata->rdclass == 4);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata->length == 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
cd30495b0ca83a04d4d8f56728e38f93769aee98James Brister UNUSED(mctx);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews a->common.rdclass = rdata->rdclass;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews a->common.rdtype = rdata->type;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews ISC_LINK_INIT(&a->common, link);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews dns_rdata_toregion(rdata, &region);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews n = uint32_fromregion(&region);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews a->in_addr.s_addr = htonl(n);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrewsstatic inline void
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefreestruct_hs_a(ARGS_FREESTRUCT) {
90f9d00f087ddb4442d1ebf628c1bcaff18226a0Andreas Gustafsson UNUSED(source);
90f9d00f087ddb4442d1ebf628c1bcaff18226a0Andreas Gustafsson
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(source != NULL);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceadditionaldata_hs_a(ARGS_ADDLDATA) {
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata->type == 1);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata->rdclass == 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson UNUSED(rdata);
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson UNUSED(add);
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson UNUSED(arg);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencedigest_hs_a(ARGS_DIGEST) {
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews isc_region_t r;
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata->type == 1);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews REQUIRE(rdata->rdclass == 4);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews dns_rdata_toregion(rdata, &r);
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews return ((digest)(arg, &r));
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews}
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews
db725ebe2b5d913949246b02573df01bd29f5412Mark Andrews#endif /* RDATA_HS_4_A_1_C */