ipseckey_45.c revision 431a83fb29482c5170b3e4026e59bb14849a6707
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff/*
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Copyright (C) 2005, 2007, 2009, 2011, 2012, 2014 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Permission to use, copy, modify, and/or distribute this software for any
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * purpose with or without fee is hereby granted, provided that the above
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
15a44745412679c30a6d022733925af70a38b715David Lawrence * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15a44745412679c30a6d022733925af70a38b715David Lawrence * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15a44745412679c30a6d022733925af70a38b715David Lawrence * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15a44745412679c30a6d022733925af70a38b715David Lawrence * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PERFORMANCE OF THIS SOFTWARE.
15a44745412679c30a6d022733925af70a38b715David Lawrence */
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff/* $Id$ */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence#ifndef RDATA_GENERIC_IPSECKEY_45_C
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff#define RDATA_GENERIC_IPSECKEY_45_C
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff#include <string.h>
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff#include <isc/net.h>
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff#define RRTYPE_IPSECKEY_ATTRIBUTES (0)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffstatic inline isc_result_t
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Grafffromtext_ipseckey(ARGS_FROMTEXT) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_token_t token;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff dns_name_t name;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_buffer_t buffer;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff unsigned int gateway;
b81306ccd14066cb7378f7f74bbf3843b5a88985Michael Graff struct in_addr addr;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff unsigned char addr6[16];
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff isc_region_t region;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff REQUIRE(type == 45);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff UNUSED(type);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff UNUSED(rdclass);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff UNUSED(callbacks);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff /*
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff * Precedence.
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff */
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
7a166c5c61a5aaa6eeb929bed152dc0a6b128e3dMichael Graff ISC_FALSE));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff if (token.value.as_ulong > 0xffU)
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff RETTOK(ISC_R_RANGE);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETERR(uint8_tobuffer(token.value.as_ulong, target));
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff /*
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Gateway type.
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff */
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff ISC_FALSE));
58ff88cca7c169f7fbebc9b6e93bbba1fb345157Michael Graff if (token.value.as_ulong > 0x3U)
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff RETTOK(ISC_R_RANGE);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff RETERR(uint8_tobuffer(token.value.as_ulong, target));
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff gateway = token.value.as_ulong;
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff /*
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff * Algorithm.
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff */
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ISC_FALSE));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff if (token.value.as_ulong > 0xffU)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETTOK(ISC_R_RANGE);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETERR(uint8_tobuffer(token.value.as_ulong, target));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff /*
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Gateway.
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff */
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ISC_FALSE));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff switch (gateway) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff case 0:
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff if (strcmp(DNS_AS_STR(token), ".") != 0)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETTOK(DNS_R_SYNTAX);
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff break;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff case 1:
b81306ccd14066cb7378f7f74bbf3843b5a88985Michael Graff if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETTOK(DNS_R_BADDOTTEDQUAD);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff isc_buffer_availableregion(target, &region);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff if (region.length < 4)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (ISC_R_NOSPACE);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff memmove(region.base, &addr, 4);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_buffer_add(target, 4);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff break;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff case 2:
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff if (inet_pton(AF_INET6, DNS_AS_STR(token), addr6) != 1)
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff RETTOK(DNS_R_BADAAAA);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_buffer_availableregion(target, &region);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff if (region.length < 16)
7a166c5c61a5aaa6eeb929bed152dc0a6b128e3dMichael Graff return (ISC_R_NOSPACE);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff memmove(region.base, addr6, 16);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff isc_buffer_add(target, 16);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff break;
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff case 3:
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff dns_name_init(&name, NULL);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff buffer_fromregion(&buffer, &token.value.as_region);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff origin = (origin != NULL) ? origin : dns_rootname;
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff RETTOK(dns_name_fromtext(&name, &buffer, origin,
58ff88cca7c169f7fbebc9b6e93bbba1fb345157Michael Graff options, target));
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff break;
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff }
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff /*
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff * Public key.
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff */
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (isc_base64_tobuffer(lexer, target, -1));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff}
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffstatic inline isc_result_t
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Grafftotext_ipseckey(ARGS_TOTEXT) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_region_t region;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff dns_name_t name;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff char buf[sizeof("255 ")];
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff unsigned short num;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff unsigned short gateway;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff REQUIRE(rdata->type == 45);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff REQUIRE(rdata->length >= 3);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff dns_name_init(&name, NULL);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff if (rdata->data[1] > 3U)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (ISC_R_NOTIMPLEMENTED);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
b81306ccd14066cb7378f7f74bbf3843b5a88985Michael Graff if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETERR(str_totext("( ", target));
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff /*
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Precedence.
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff */
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff dns_rdata_toregion(rdata, &region);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff num = uint8_fromregion(&region);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_region_consume(&region, 1);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff sprintf(buf, "%u ", num);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff RETERR(str_totext(buf, target));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
58ff88cca7c169f7fbebc9b6e93bbba1fb345157Michael Graff /*
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff * Gateway type.
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff */
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff gateway = uint8_fromregion(&region);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff isc_region_consume(&region, 1);
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff sprintf(buf, "%u ", gateway);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff RETERR(str_totext(buf, target));
7a166c5c61a5aaa6eeb929bed152dc0a6b128e3dMichael Graff
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff /*
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff * Algorithm.
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff */
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff num = uint8_fromregion(&region);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff isc_region_consume(&region, 1);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff sprintf(buf, "%u ", num);
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff RETERR(str_totext(buf, target));
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff /*
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff * Gateway.
28dff2287e42c8b83eda2abb95667b4596dc994bMichael Graff */
28dff2287e42c8b83eda2abb95667b4596dc994bMichael Graff switch (gateway) {
28dff2287e42c8b83eda2abb95667b4596dc994bMichael Graff case 0:
031ce3bc62d273c5bd99596e01aa95c7ed33bbd7Brian Wellington RETERR(str_totext(".", target));
28dff2287e42c8b83eda2abb95667b4596dc994bMichael Graff break;
28dff2287e42c8b83eda2abb95667b4596dc994bMichael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff case 1:
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff RETERR(inet_totext(AF_INET, &region, target));
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff isc_region_consume(&region, 4);
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff break;
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff case 2:
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff RETERR(inet_totext(AF_INET6, &region, target));
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff isc_region_consume(&region, 16);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff break;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff case 3:
b81306ccd14066cb7378f7f74bbf3843b5a88985Michael Graff dns_name_fromregion(&name, &region);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff RETERR(dns_name_totext(&name, ISC_FALSE, target));
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff isc_region_consume(&region, name_length(&name));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff break;
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff }
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff /*
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Key.
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff */
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff if (region.length > 0U) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETERR(str_totext(tctx->linebreak, target));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff if (tctx->width == 0) /* No splitting */
58ff88cca7c169f7fbebc9b6e93bbba1fb345157Michael Graff RETERR(isc_base64_totext(&region, 60, "", target));
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff else
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff RETERR(isc_base64_totext(&region, tctx->width - 2,
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff tctx->linebreak, target));
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff }
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
7a166c5c61a5aaa6eeb929bed152dc0a6b128e3dMichael Graff RETERR(str_totext(" )", target));
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff return (ISC_R_SUCCESS);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff}
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graffstatic inline isc_result_t
658db10162f779c8a5ed4e40c77111a7e18492beMichael Grafffromwire_ipseckey(ARGS_FROMWIRE) {
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff dns_name_t name;
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff isc_region_t region;
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff REQUIRE(type == 45);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff UNUSED(type);
28dff2287e42c8b83eda2abb95667b4596dc994bMichael Graff UNUSED(rdclass);
28dff2287e42c8b83eda2abb95667b4596dc994bMichael Graff
031ce3bc62d273c5bd99596e01aa95c7ed33bbd7Brian Wellington dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
28dff2287e42c8b83eda2abb95667b4596dc994bMichael Graff
28dff2287e42c8b83eda2abb95667b4596dc994bMichael Graff dns_name_init(&name, NULL);
28dff2287e42c8b83eda2abb95667b4596dc994bMichael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff isc_buffer_activeregion(source, &region);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff if (region.length < 3)
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff return (ISC_R_UNEXPECTEDEND);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff switch (region.base[1]) {
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff case 0:
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff isc_buffer_forward(source, region.length);
658db10162f779c8a5ed4e40c77111a7e18492beMichael Graff return (mem_tobuffer(target, region.base, region.length));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff case 1:
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff if (region.length < 7)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (ISC_R_UNEXPECTEDEND);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_buffer_forward(source, region.length);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (mem_tobuffer(target, region.base, region.length));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff case 2:
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff if (region.length < 19)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (ISC_R_UNEXPECTEDEND);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_buffer_forward(source, region.length);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (mem_tobuffer(target, region.base, region.length));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff case 3:
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETERR(mem_tobuffer(target, region.base, 3));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_buffer_forward(source, 3);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RETERR(dns_name_fromwire(&name, source, dctx, options, target));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_buffer_activeregion(source, &region);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_buffer_forward(source, region.length);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return(mem_tobuffer(target, region.base, region.length));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff default:
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (ISC_R_NOTIMPLEMENTED);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff }
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff}
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffstatic inline isc_result_t
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Grafftowire_ipseckey(ARGS_TOWIRE) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_region_t region;
REQUIRE(rdata->type == 45);
REQUIRE(rdata->length != 0);
UNUSED(cctx);
dns_rdata_toregion(rdata, &region);
return (mem_tobuffer(target, region.base, region.length));
}
static inline int
compare_ipseckey(ARGS_COMPARE) {
isc_region_t region1;
isc_region_t region2;
REQUIRE(rdata1->type == rdata2->type);
REQUIRE(rdata1->rdclass == rdata2->rdclass);
REQUIRE(rdata1->type == 45);
REQUIRE(rdata1->length >= 3);
REQUIRE(rdata2->length >= 3);
dns_rdata_toregion(rdata1, &region1);
dns_rdata_toregion(rdata2, &region2);
return (isc_region_compare(&region1, &region2));
}
static inline isc_result_t
fromstruct_ipseckey(ARGS_FROMSTRUCT) {
dns_rdata_ipseckey_t *ipseckey = source;
isc_region_t region;
isc_uint32_t n;
REQUIRE(type == 45);
REQUIRE(source != NULL);
REQUIRE(ipseckey->common.rdtype == type);
REQUIRE(ipseckey->common.rdclass == rdclass);
UNUSED(type);
UNUSED(rdclass);
if (ipseckey->gateway_type > 3U)
return (ISC_R_NOTIMPLEMENTED);
RETERR(uint8_tobuffer(ipseckey->precedence, target));
RETERR(uint8_tobuffer(ipseckey->gateway_type, target));
RETERR(uint8_tobuffer(ipseckey->algorithm, target));
switch (ipseckey->gateway_type) {
case 0:
break;
case 1:
n = ntohl(ipseckey->in_addr.s_addr);
RETERR(uint32_tobuffer(n, target));
break;
case 2:
RETERR(mem_tobuffer(target, ipseckey->in6_addr.s6_addr, 16));
break;
case 3:
dns_name_toregion(&ipseckey->gateway, &region);
RETERR(isc_buffer_copyregion(target, &region));
break;
}
return (mem_tobuffer(target, ipseckey->key, ipseckey->keylength));
}
static inline isc_result_t
tostruct_ipseckey(ARGS_TOSTRUCT) {
isc_region_t region;
dns_rdata_ipseckey_t *ipseckey = target;
dns_name_t name;
isc_uint32_t n;
REQUIRE(rdata->type == 45);
REQUIRE(target != NULL);
REQUIRE(rdata->length >= 3);
if (rdata->data[1] > 3U)
return (ISC_R_NOTIMPLEMENTED);
ipseckey->common.rdclass = rdata->rdclass;
ipseckey->common.rdtype = rdata->type;
ISC_LINK_INIT(&ipseckey->common, link);
dns_name_init(&name, NULL);
dns_rdata_toregion(rdata, &region);
ipseckey->precedence = uint8_fromregion(&region);
isc_region_consume(&region, 1);
ipseckey->gateway_type = uint8_fromregion(&region);
isc_region_consume(&region, 1);
ipseckey->algorithm = uint8_fromregion(&region);
isc_region_consume(&region, 1);
switch (ipseckey->gateway_type) {
case 0:
break;
case 1:
n = uint32_fromregion(&region);
ipseckey->in_addr.s_addr = htonl(n);
isc_region_consume(&region, 4);
break;
case 2:
memmove(ipseckey->in6_addr.s6_addr, region.base, 16);
isc_region_consume(&region, 16);
break;
case 3:
dns_name_init(&ipseckey->gateway, NULL);
dns_name_fromregion(&name, &region);
RETERR(name_duporclone(&name, mctx, &ipseckey->gateway));
isc_region_consume(&region, name_length(&name));
break;
}
ipseckey->keylength = region.length;
if (ipseckey->keylength != 0U) {
ipseckey->key = mem_maybedup(mctx, region.base,
ipseckey->keylength);
if (ipseckey->key == NULL) {
if (ipseckey->gateway_type == 3)
dns_name_free(&ipseckey->gateway,
ipseckey->mctx);
return (ISC_R_NOMEMORY);
}
} else
ipseckey->key = NULL;
ipseckey->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
freestruct_ipseckey(ARGS_FREESTRUCT) {
dns_rdata_ipseckey_t *ipseckey = source;
REQUIRE(source != NULL);
REQUIRE(ipseckey->common.rdtype == 45);
if (ipseckey->mctx == NULL)
return;
if (ipseckey->gateway_type == 3)
dns_name_free(&ipseckey->gateway, ipseckey->mctx);
if (ipseckey->key != NULL)
isc_mem_free(ipseckey->mctx, ipseckey->key);
ipseckey->mctx = NULL;
}
static inline isc_result_t
additionaldata_ipseckey(ARGS_ADDLDATA) {
REQUIRE(rdata->type == 45);
UNUSED(rdata);
UNUSED(add);
UNUSED(arg);
return (ISC_R_SUCCESS);
}
static inline isc_result_t
digest_ipseckey(ARGS_DIGEST) {
isc_region_t region;
REQUIRE(rdata->type == 45);
dns_rdata_toregion(rdata, &region);
return ((digest)(arg, &region));
}
static inline isc_boolean_t
checkowner_ipseckey(ARGS_CHECKOWNER) {
REQUIRE(type == 45);
UNUSED(name);
UNUSED(type);
UNUSED(rdclass);
UNUSED(wildcard);
return (ISC_TRUE);
}
static inline isc_boolean_t
checknames_ipseckey(ARGS_CHECKNAMES) {
REQUIRE(rdata->type == 45);
UNUSED(rdata);
UNUSED(owner);
UNUSED(bad);
return (ISC_TRUE);
}
static inline int
casecompare_ipseckey(ARGS_COMPARE) {
isc_region_t region1;
isc_region_t region2;
dns_name_t name1;
dns_name_t name2;
int order;
REQUIRE(rdata1->type == rdata2->type);
REQUIRE(rdata1->rdclass == rdata2->rdclass);
REQUIRE(rdata1->type == 45);
REQUIRE(rdata1->length >= 3);
REQUIRE(rdata2->length >= 3);
dns_rdata_toregion(rdata1, &region1);
dns_rdata_toregion(rdata2, &region2);
if (memcmp(region1.base, region2.base, 3) != 0 || region1.base[1] != 3)
return (isc_region_compare(&region1, &region2));
dns_name_init(&name1, NULL);
dns_name_init(&name2, NULL);
isc_region_consume(&region1, 3);
isc_region_consume(&region2, 3);
dns_name_fromregion(&name1, &region1);
dns_name_fromregion(&name2, &region2);
order = dns_name_rdatacompare(&name1, &name2);
if (order != 0)
return (order);
isc_region_consume(&region1, name_length(&name1));
isc_region_consume(&region2, name_length(&name2));
return (isc_region_compare(&region1, &region2));
}
#endif /* RDATA_GENERIC_IPSECKEY_45_C */