e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews/*
a134177ed9f82189504191d90f3ed9e97c2b47cbTinderbox User * Copyright (C) 2009, 2011, 2013-2017 Internet Systems Consortium, Inc. ("ISC")
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
9cee5bb02863bf191e12cd4297adabf1971020deAutomatic Updater/* $Id: hip_55.c,v 1.8 2011/01/13 04:59:26 tbox Exp $ */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews/* reviewed: TBC */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews/* RFC 5205 */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews#ifndef RDATA_GENERIC_HIP_5_C
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews#define RDATA_GENERIC_HIP_5_C
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews#define RRTYPE_HIP_ATTRIBUTES (0)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline isc_result_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsfromtext_hip(ARGS_FROMTEXT) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_token_t token;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_name_t name;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_buffer_t buffer;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_buffer_t hit_len;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_buffer_t key_len;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews unsigned char *start;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews size_t len;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(type);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(rdclass);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(callbacks);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Dummy HIT len.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hit_len = *target;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(uint8_tobuffer(0, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Algorithm.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews ISC_FALSE));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (token.value.as_ulong > 0xffU)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETTOK(ISC_R_RANGE);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(uint8_tobuffer(token.value.as_ulong, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Dummy KEY len.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews key_len = *target;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(uint16_tobuffer(0, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * HIT (base16).
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews start = isc_buffer_used(target);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews ISC_FALSE));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETTOK(isc_hex_decodestring(DNS_AS_STR(token), target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Fill in HIT len.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews len = (unsigned char *)isc_buffer_used(target) - start;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (len > 0xffU)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETTOK(ISC_R_RANGE);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews RETERR(uint8_tobuffer((isc_uint32_t)len, &hit_len));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Public key (base64).
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews start = isc_buffer_used(target);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews ISC_FALSE));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETTOK(isc_base64_decodestring(DNS_AS_STR(token), target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Fill in KEY len.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews len = (unsigned char *)isc_buffer_used(target) - start;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (len > 0xffffU)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETTOK(ISC_R_RANGE);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews RETERR(uint16_tobuffer((isc_uint32_t)len, &key_len));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e0a30050c8516a3d54a4f8dcdd88435704a8a3edMark Andrews if (origin == NULL)
e0a30050c8516a3d54a4f8dcdd88435704a8a3edMark Andrews origin = dns_rootname;
e0a30050c8516a3d54a4f8dcdd88435704a8a3edMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Rendezvous Servers.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_name_init(&name, NULL);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews do {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(isc_lex_getmastertoken(lexer, &token,
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_tokentype_string,
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews ISC_TRUE));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (token.type != isc_tokentype_string)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews break;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews buffer_fromregion(&buffer, &token.value.as_region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETTOK(dns_name_fromtext(&name, &buffer, origin, options,
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews } while (1);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Let upper layer handle eol/eof.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_lex_ungettoken(lexer, &token);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_R_SUCCESS);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline isc_result_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewstotext_hip(ARGS_TOTEXT) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_t region;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_name_t name;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews unsigned int length, key_len, hit_len;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews unsigned char algorithm;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews char buf[sizeof("225 ")];
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(rdata->length != 0);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_rdata_toregion(rdata, &region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hit_len = uint8_fromregion(&region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(&region, 1);
92e4603c55532dc87558a0e0426ad5225ac2ca5dAutomatic Updater
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews algorithm = uint8_fromregion(&region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(&region, 1);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews key_len = uint16_fromregion(&region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(&region, 2);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(str_totext("( ", target));
92e4603c55532dc87558a0e0426ad5225ac2ca5dAutomatic Updater
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Algorithm
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf), "%u ", algorithm);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(str_totext(buf, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * HIT.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews INSIST(hit_len < region.length);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews length = region.length;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews region.length = hit_len;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(isc_hex_totext(&region, 1, "", target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews region.length = length - hit_len;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(str_totext(tctx->linebreak, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Public KEY.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews INSIST(key_len <= region.length);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews length = region.length;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews region.length = key_len;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(isc_base64_totext(&region, 1, "", target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews region.length = length - key_len;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(str_totext(tctx->linebreak, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /*
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Rendezvous Servers.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_name_init(&name, NULL);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews while (region.length > 0) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_name_fromregion(&name, &region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
38b84a1fcfdbda4d1d0fdca409004ae83be2ace8Mark Andrews RETERR(dns_name_totext(&name, ISC_FALSE, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(&region, name.length);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (region.length > 0)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(str_totext(tctx->linebreak, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews }
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(str_totext(" )", target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_R_SUCCESS);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline isc_result_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsfromwire_hip(ARGS_FROMWIRE) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_t region, rr;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_name_t name;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_uint8_t hit_len;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_uint16_t key_len;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(type);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(rdclass);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_buffer_activeregion(source, &region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (region.length < 4U)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(DNS_R_FORMERR);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews rr = region;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hit_len = uint8_fromregion(&region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hit_len == 0)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(DNS_R_FORMERR);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(&region, 2); /* hit length + algorithm */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews key_len = uint16_fromregion(&region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (key_len == 0)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(DNS_R_FORMERR);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(&region, 2);
e7c38ca9635e73c9a928bbab9c73c2abbd499f8bEvan Hunt if (region.length < (unsigned) (hit_len + key_len))
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(DNS_R_FORMERR);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(mem_tobuffer(target, rr.base, 4 + hit_len + key_len));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_buffer_forward(source, 4 + hit_len + key_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews while (isc_buffer_activelength(source) > 0) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_name_init(&name, NULL);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(dns_name_fromwire(&name, source, dctx, options, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews }
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_R_SUCCESS);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline isc_result_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewstowire_hip(ARGS_TOWIRE) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_t region;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(rdata->length != 0);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(cctx);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_rdata_toregion(rdata, &region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (mem_tobuffer(target, region.base, region.length));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline int
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewscompare_hip(ARGS_COMPARE) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_t region1;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_t region2;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(rdata1->type == rdata2->type);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(rdata1->rdclass == rdata2->rdclass);
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata1->type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(rdata1->length != 0);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(rdata2->length != 0);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_rdata_toregion(rdata1, &region1);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_rdata_toregion(rdata2, &region2);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (isc_region_compare(&region1, &region2));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline isc_result_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsfromstruct_hip(ARGS_FROMSTRUCT) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_rdata_hip_t *hip = source;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_rdata_hip_t myhip;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_result_t result;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(source != NULL);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(hip->common.rdtype == type);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(hip->common.rdclass == rdclass);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(hip->hit_len > 0 && hip->hit != NULL);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(hip->key_len > 0 && hip->key != NULL);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE((hip->servers == NULL && hip->servers_len == 0) ||
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews (hip->servers != NULL && hip->servers_len != 0));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(type);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(rdclass);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(uint8_tobuffer(hip->hit_len, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(uint8_tobuffer(hip->algorithm, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(uint16_tobuffer(hip->key_len, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(mem_tobuffer(target, hip->hit, hip->hit_len));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(mem_tobuffer(target, hip->key, hip->key_len));
92e4603c55532dc87558a0e0426ad5225ac2ca5dAutomatic Updater
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews myhip = *hip;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews for (result = dns_rdata_hip_first(&myhip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews result == ISC_R_SUCCESS;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews result = dns_rdata_hip_next(&myhip))
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /* empty */;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return(mem_tobuffer(target, hip->servers, hip->servers_len));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline isc_result_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewstostruct_hip(ARGS_TOSTRUCT) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_t region;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_rdata_hip_t *hip = target;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(target != NULL);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(rdata->length != 0);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->common.rdclass = rdata->rdclass;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->common.rdtype = rdata->type;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews ISC_LINK_INIT(&hip->common, link);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_rdata_toregion(rdata, &region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->hit_len = uint8_fromregion(&region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(&region, 1);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->algorithm = uint8_fromregion(&region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(&region, 1);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->key_len = uint16_fromregion(&region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(&region, 2);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->hit = hip->key = hip->servers = NULL;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->hit = mem_maybedup(mctx, region.base, hip->hit_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hip->hit == NULL)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews goto cleanup;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(&region, hip->hit_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
23fe5cbb07535b4b6dbb93d62af164ece50f2d0bMark Andrews INSIST(hip->key_len <= region.length);
23fe5cbb07535b4b6dbb93d62af164ece50f2d0bMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->key = mem_maybedup(mctx, region.base, hip->key_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hip->key == NULL)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews goto cleanup;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(&region, hip->key_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->servers_len = region.length;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hip->servers_len != 0) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->servers = mem_maybedup(mctx, region.base, region.length);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hip->servers == NULL)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews goto cleanup;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews }
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->offset = hip->servers_len;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->mctx = mctx;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_R_SUCCESS);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews cleanup:
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hip->hit != NULL)
92e4603c55532dc87558a0e0426ad5225ac2ca5dAutomatic Updater isc_mem_free(mctx, hip->hit);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hip->key != NULL)
92e4603c55532dc87558a0e0426ad5225ac2ca5dAutomatic Updater isc_mem_free(mctx, hip->key);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hip->servers != NULL)
92e4603c55532dc87558a0e0426ad5225ac2ca5dAutomatic Updater isc_mem_free(mctx, hip->servers);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_R_NOMEMORY);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline void
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsfreestruct_hip(ARGS_FREESTRUCT) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_rdata_hip_t *hip = source;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(source != NULL);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hip->mctx == NULL)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
92e4603c55532dc87558a0e0426ad5225ac2ca5dAutomatic Updater isc_mem_free(hip->mctx, hip->hit);
92e4603c55532dc87558a0e0426ad5225ac2ca5dAutomatic Updater isc_mem_free(hip->mctx, hip->key);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hip->servers != NULL)
92e4603c55532dc87558a0e0426ad5225ac2ca5dAutomatic Updater isc_mem_free(hip->mctx, hip->servers);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->mctx = NULL;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline isc_result_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsadditionaldata_hip(ARGS_ADDLDATA) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(rdata);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(add);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(arg);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_R_SUCCESS);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline isc_result_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsdigest_hip(ARGS_DIGEST) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_t r;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_rdata_toregion(rdata, &r);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return ((digest)(arg, &r));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline isc_boolean_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewscheckowner_hip(ARGS_CHECKOWNER) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(name);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(type);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(rdclass);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(wildcard);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_TRUE);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline isc_boolean_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewschecknames_hip(ARGS_CHECKNAMES) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(rdata);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(owner);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews UNUSED(bad);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_TRUE);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsisc_result_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsdns_rdata_hip_first(dns_rdata_hip_t *hip) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hip->servers_len == 0)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_R_NOMORE);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->offset = 0;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_R_SUCCESS);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsisc_result_t
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsdns_rdata_hip_next(dns_rdata_hip_t *hip) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_t region;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_name_t name;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if (hip->offset >= hip->servers_len)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_R_NOMORE);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews region.base = hip->servers + hip->offset;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews region.length = hip->servers_len - hip->offset;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_name_init(&name, NULL);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_name_fromregion(&name, &region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->offset += name.length;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews INSIST(hip->offset <= hip->servers_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (ISC_R_SUCCESS);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsvoid
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsdns_rdata_hip_current(dns_rdata_hip_t *hip, dns_name_t *name) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_t region;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE(hip->offset < hip->servers_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews region.base = hip->servers + hip->offset;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews region.length = hip->servers_len - hip->offset;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_name_fromregion(name, &region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews INSIST(name->length + hip->offset <= hip->servers_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews}
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewsstatic inline int
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewscasecompare_hip(ARGS_COMPARE) {
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater isc_region_t r1;
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater isc_region_t r2;
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater dns_name_t name1;
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater dns_name_t name2;
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater int order;
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews isc_uint8_t hit_len;
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews isc_uint16_t key_len;
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater REQUIRE(rdata1->type == rdata2->type);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater REQUIRE(rdata1->rdclass == rdata2->rdclass);
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata1->type == dns_rdatatype_hip);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater REQUIRE(rdata1->length != 0);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater REQUIRE(rdata2->length != 0);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater dns_rdata_toregion(rdata1, &r1);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater dns_rdata_toregion(rdata2, &r2);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater INSIST(r1.length > 4);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater INSIST(r2.length > 4);
0c2313eb367de3b58801d643d52c0fd9bc0e5df7Evan Hunt order = memcmp(r1.base, r2.base, 4);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater if (order != 0)
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater return (order);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater hit_len = uint8_fromregion(&r1);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater isc_region_consume(&r1, 2); /* hit length + algorithm */
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater key_len = uint16_fromregion(&r1);
0c2313eb367de3b58801d643d52c0fd9bc0e5df7Evan Hunt isc_region_consume(&r1, 2); /* key length */
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater isc_region_consume(&r2, 4);
0c2313eb367de3b58801d643d52c0fd9bc0e5df7Evan Hunt
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater INSIST(r1.length >= (unsigned) (hit_len + key_len));
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater INSIST(r2.length >= (unsigned) (hit_len + key_len));
0c2313eb367de3b58801d643d52c0fd9bc0e5df7Evan Hunt order = memcmp(r1.base, r2.base, hit_len + key_len);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater if (order != 0)
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater return (order);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater isc_region_consume(&r1, hit_len + key_len);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater isc_region_consume(&r2, hit_len + key_len);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater dns_name_init(&name1, NULL);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater dns_name_init(&name2, NULL);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews while (r1.length != 0 && r2.length != 0) {
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews dns_name_fromregion(&name1, &r1);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews dns_name_fromregion(&name2, &r2);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews order = dns_name_rdatacompare(&name1, &name2);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews if (order != 0)
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews return (order);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews isc_region_consume(&r1, name_length(&name1));
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews isc_region_consume(&r2, name_length(&name2));
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews }
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater return (isc_region_compare(&r1, &r2));
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews}
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews#endif /* RDATA_GENERIC_HIP_5_C */