5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
74e2f784928d6d5e4897174b21dd35d5a5ab53faTinderbox User * Copyright (C) 1998-2017 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
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/.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id$ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <config.h>
de153390f5a1f6d4fa86af91d4cae772d9846ca0Mark Andrews#include <ctype.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff
822f6cdabb1edd44472c7a758b5cae71376fa9beBrian Wellington#include <isc/base64.h>
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington#include <isc/hex.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <isc/lex.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/mem.h>
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson#include <isc/parseint.h>
25a66b4e41e2b0a2af4840749bac80ae78c678bfMark Andrews#include <isc/print.h>
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence#include <isc/string.h>
21f1794606dce19928cf455029e173321f166380Mark Andrews#include <isc/stdlib.h>
973a19342597823f111fce6a8cd5adfd0e2e7c0dMark Andrews#include <isc/util.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/callbacks.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/cert.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/compress.h>
058e44186b74531402c1f99088eb9dbe4926f8daMark Andrews#include <dns/dsdigest.h>
28b863e609ff2d97b78663b46894494cfa2ea411Mark Andrews#include <dns/enumtype.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/keyflags.h>
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington#include <dns/keyvalues.h>
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉#include <dns/message.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/rcode.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <dns/rdata.h>
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews#include <dns/rdataclass.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/rdatastruct.h>
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews#include <dns/rdatatype.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/result.h>
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews#include <dns/secalg.h>
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson#include <dns/secproto.h>
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#include <dns/time.h>
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#include <dns/ttl.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews#define RETERR(x) \
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews do { \
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews isc_result_t _r = (x); \
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews if (_r != ISC_R_SUCCESS) \
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews return (_r); \
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews } while (0)
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews#define RETTOK(x) \
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews do { \
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews isc_result_t _r = (x); \
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews if (_r != ISC_R_SUCCESS) { \
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews isc_lex_ungettoken(lexer, &token); \
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews return (_r); \
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews } \
eb6bd543c7d072efdca509eb17f8f301c1467b53Mark Andrews } while (0)
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews#define CHECK(op) \
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews do { result = (op); \
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews if (result != ISC_R_SUCCESS) goto cleanup; \
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews } while (0)
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews#define CHECKTOK(op) \
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews do { result = (op); \
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews if (result != ISC_R_SUCCESS) { \
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews isc_lex_ungettoken(lexer, &token); \
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews goto cleanup; \
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews } \
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews } while (0)
82a50a619afa73ae9a212399505b9f1b327128cdMark Andrews
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews#define DNS_AS_STR(t) ((t).value.as_textregion.base)
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence#define ARGS_FROMTEXT int rdclass, dns_rdatatype_t type, \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence isc_lex_t *lexer, dns_name_t *origin, \
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews unsigned int options, isc_buffer_t *target, \
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews dns_rdatacallbacks_t *callbacks
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define ARGS_TOTEXT dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence isc_buffer_t *target
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence#define ARGS_FROMWIRE int rdclass, dns_rdatatype_t type, \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence isc_buffer_t *source, dns_decompress_t *dctx, \
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews unsigned int options, isc_buffer_t *target
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define ARGS_TOWIRE dns_rdata_t *rdata, dns_compress_t *cctx, \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence isc_buffer_t *target
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define ARGS_COMPARE const dns_rdata_t *rdata1, const dns_rdata_t *rdata2
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence#define ARGS_FROMSTRUCT int rdclass, dns_rdatatype_t type, \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence void *source, isc_buffer_t *target
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define ARGS_TOSTRUCT dns_rdata_t *rdata, void *target, isc_mem_t *mctx
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define ARGS_FREESTRUCT void *source
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define ARGS_ADDLDATA dns_rdata_t *rdata, dns_additionaldatafunc_t add, \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence void *arg
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define ARGS_DIGEST dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews#define ARGS_CHECKOWNER dns_name_t *name, dns_rdataclass_t rdclass, \
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_rdatatype_t type, isc_boolean_t wildcard
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews#define ARGS_CHECKNAMES dns_rdata_t *rdata, dns_name_t *owner, dns_name_t *bad
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Context structure for the totext_ functions.
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * Contains formatting options for rdata-to-text
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * conversion.
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafssontypedef struct dns_rdata_textctx {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_name_t *origin; /*%< Current origin, or NULL. */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein unsigned int flags; /*%< DNS_STYLEFLAG_* */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein unsigned int width; /*%< Width of rdata column. */
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater const char *linebreak; /*%< Line break string. */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson} dns_rdata_textctx_t;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
2383eb527269d333df4222da20e4b422c3662daaEvan Hunttxt_totext(isc_region_t *source, isc_boolean_t quote, isc_buffer_t *target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencetxt_fromtext(isc_textregion_t *source, isc_buffer_t *target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencetxt_fromwire(isc_buffer_t *source, isc_buffer_t *target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupontstatic isc_result_t
7712d1660a308ec3de17f1ddbbf801eb0d663f3eEvan Huntmultitxt_totext(isc_region_t *source, isc_buffer_t *target);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupontstatic isc_result_t
7712d1660a308ec3de17f1ddbbf801eb0d663f3eEvan Huntmultitxt_fromtext(isc_textregion_t *source, isc_buffer_t *target);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_boolean_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencename_prefix(dns_name_t *name, dns_name_t *origin, dns_name_t *target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic unsigned int
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencename_length(dns_name_t *name);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencestr_totext(const char *source, isc_buffer_t *target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellingtonstatic isc_result_t
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellingtoninet_totext(int af, isc_region_t *src, isc_buffer_t *target);
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_boolean_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencebuffer_empty(isc_buffer_t *source);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic void
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencebuffer_fromregion(isc_buffer_t *buffer, isc_region_t *region);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceuint32_tobuffer(isc_uint32_t, isc_buffer_t *target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceuint16_tobuffer(isc_uint32_t, isc_buffer_t *target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceuint8_tobuffer(isc_uint32_t, isc_buffer_t *target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencename_tobuffer(dns_name_t *name, isc_buffer_t *target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_uint32_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceuint32_fromregion(isc_region_t *region);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_uint16_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceuint16_fromregion(isc_region_t *region);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_uint8_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceuint8_fromregion(isc_region_t *region);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic isc_uint8_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsuint8_consume_fromregion(isc_region_t *region);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencemem_tobuffer(isc_buffer_t *target, void *base, unsigned int length);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic int
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencehexvalue(char value);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic int
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedecvalue(char value);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencebtoa_totext(unsigned char *inbuf, int inbuflen, isc_buffer_t *target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceatob_tobuffer(isc_lex_t *lexer, isc_buffer_t *target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic void
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafssondefault_fromtext_callback(dns_rdatacallbacks_t *callbacks, const char *, ...)
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson ISC_FORMAT_PRINTF(2, 3);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic void
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromtext_error(void (*callback)(dns_rdatacallbacks_t *, const char *, ...),
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence dns_rdatacallbacks_t *callbacks, const char *name,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence unsigned long line, isc_token_t *token, isc_result_t result);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrewsstatic void
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrewsfromtext_warneof(isc_lex_t *lexer, dns_rdatacallbacks_t *callbacks);
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencerdata_totext(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_buffer_t *target);
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsstatic void
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewswarn_badname(dns_name_t *name, isc_lex_t *lexer,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_rdatacallbacks_t *callbacks);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsstatic void
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewswarn_badmx(isc_token_t *token, isc_lex_t *lexer,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_rdatacallbacks_t *callbacks);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic isc_uint16_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsuint16_consume_fromregion(isc_region_t *region);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrewsstatic isc_result_t
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrewsunknown_totext(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews isc_buffer_t *target);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsstatic inline isc_result_t
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsgeneric_fromtext_key(ARGS_FROMTEXT);
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrews
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsstatic inline isc_result_t
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsgeneric_totext_key(ARGS_TOTEXT);
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrews
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsstatic inline isc_result_t
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsgeneric_fromwire_key(ARGS_FROMWIRE);
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrews
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsstatic inline isc_result_t
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsgeneric_fromstruct_key(ARGS_FROMSTRUCT);
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrews
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsstatic inline isc_result_t
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsgeneric_tostruct_key(ARGS_TOSTRUCT);
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrews
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsstatic inline void
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrewsgeneric_freestruct_key(ARGS_FREESTRUCT);
8b29fc0b7a13db404f1a13fcfad42c2e7cfbe25bMark Andrews
63874956de9673be49d4a75484514836dd27e6edMark Andrewsstatic isc_result_t
63874956de9673be49d4a75484514836dd27e6edMark Andrewsgeneric_fromtext_txt(ARGS_FROMTEXT);
63874956de9673be49d4a75484514836dd27e6edMark Andrews
63874956de9673be49d4a75484514836dd27e6edMark Andrewsstatic isc_result_t
63874956de9673be49d4a75484514836dd27e6edMark Andrewsgeneric_totext_txt(ARGS_TOTEXT);
63874956de9673be49d4a75484514836dd27e6edMark Andrews
63874956de9673be49d4a75484514836dd27e6edMark Andrewsstatic isc_result_t
63874956de9673be49d4a75484514836dd27e6edMark Andrewsgeneric_fromwire_txt(ARGS_FROMWIRE);
63874956de9673be49d4a75484514836dd27e6edMark Andrews
63874956de9673be49d4a75484514836dd27e6edMark Andrewsstatic isc_result_t
63874956de9673be49d4a75484514836dd27e6edMark Andrewsgeneric_fromstruct_txt(ARGS_FROMSTRUCT);
63874956de9673be49d4a75484514836dd27e6edMark Andrews
63874956de9673be49d4a75484514836dd27e6edMark Andrewsstatic isc_result_t
63874956de9673be49d4a75484514836dd27e6edMark Andrewsgeneric_tostruct_txt(ARGS_TOSTRUCT);
63874956de9673be49d4a75484514836dd27e6edMark Andrews
63874956de9673be49d4a75484514836dd27e6edMark Andrewsstatic void
63874956de9673be49d4a75484514836dd27e6edMark Andrewsgeneric_freestruct_txt(ARGS_FREESTRUCT);
63874956de9673be49d4a75484514836dd27e6edMark Andrews
63874956de9673be49d4a75484514836dd27e6edMark Andrewsstatic isc_result_t
63874956de9673be49d4a75484514836dd27e6edMark Andrewsgeneric_txt_first(dns_rdata_txt_t *txt);
63874956de9673be49d4a75484514836dd27e6edMark Andrews
63874956de9673be49d4a75484514836dd27e6edMark Andrewsstatic isc_result_t
63874956de9673be49d4a75484514836dd27e6edMark Andrewsgeneric_txt_next(dns_rdata_txt_t *txt);
63874956de9673be49d4a75484514836dd27e6edMark Andrews
63874956de9673be49d4a75484514836dd27e6edMark Andrewsstatic isc_result_t
63874956de9673be49d4a75484514836dd27e6edMark Andrewsgeneric_txt_current(dns_rdata_txt_t *txt, dns_rdata_txt_string_t *string);
63874956de9673be49d4a75484514836dd27e6edMark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsstatic isc_result_t
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsgeneric_totext_ds(ARGS_TOTEXT);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsstatic isc_result_t
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsgeneric_tostruct_ds(ARGS_TOSTRUCT);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsstatic isc_result_t
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsgeneric_fromtext_ds(ARGS_FROMTEXT);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsstatic isc_result_t
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsgeneric_fromwire_ds(ARGS_FROMWIRE);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsstatic isc_result_t
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrewsgeneric_fromstruct_ds(ARGS_FROMSTRUCT);
3dd63ba00f91f4d54ba45ba1831375950758c0a7Mark Andrews
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsstatic isc_result_t
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsgeneric_fromtext_tlsa(ARGS_FROMTEXT);
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrews
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsstatic isc_result_t
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsgeneric_totext_tlsa(ARGS_TOTEXT);
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrews
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsstatic isc_result_t
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsgeneric_fromwire_tlsa(ARGS_FROMWIRE);
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrews
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsstatic isc_result_t
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsgeneric_fromstruct_tlsa(ARGS_FROMSTRUCT);
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrews
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsstatic isc_result_t
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsgeneric_tostruct_tlsa(ARGS_TOSTRUCT);
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrews
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsstatic void
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrewsgeneric_freestruct_tlsa(ARGS_FREESTRUCT);
322e6b5be784d79d15fea9db9440dd821162c574Mark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews/*% INT16 Size */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define NS_INT16SZ 2
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews/*% IPv6 Address Size */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define NS_LOCATORSZ 8
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
dc3912f3caac1104fef441fd18571b7a975708eaMark Andrews/*
dc3912f3caac1104fef441fd18571b7a975708eaMark Andrews * Active Diretory gc._msdcs.<forest> prefix.
dc3912f3caac1104fef441fd18571b7a975708eaMark Andrews */
dc3912f3caac1104fef441fd18571b7a975708eaMark Andrewsstatic unsigned char gc_msdcs_data[] = "\002gc\006_msdcs";
dc3912f3caac1104fef441fd18571b7a975708eaMark Andrewsstatic unsigned char gc_msdcs_offset [] = { 0, 3 };
dc3912f3caac1104fef441fd18571b7a975708eaMark Andrews
3ed16e796dba90c96933c8a8a3f5b9404d8d3e61Mark Andrewsstatic dns_name_t const gc_msdcs =
3ed16e796dba90c96933c8a8a3f5b9404d8d3e61Mark Andrews DNS_NAME_INITNONABSOLUTE(gc_msdcs_data, gc_msdcs_offset);
dc3912f3caac1104fef441fd18571b7a975708eaMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews/*%
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * convert presentation level address to network order binary form.
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * \return
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * \note
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews * (1) does not touch `dst' unless it's returning 1.
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline int
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewslocator_pton(const char *src, unsigned char *dst) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews static const char xdigits_l[] = "0123456789abcdef",
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews xdigits_u[] = "0123456789ABCDEF";
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews unsigned char tmp[NS_LOCATORSZ];
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews unsigned char *tp = tmp, *endp;
6a528eaa09b6eed63144250dc61062f3a84880abMark Andrews const char *xdigits;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews int ch, seen_xdigits;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews unsigned int val;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews memset(tp, '\0', NS_LOCATORSZ);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews endp = tp + NS_LOCATORSZ;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews seen_xdigits = 0;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews val = 0;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews while ((ch = *src++) != '\0') {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews const char *pch;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews pch = strchr((xdigits = xdigits_l), ch);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (pch == NULL)
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews pch = strchr((xdigits = xdigits_u), ch);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (pch != NULL) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews val <<= 4;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews val |= (pch - xdigits);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (++seen_xdigits > 4)
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (0);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews continue;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews }
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (ch == ':') {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (!seen_xdigits)
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (0);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (tp + NS_INT16SZ > endp)
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (0);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews *tp++ = (unsigned char) (val >> 8) & 0xff;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews *tp++ = (unsigned char) val & 0xff;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews seen_xdigits = 0;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews val = 0;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews continue;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews }
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (0);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews }
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (seen_xdigits) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (tp + NS_INT16SZ > endp)
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (0);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews *tp++ = (unsigned char) (val >> 8) & 0xff;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews *tp++ = (unsigned char) val & 0xff;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews }
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (tp != endp)
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (0);
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(dst, tmp, NS_LOCATORSZ);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (1);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrewsstatic inline int
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrewsgetquad(const void *src, struct in_addr *dst,
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews isc_lex_t *lexer, dns_rdatacallbacks_t *callbacks)
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews{
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews int result;
3e4480ae34229a69b6a0c0541b445aba4a80dc74Mark Andrews struct in_addr tmp;
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews result = inet_aton(src, dst);
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews if (result == 1 && callbacks != NULL &&
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews inet_pton(AF_INET, src, &tmp) != 1) {
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews const char *name = isc_lex_getsourcename(lexer);
b6a0341bcb113e93bd0bc41a9f9a1fc117444da6Mark Andrews if (name == NULL)
b6a0341bcb113e93bd0bc41a9f9a1fc117444da6Mark Andrews name = "UNKNOWN";
aa05bbdef7f7827dde158dcc913f4dade84c8511Brian Wellington (*callbacks->warn)(callbacks, "%s:%lu: \"%s\" "
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews "is not a decimal dotted quad", name,
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews isc_lex_getsourceline(lexer), src);
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews }
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews return (result);
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews}
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsstatic inline isc_result_t
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsname_duporclone(dns_name_t *source, isc_mem_t *mctx, dns_name_t *target) {
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews if (mctx != NULL)
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington return (dns_name_dup(source, mctx, target));
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews dns_name_clone(source, target);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews return (ISC_R_SUCCESS);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews}
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsstatic inline void *
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsmem_maybedup(isc_mem_t *mctx, void *source, size_t length) {
d4422ec231e58b60693620cf298276e47f04f0ecMark Andrews void *copy;
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews if (mctx == NULL)
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews return (source);
d4422ec231e58b60693620cf298276e47f04f0ecMark Andrews copy = isc_mem_allocate(mctx, length);
d4422ec231e58b60693620cf298276e47f04f0ecMark Andrews if (copy != NULL)
d4422ec231e58b60693620cf298276e47f04f0ecMark Andrews memmove(copy, source, length);
f6407f9a0b890bebbfd5f738d9c4aef3d3315fe9Michael Graff
d4422ec231e58b60693620cf298276e47f04f0ecMark Andrews return (copy);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews}
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrewsstatic inline isc_result_t
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrewstypemap_fromtext(isc_lex_t *lexer, isc_buffer_t *target,
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews isc_boolean_t allow_empty)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews{
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews isc_token_t token;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews unsigned char bm[8*1024]; /* 64k bits */
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman dns_rdatatype_t covered, max_used;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews int octet;
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman unsigned int max_octet, newend, end;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews int window;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews isc_boolean_t first = ISC_TRUE;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman max_used = 0;
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman bm[0] = 0;
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman end = 0;
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews do {
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(isc_lex_getmastertoken(lexer, &token,
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews isc_tokentype_string, ISC_TRUE));
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (token.type != isc_tokentype_string)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews break;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETTOK(dns_rdatatype_fromtext(&covered,
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews &token.value.as_textregion));
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman if (covered > max_used) {
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman newend = covered / 8;
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman if (newend > end) {
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman memset(&bm[end + 1], 0, newend - end);
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman end = newend;
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman }
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman max_used = covered;
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman }
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews bm[covered/8] |= (0x80>>(covered%8));
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews first = ISC_FALSE;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews } while (1);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews isc_lex_ungettoken(lexer, &token);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (!allow_empty && first)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews return (DNS_R_FORMERR);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews for (window = 0; window < 256 ; window++) {
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman if (max_used < window * 256)
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman break;
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman max_octet = max_used - (window * 256);
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman if (max_octet >= 256)
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman max_octet = 31;
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman else
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman max_octet /= 8;
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews /*
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews * Find if we have a type in this window.
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews */
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman for (octet = max_octet; octet >= 0; octet--) {
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (bm[window * 32 + octet] != 0)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews break;
5b13a593fe7d8055992bd12aeb399bdb06e2a533Mukund Sivaraman }
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (octet < 0)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews continue;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(uint8_tobuffer(window, target));
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(uint8_tobuffer(octet + 1, target));
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(mem_tobuffer(target, &bm[window * 32], octet + 1));
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews }
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews return (ISC_R_SUCCESS);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews}
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrewsstatic inline isc_result_t
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrewstypemap_totext(isc_region_t *sr, dns_rdata_textctx_t *tctx,
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews isc_buffer_t *target)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews{
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews unsigned int i, j, k;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews unsigned int window, len;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews isc_boolean_t first = ISC_FALSE;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews for (i = 0; i < sr->length; i += len) {
9268c62bd0d85badde488143796be44bd75ca46aTinderbox User if (tctx != NULL &&
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews (tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
9268c62bd0d85badde488143796be44bd75ca46aTinderbox User RETERR(str_totext(tctx->linebreak, target));
9268c62bd0d85badde488143796be44bd75ca46aTinderbox User first = ISC_TRUE;
9268c62bd0d85badde488143796be44bd75ca46aTinderbox User }
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews INSIST(i + 2 <= sr->length);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews window = sr->base[i];
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews len = sr->base[i + 1];
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews INSIST(len > 0 && len <= 32);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews i += 2;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews INSIST(i + len <= sr->length);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews for (j = 0; j < len; j++) {
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews dns_rdatatype_t t;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (sr->base[i + j] == 0)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews continue;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews for (k = 0; k < 8; k++) {
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if ((sr->base[i + j] & (0x80 >> k)) == 0)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews continue;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews t = window * 256 + j * 8 + k;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (!first)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(str_totext(" ", target));
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews first = ISC_FALSE;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (dns_rdatatype_isknown(t)) {
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(dns_rdatatype_totext(t, target));
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews } else {
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews char buf[sizeof("TYPE65535")];
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf), "TYPE%u", t);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(str_totext(buf, target));
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews }
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews }
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews }
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews }
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews return (ISC_R_SUCCESS);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews}
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrewsstatic isc_result_t
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrewstypemap_test(isc_region_t *sr, isc_boolean_t allow_empty) {
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews unsigned int window, lastwindow = 0;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews unsigned int len;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews isc_boolean_t first = ISC_TRUE;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews unsigned int i;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews for (i = 0; i < sr->length; i += len) {
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews /*
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews * Check for overflow.
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews */
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (i + 2 > sr->length)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(DNS_R_FORMERR);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews window = sr->base[i];
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews len = sr->base[i + 1];
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews i += 2;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews /*
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews * Check that bitmap windows are in the correct order.
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews */
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (!first && window <= lastwindow)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(DNS_R_FORMERR);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews /*
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews * Check for legal lengths.
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews */
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (len < 1 || len > 32)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(DNS_R_FORMERR);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews /*
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews * Check for overflow.
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews */
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (i + len > sr->length)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(DNS_R_FORMERR);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews /*
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews * The last octet of the bitmap must be non zero.
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews */
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (sr->base[i + len - 1] == 0)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(DNS_R_FORMERR);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews lastwindow = window;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews first = ISC_FALSE;
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews }
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (i != sr->length)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews return (DNS_R_EXTRADATA);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews if (!allow_empty && first)
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews RETERR(DNS_R_FORMERR);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews return (ISC_R_SUCCESS);
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews}
f6e45a5c54b7af4b1c303e8d3ff3b7d78622df9eMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic const char hexdigits[] = "0123456789abcdef";
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic const char decdigits[] = "0123456789";
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include "code.h"
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews#define META 0x0001
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews#define RESERVED 0x0002
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/***
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *** Initialization
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ***/
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsvoid
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsdns_rdata_init(dns_rdata_t *rdata) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(rdata != NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rdata->data = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rdata->length = 0;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley rdata->rdclass = 0;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rdata->type = 0;
e6bd97dded968f82e26b270842b789bff7bca422Mark Andrews rdata->flags = 0;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_LINK_INIT(rdata, link);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews /* ISC_LIST_INIT(rdata->list); */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrewsvoid
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrewsdns_rdata_reset(dns_rdata_t *rdata) {
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellington REQUIRE(rdata != NULL);
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellington
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews REQUIRE(!ISC_LINK_LINKED(rdata, link));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews rdata->data = NULL;
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews rdata->length = 0;
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews rdata->rdclass = 0;
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews rdata->type = 0;
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews rdata->flags = 0;
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews}
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrews
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews/***
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews ***
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews ***/
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
29c818c7d40fc8898b062903ec703851328a4deaMark Andrewsvoid
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrewsdns_rdata_clone(const dns_rdata_t *src, dns_rdata_t *target) {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellington REQUIRE(src != NULL);
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellington REQUIRE(target != NULL);
cabaeca9ae5b98c80586b91e89cf552e17a75a9bBrian Wellington
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellington REQUIRE(DNS_RDATA_INITIALIZED(target));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(src));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(target));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews target->data = src->data;
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews target->length = src->length;
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews target->rdclass = src->rdclass;
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews target->type = src->type;
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews target->flags = src->flags;
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews}
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/***
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *** Comparisons
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ***/
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsint
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencedns_rdata_compare(const dns_rdata_t *rdata1, const dns_rdata_t *rdata2) {
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews int result = 0;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_boolean_t use_default = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(rdata1 != NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(rdata2 != NULL);
735ca24fa61ad9cd0285776c2fc4c14032f8f194Mark Andrews REQUIRE(rdata1->length == 0 || rdata1->data != NULL);
735ca24fa61ad9cd0285776c2fc4c14032f8f194Mark Andrews REQUIRE(rdata2->length == 0 || rdata2->data != NULL);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata1));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata2));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (rdata1->rdclass != rdata2->rdclass)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley return (rdata1->rdclass < rdata2->rdclass ? -1 : 1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (rdata1->type != rdata2->type)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (rdata1->type < rdata2->type ? -1 : 1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews COMPARESWITCH
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (use_default) {
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_region_t r1;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_region_t r2;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews dns_rdata_toregion(rdata1, &r1);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews dns_rdata_toregion(rdata2, &r2);
90e303b114e56db5809fdd19805243457fa43cd9Olafur Gudmundsson result = isc_region_compare(&r1, &r2);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewsint
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewsdns_rdata_casecompare(const dns_rdata_t *rdata1, const dns_rdata_t *rdata2) {
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews int result = 0;
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews isc_boolean_t use_default = ISC_FALSE;
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews REQUIRE(rdata1 != NULL);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews REQUIRE(rdata2 != NULL);
735ca24fa61ad9cd0285776c2fc4c14032f8f194Mark Andrews REQUIRE(rdata1->length == 0 || rdata1->data != NULL);
735ca24fa61ad9cd0285776c2fc4c14032f8f194Mark Andrews REQUIRE(rdata2->length == 0 || rdata2->data != NULL);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata1));
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata2));
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews if (rdata1->rdclass != rdata2->rdclass)
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews return (rdata1->rdclass < rdata2->rdclass ? -1 : 1);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews if (rdata1->type != rdata2->type)
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews return (rdata1->type < rdata2->type ? -1 : 1);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews CASECOMPARESWITCH
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews if (use_default) {
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews isc_region_t r1;
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews isc_region_t r2;
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews dns_rdata_toregion(rdata1, &r1);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews dns_rdata_toregion(rdata2, &r2);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews result = isc_region_compare(&r1, &r2);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews }
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews return (result);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews}
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/***
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *** Conversions
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ***/
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsvoid
d981ca645597116d227a48bf37cc5edc061c854dBob Halleydns_rdata_fromregion(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews dns_rdatatype_t type, isc_region_t *r)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews{
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(rdata != NULL);
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellington REQUIRE(DNS_RDATA_INITIALIZED(rdata));
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(r != NULL);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rdata->data = r->base;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rdata->length = r->length;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley rdata->rdclass = rdclass;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rdata->type = type;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews rdata->flags = 0;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsvoid
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencedns_rdata_toregion(const dns_rdata_t *rdata, isc_region_t *r) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(rdata != NULL);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(r != NULL);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews r->base = rdata->data;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews r->length = rdata->length;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
d981ca645597116d227a48bf37cc5edc061c854dBob Halleydns_rdata_fromwire(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews dns_rdatatype_t type, isc_buffer_t *source,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_decompress_t *dctx, unsigned int options,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews isc_buffer_t *target)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews{
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_result_t result = ISC_R_NOTIMPLEMENTED;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_t ss;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_t st;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_boolean_t use_default = ISC_FALSE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_uint32_t activelength;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews unsigned int length;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(dctx != NULL);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews if (rdata != NULL) {
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellington REQUIRE(DNS_RDATA_INITIALIZED(rdata));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews }
7e9d637131516486630290d36c4c0db544cb700eMark Andrews REQUIRE(source != NULL);
7e9d637131516486630290d36c4c0db544cb700eMark Andrews REQUIRE(target != NULL);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
6bebabb376b93e7d12f53a253b197a3fc0e0b001Andreas Gustafsson if (type == 0)
6bebabb376b93e7d12f53a253b197a3fc0e0b001Andreas Gustafsson return (DNS_R_FORMERR);
6bebabb376b93e7d12f53a253b197a3fc0e0b001Andreas Gustafsson
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ss = *source;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews st = *target;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews activelength = isc_buffer_activelength(source);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews INSIST(activelength < 65536);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews FROMWIRESWITCH
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (use_default) {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (activelength > isc_buffer_availablelength(target))
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews result = ISC_R_NOSPACE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews else {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_buffer_putmem(target, isc_buffer_current(source),
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews activelength);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_buffer_forward(source, activelength);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews result = ISC_R_SUCCESS;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews }
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews /*
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews * Reject any rdata that expands out to more than DNS_RDATA_MAXLENGTH
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews * as we cannot transmit it.
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews */
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews length = isc_buffer_usedlength(target) - isc_buffer_usedlength(&st);
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews if (result == ISC_R_SUCCESS && length > DNS_RDATA_MAXLENGTH)
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews result = DNS_R_FORMERR;
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * We should have consumed all of our buffer.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_SUCCESS && !buffer_empty(source))
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews result = DNS_R_EXTRADATA;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
ad7209ea70d346527ffdcda335153831341d9dcfAndreas Gustafsson if (rdata != NULL && result == ISC_R_SUCCESS) {
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews region.base = isc_buffer_used(&st);
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews region.length = length;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_rdata_fromregion(rdata, rdclass, type, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *source = ss;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *target = st;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsdns_rdata_towire(dns_rdata_t *rdata, dns_compress_t *cctx,
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington isc_buffer_t *target)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews{
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_result_t result = ISC_R_NOTIMPLEMENTED;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_boolean_t use_default = ISC_FALSE;
f0a5bb8f86631ce638cb2b6c65bbb9bcf9b0cdc0Bob Halley isc_region_t tr;
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews isc_buffer_t st;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(rdata != NULL);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson /*
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson * Some DynDNS meta-RRs have empty rdata.
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson */
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews if ((rdata->flags & DNS_RDATA_UPDATE) != 0) {
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews INSIST(rdata->length == 0);
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson return (ISC_R_SUCCESS);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews }
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews st = *target;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews TOWIRESWITCH
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (use_default) {
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tr);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (tr.length < rdata->length)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(tr.base, rdata->data, rdata->length);
f0a5bb8f86631ce638cb2b6c65bbb9bcf9b0cdc0Bob Halley isc_buffer_add(target, rdata->length);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS) {
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews *target = st;
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence INSIST(target->used < 65536);
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence dns_compress_rollback(cctx, (isc_uint16_t)target->used);
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson/*
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson * If the binary data in 'src' is valid uncompressed wire format
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson * rdata of class 'rdclass' and type 'type', return ISC_R_SUCCESS
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson * and copy the validated rdata to 'dest'. Otherwise return an error.
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson */
3a16668468060842e847ea6556e80e1405d35cd6Brian Wellingtonstatic isc_result_t
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafssonrdata_validate(isc_buffer_t *src, isc_buffer_t *dest, dns_rdataclass_t rdclass,
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington dns_rdatatype_t type)
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews{
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington dns_decompress_t dctx;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington isc_result_t result;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington
942d1a339b1fe617f7d17d66cb5fccce798d15aeBrian Wellington dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_NONE);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington isc_buffer_setactive(src, isc_buffer_usedlength(src));
7e9d637131516486630290d36c4c0db544cb700eMark Andrews result = dns_rdata_fromwire(NULL, rdclass, type, src, &dctx, 0, dest);
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington dns_decompress_invalidate(&dctx);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews return (result);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews}
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellingtonstatic isc_result_t
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellingtonunknown_fromtext(dns_rdataclass_t rdclass, dns_rdatatype_t type,
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington isc_lex_t *lexer, isc_mem_t *mctx, isc_buffer_t *target)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington{
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington isc_result_t result;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington isc_buffer_t *buf = NULL;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington isc_token_t token;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington
de5247ae1683ce145662180ee50272d2214a0232Andreas Gustafsson if (type == 0 || dns_rdatatype_ismeta(type))
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington return (DNS_R_METATYPE);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington
1cc4695f0da63f0190e3514adccf6a96f3dc1519Mark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
1cc4695f0da63f0190e3514adccf6a96f3dc1519Mark Andrews ISC_FALSE));
1cc4695f0da63f0190e3514adccf6a96f3dc1519Mark Andrews if (token.value.as_ulong > 65535U)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington return (ISC_R_RANGE);
f16495732753175e4a9fc144323a12fdcc29b561Brian Wellington result = isc_buffer_allocate(mctx, &buf, token.value.as_ulong);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (result != ISC_R_SUCCESS)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington return (result);
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater
e086935752b6e2f51ef2985fee21ccfff617b115David Lawrence result = isc_hex_tobuffer(lexer, buf,
e086935752b6e2f51ef2985fee21ccfff617b115David Lawrence (unsigned int)token.value.as_ulong);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (result != ISC_R_SUCCESS)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington goto failure;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (isc_buffer_usedlength(buf) != token.value.as_ulong) {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington result = ISC_R_UNEXPECTEDEND;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington goto failure;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington }
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (dns_rdatatype_isknown(type)) {
7e4cda9965e2edf2ec43c57967eec8eff7061ab0Andreas Gustafsson result = rdata_validate(buf, target, rdclass, type);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington } else {
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington isc_region_t r;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington isc_buffer_usedregion(buf, &r);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington result = isc_buffer_copyregion(target, &r);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington }
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington if (result != ISC_R_SUCCESS)
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington goto failure;
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington isc_buffer_free(&buf);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington return (ISC_R_SUCCESS);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington failure:
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington isc_buffer_free(&buf);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington return (result);
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington}
93ed317bb43658ed48ee7439f7a36bb9bcf80c94Brian Wellington
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
d981ca645597116d227a48bf37cc5edc061c854dBob Halleydns_rdata_fromtext(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews dns_rdatatype_t type, isc_lex_t *lexer,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_name_t *origin, unsigned int options, isc_mem_t *mctx,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews isc_buffer_t *target, dns_rdatacallbacks_t *callbacks)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews{
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_result_t result = ISC_R_NOTIMPLEMENTED;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_t st;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_token_t token;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews unsigned int lexoptions = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF |
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews ISC_LEXOPT_DNSMULTILINE | ISC_LEXOPT_ESCAPE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews char *name;
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence unsigned long line;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence void (*callback)(dns_rdatacallbacks_t *, const char *, ...);
8dd5237a27e2e824d18f835dc711573aeb23a173Mark Andrews isc_result_t tresult;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews unsigned int length;
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews isc_boolean_t unknown;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence REQUIRE(origin == NULL || dns_name_isabsolute(origin) == ISC_TRUE);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews if (rdata != NULL) {
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellington REQUIRE(DNS_RDATA_INITIALIZED(rdata));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews }
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews if (callbacks != NULL) {
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews REQUIRE(callbacks->warn != NULL);
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews REQUIRE(callbacks->error != NULL);
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews }
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews st = *target;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews if (callbacks != NULL)
228c679d7a269423019f7c528db92e855f08240bMark Andrews callback = callbacks->error;
b6a0341bcb113e93bd0bc41a9f9a1fc117444da6Mark Andrews else
228c679d7a269423019f7c528db92e855f08240bMark Andrews callback = default_fromtext_callback;
228c679d7a269423019f7c528db92e855f08240bMark Andrews
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington result = isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington ISC_FALSE);
228c679d7a269423019f7c528db92e855f08240bMark Andrews if (result != ISC_R_SUCCESS) {
228c679d7a269423019f7c528db92e855f08240bMark Andrews name = isc_lex_getsourcename(lexer);
228c679d7a269423019f7c528db92e855f08240bMark Andrews line = isc_lex_getsourceline(lexer);
c51f2c9a529b2130a8058cb7a32bd284fa6cfdb9Mark Andrews fromtext_error(callback, callbacks, name, line, NULL, result);
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington return (result);
228c679d7a269423019f7c528db92e855f08240bMark Andrews }
228c679d7a269423019f7c528db92e855f08240bMark Andrews
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews unknown = ISC_FALSE;
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews if (token.type == isc_tokentype_string &&
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews strcmp(DNS_AS_STR(token), "\\#") == 0) {
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews /*
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews * If this is a TXT record '\#' could be a escaped '#'.
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews * Look to see if the next token is a number and if so
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews * treat it as a unknown record format.
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews */
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews if (type == dns_rdatatype_txt) {
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews result = isc_lex_getmastertoken(lexer, &token,
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews isc_tokentype_number,
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews ISC_FALSE);
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews if (result == ISC_R_SUCCESS)
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews isc_lex_ungettoken(lexer, &token);
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews }
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews if (result == ISC_R_SUCCESS) {
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews unknown = ISC_TRUE;
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews result = unknown_fromtext(rdclass, type, lexer,
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews mctx, target);
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews } else
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews options |= DNS_RDATA_UNKNOWNESCAPE;
b8e2e5dd861bdc72a5496a745a85f8761bef7dc4Tinderbox User } else
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington isc_lex_ungettoken(lexer, &token);
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington
e85702ce5be33d7c07eff6487c6bb4730165f331Mark Andrews if (!unknown)
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington FROMTEXTSWITCH
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews /*
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews * Consume to end of line / file.
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews * If not at end of line initially set error code.
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews * Call callback via fromtext_error once if there was an error.
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews */
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews do {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews name = isc_lex_getsourcename(lexer);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews line = isc_lex_getsourceline(lexer);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews tresult = isc_lex_gettoken(lexer, lexoptions, &token);
8dd5237a27e2e824d18f835dc711573aeb23a173Mark Andrews if (tresult != ISC_R_SUCCESS) {
8dd5237a27e2e824d18f835dc711573aeb23a173Mark Andrews if (result == ISC_R_SUCCESS)
8dd5237a27e2e824d18f835dc711573aeb23a173Mark Andrews result = tresult;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (callback != NULL)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews fromtext_error(callback, callbacks, name,
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews line, NULL, result);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews break;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews } else if (token.type != isc_tokentype_eol &&
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews token.type != isc_tokentype_eof) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_SUCCESS)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews result = DNS_R_EXTRATOKEN;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (callback != NULL) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews fromtext_error(callback, callbacks, name,
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews line, &token, result);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews callback = NULL;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff } else if (result != ISC_R_SUCCESS && callback != NULL) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews fromtext_error(callback, callbacks, name, line,
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews &token, result);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews break;
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews } else {
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews if (token.type == isc_tokentype_eof)
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews fromtext_warneof(lexer, callbacks);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews break;
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews }
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews } while (1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews length = isc_buffer_usedlength(target) - isc_buffer_usedlength(&st);
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews if (result == ISC_R_SUCCESS && length > DNS_RDATA_MAXLENGTH)
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews result = ISC_R_NOSPACE;
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (rdata != NULL && result == ISC_R_SUCCESS) {
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews region.base = isc_buffer_used(&st);
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews region.length = length;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_rdata_fromregion(rdata, rdclass, type, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *target = st;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrewsstatic isc_result_t
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrewsunknown_totext(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews isc_buffer_t *target)
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews{
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews isc_result_t result;
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews char buf[sizeof("65535")];
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews isc_region_t sr;
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews strlcpy(buf, "\\# ", sizeof(buf));
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews result = str_totext(buf, target);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews if (result != ISC_R_SUCCESS)
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews return (result);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews dns_rdata_toregion(rdata, &sr);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews INSIST(sr.length < 65536);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews snprintf(buf, sizeof(buf), "%u", sr.length);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews result = str_totext(buf, target);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews if (result != ISC_R_SUCCESS)
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews return (result);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews if (sr.length != 0U) {
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews result = str_totext(" ( ", target);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews else
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews result = str_totext(" ", target);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews if (result != ISC_R_SUCCESS)
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews return (result);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews if (tctx->width == 0) /* No splitting */
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews result = isc_hex_totext(&sr, 0, "", target);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews else
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews result = isc_hex_totext(&sr, tctx->width - 2,
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews tctx->linebreak,
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews target);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews if (result == ISC_R_SUCCESS &&
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews (tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews result = str_totext(" )", target);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews }
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews return (result);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews}
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halleyrdata_totext(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley isc_buffer_t *target)
19d365e4448f1782611280b020987988b7ac3210Mark Andrews{
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_result_t result = ISC_R_NOTIMPLEMENTED;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_boolean_t use_default = ISC_FALSE;
ec3dbae9eb0fdbda37c76c2b41e819c7982be1c4Mukund Sivaraman unsigned int cur;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(rdata != NULL);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence REQUIRE(tctx->origin == NULL ||
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence dns_name_isabsolute(tctx->origin) == ISC_TRUE);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Some DynDNS meta-RRs have empty rdata.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews if ((rdata->flags & DNS_RDATA_UPDATE) != 0) {
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews INSIST(rdata->length == 0);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews }
f8aae502686e2448c48f56697c212a50e2a1cbaeAndreas Gustafsson
79a55d4f4dcf3d6f617523228503d8584b72a3a3Mukund Sivaraman if ((tctx->flags & DNS_STYLEFLAG_UNKNOWNFORMAT) != 0)
79a55d4f4dcf3d6f617523228503d8584b72a3a3Mukund Sivaraman return (unknown_totext(rdata, tctx, target));
79a55d4f4dcf3d6f617523228503d8584b72a3a3Mukund Sivaraman
ec3dbae9eb0fdbda37c76c2b41e819c7982be1c4Mukund Sivaraman cur = isc_buffer_usedlength(target);
ec3dbae9eb0fdbda37c76c2b41e819c7982be1c4Mukund Sivaraman
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews TOTEXTSWITCH
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
ec3dbae9eb0fdbda37c76c2b41e819c7982be1c4Mukund Sivaraman if (use_default || (result == ISC_R_NOTIMPLEMENTED)) {
ec3dbae9eb0fdbda37c76c2b41e819c7982be1c4Mukund Sivaraman unsigned int u = isc_buffer_usedlength(target);
ec3dbae9eb0fdbda37c76c2b41e819c7982be1c4Mukund Sivaraman
ec3dbae9eb0fdbda37c76c2b41e819c7982be1c4Mukund Sivaraman INSIST(u >= cur);
ec3dbae9eb0fdbda37c76c2b41e819c7982be1c4Mukund Sivaraman isc_buffer_subtract(target, u - cur);
fe3472c80b76b6fed0ae674fd63471d02477a03aMark Andrews result = unknown_totext(rdata, tctx, target);
ec3dbae9eb0fdbda37c76c2b41e819c7982be1c4Mukund Sivaraman }
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdata_totext(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target)
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson{
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews dns_rdata_textctx_t tctx;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Set up formatting options for single-line output.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson tctx.origin = origin;
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson tctx.flags = 0;
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson tctx.width = 60;
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson tctx.linebreak = " ";
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley return (rdata_totext(rdata, &tctx, target));
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson}
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafssondns_rdata_tofmttext(dns_rdata_t *rdata, dns_name_t *origin,
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson unsigned int flags, unsigned int width,
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt unsigned int split_width, const char *linebreak,
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt isc_buffer_t *target)
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson{
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews dns_rdata_textctx_t tctx;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Set up formatting options for formatted output.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson tctx.origin = origin;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson tctx.flags = flags;
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt if (split_width == 0xffffffff)
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson tctx.width = width;
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt else
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt tctx.width = split_width;
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt if ((flags & DNS_STYLEFLAG_MULTILINE) != 0)
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson tctx.linebreak = linebreak;
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt else {
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt if (split_width == 0xffffffff)
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt tctx.width = 60; /* Used for hex word length only. */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson tctx.linebreak = " ";
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson }
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley return (rdata_totext(rdata, &tctx, target));
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson}
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
d981ca645597116d227a48bf37cc5edc061c854dBob Halleydns_rdata_fromstruct(dns_rdata_t *rdata, dns_rdataclass_t rdclass,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews dns_rdatatype_t type, void *source,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews isc_buffer_t *target)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews{
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_result_t result = ISC_R_NOTIMPLEMENTED;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_t st;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_boolean_t use_default = ISC_FALSE;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews unsigned int length;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(source != NULL);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews if (rdata != NULL) {
f1cae4bcb7ee3060d893f5ab3ba55c1820bf3e4aBrian Wellington REQUIRE(DNS_RDATA_INITIALIZED(rdata));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews }
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews st = *target;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews FROMSTRUCTSWITCH
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (use_default)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews (void)NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews length = isc_buffer_usedlength(target) - isc_buffer_usedlength(&st);
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews if (result == ISC_R_SUCCESS && length > DNS_RDATA_MAXLENGTH)
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews result = ISC_R_NOSPACE;
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (rdata != NULL && result == ISC_R_SUCCESS) {
7d8cdd869ed2162a5befda7cc1600136110f54d6Mark Andrews region.base = isc_buffer_used(&st);
1bbd36c4db2c86762b582db4b0504e6e68a183f6Mark Andrews region.length = length;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_rdata_fromregion(rdata, rdclass, type, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *target = st;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrewsdns_rdata_tostruct(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_result_t result = ISC_R_NOTIMPLEMENTED;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_boolean_t use_default = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(rdata != NULL);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews TOSTRUCTSWITCH
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (use_default)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews (void)NULL;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrewsvoid
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrewsdns_rdata_freestruct(void *source) {
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews dns_rdatacommon_t *common = source;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews REQUIRE(source != NULL);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews FREESTRUCTSWITCH
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews}
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
d981ca645597116d227a48bf37cc5edc061c854dBob Halleydns_rdata_additionaldata(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley void *arg)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley{
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_result_t result = ISC_R_NOTIMPLEMENTED;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley isc_boolean_t use_default = ISC_FALSE;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley /*
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * Call 'add' for each name and type from 'rdata' which is subject to
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * additional section processing.
d981ca645597116d227a48bf37cc5edc061c854dBob Halley */
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley REQUIRE(rdata != NULL);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley REQUIRE(add != NULL);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley ADDITIONALDATASWITCH
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews /* No additional processing for unknown types */
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (use_default)
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews result = ISC_R_SUCCESS;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley return (result);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley}
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halleydns_rdata_digest(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_result_t result = ISC_R_NOTIMPLEMENTED;
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley isc_boolean_t use_default = ISC_FALSE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_region_t r;
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley /*
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley * Send 'rdata' in DNSSEC canonical form to 'digest'.
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley */
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley REQUIRE(rdata != NULL);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley REQUIRE(digest != NULL);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews REQUIRE(DNS_RDATA_VALIDFLAGS(rdata));
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley DIGESTSWITCH
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (use_default) {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_rdata_toregion(rdata, &r);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews result = (digest)(arg, &r);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews }
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley return (result);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley}
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsisc_boolean_t
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsdns_rdata_checkowner(dns_name_t *name, dns_rdataclass_t rdclass,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_rdatatype_t type, isc_boolean_t wildcard)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews{
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews isc_boolean_t result;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews CHECKOWNERSWITCH
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews return (result);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsisc_boolean_t
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsdns_rdata_checknames(dns_rdata_t *rdata, dns_name_t *owner, dns_name_t *bad)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews{
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews isc_boolean_t result;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews CHECKNAMESSWITCH
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews return (result);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
6324997211a5e2d82528dcde98e8981190a35faeMichael Graffunsigned int
6324997211a5e2d82528dcde98e8981190a35faeMichael Graffdns_rdatatype_attributes(dns_rdatatype_t type)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff{
28b863e609ff2d97b78663b46894494cfa2ea411Mark Andrews RDATATYPE_ATTRIBUTE_SW
0316be2d7786f72b886d9e5ba892c77038543ef7Evan Hunt if (type >= (dns_rdatatype_t)128 && type < (dns_rdatatype_t)255)
0316be2d7786f72b886d9e5ba892c77038543ef7Evan Hunt return (DNS_RDATATYPEATTR_UNKNOWN | DNS_RDATATYPEATTR_META);
471e0563c7965c556c759775882cd3448dae78eaMark Andrews return (DNS_RDATATYPEATTR_UNKNOWN);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff}
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdatatype_fromtext(dns_rdatatype_t *typep, isc_textregion_t *source) {
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff unsigned int hash;
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews unsigned int n;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff unsigned char a, b;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff n = source->length;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff if (n == 0)
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff return (DNS_R_UNKNOWN);
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence a = tolower((unsigned char)source->base[0]);
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence b = tolower((unsigned char)source->base[n - 1]);
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff hash = ((a + n) * b) % 256;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff /*
29747dfe5e073a299b3681e01f5c55540f8bfed7Mark Andrews * This switch block is inlined via \#define, and will use "return"
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff * to return a result to the caller if it is a valid (known)
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff * rdatatype name.
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff */
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews RDATATYPE_FROMTEXT_SW(hash, source->base, n, typep);
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews if (source->length > 4 && source->length < (4 + sizeof("65000")) &&
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews strncasecmp("type", source->base, 4) == 0) {
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews char buf[sizeof("65000")];
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington char *endp;
9be230cfca126bea6b666f506a230ffcdfba60dbMark Andrews unsigned int val;
8695d7b357789bedff63e5b19c5ab25cd58fcd4bMark Andrews
5a93d3be4e0c652f455066bb764416173a00c951Mark Andrews /*
5a93d3be4e0c652f455066bb764416173a00c951Mark Andrews * source->base is not required to be NUL terminated.
5a93d3be4e0c652f455066bb764416173a00c951Mark Andrews * Copy up to remaining bytes and NUL terminate.
5a93d3be4e0c652f455066bb764416173a00c951Mark Andrews */
28326542361e6a3a32511b9a5a445e749bce6231Mark Andrews snprintf(buf, sizeof(buf), "%.*s",
28326542361e6a3a32511b9a5a445e749bce6231Mark Andrews (int)(source->length - 4), source->base + 4);
beed6a0e226fbd0c18c19a3e341a2003cba020a5Mark Andrews val = strtoul(buf, &endp, 10);
9be230cfca126bea6b666f506a230ffcdfba60dbMark Andrews if (*endp == '\0' && val <= 0xffff) {
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington *typep = (dns_rdatatype_t)val;
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington return (ISC_R_SUCCESS);
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington }
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington }
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews return (DNS_R_UNKNOWN);
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews}
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdatatype_totext(dns_rdatatype_t type, isc_buffer_t *target) {
79a55d4f4dcf3d6f617523228503d8584b72a3a3Mukund Sivaraman RDATATYPE_TOTEXT_SW
79a55d4f4dcf3d6f617523228503d8584b72a3a3Mukund Sivaraman
79a55d4f4dcf3d6f617523228503d8584b72a3a3Mukund Sivaraman return (dns_rdatatype_tounknowntext(type, target));
79a55d4f4dcf3d6f617523228503d8584b72a3a3Mukund Sivaraman}
79a55d4f4dcf3d6f617523228503d8584b72a3a3Mukund Sivaraman
79a55d4f4dcf3d6f617523228503d8584b72a3a3Mukund Sivaramanisc_result_t
79a55d4f4dcf3d6f617523228503d8584b72a3a3Mukund Sivaramandns_rdatatype_tounknowntext(dns_rdatatype_t type, isc_buffer_t *target) {
471e0563c7965c556c759775882cd3448dae78eaMark Andrews char buf[sizeof("TYPE65535")];
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
cc083bb7031c04d57cbad41b2f5a796a4fd1865cMark Andrews snprintf(buf, sizeof(buf), "TYPE%u", type);
471e0563c7965c556c759775882cd3448dae78eaMark Andrews return (str_totext(buf, target));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews}
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafssonvoid
8c962eba3d6faebc008806ebb6bb9d08089118e9Andreas Gustafssondns_rdatatype_format(dns_rdatatype_t rdtype,
8c962eba3d6faebc008806ebb6bb9d08089118e9Andreas Gustafsson char *array, unsigned int size)
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson{
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson isc_result_t result;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson isc_buffer_t buf;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson
e01f55daa4b611190a11a40299007e5e55018854Mark Andrews if (size == 0U)
e01f55daa4b611190a11a40299007e5e55018854Mark Andrews return;
e01f55daa4b611190a11a40299007e5e55018854Mark Andrews
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson isc_buffer_init(&buf, array, size);
8c962eba3d6faebc008806ebb6bb9d08089118e9Andreas Gustafsson result = dns_rdatatype_totext(rdtype, &buf);
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson /*
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson * Null terminate.
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson */
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson if (result == ISC_R_SUCCESS) {
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson if (isc_buffer_availablelength(&buf) >= 1)
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson isc_buffer_putuint8(&buf, 0);
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson else
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson result = ISC_R_NOSPACE;
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson }
e01f55daa4b611190a11a40299007e5e55018854Mark Andrews if (result != ISC_R_SUCCESS)
e01f55daa4b611190a11a40299007e5e55018854Mark Andrews strlcpy(array, "<unknown>", size);
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson}
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence/*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Private function.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic unsigned int
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsname_length(dns_name_t *name) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (name->length);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
2383eb527269d333df4222da20e4b422c3662daaEvan Hunttxt_totext(isc_region_t *source, isc_boolean_t quote, isc_buffer_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int tl;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int n;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned char *sp;
fe47f41b13620bfafc4f8cf65d5df24f1e568764Bob Halley char *tp;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews sp = source->base;
fe47f41b13620bfafc4f8cf65d5df24f1e568764Bob Halley tp = (char *)region.base;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews tl = region.length;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews n = *sp++;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews REQUIRE(n + 1 <= source->length);
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt if (n == 0U)
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt REQUIRE(quote == ISC_TRUE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt if (quote) {
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt if (tl < 1)
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt return (ISC_R_NOSPACE);
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt *tp++ = '"';
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt tl--;
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews while (n--) {
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt /*
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt * \DDD space (0x20) if not quoting.
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt */
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt if (*sp < (quote ? 0x20 : 0x21) || *sp >= 0x7f) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (tl < 4)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
7755f5932a3e59d0c6a2506cc94519de92b91ca6Mark Andrews *tp++ = 0x5c;
7755f5932a3e59d0c6a2506cc94519de92b91ca6Mark Andrews *tp++ = 0x30 + ((*sp / 100) % 10);
7755f5932a3e59d0c6a2506cc94519de92b91ca6Mark Andrews *tp++ = 0x30 + ((*sp / 10) % 10);
7755f5932a3e59d0c6a2506cc94519de92b91ca6Mark Andrews *tp++ = 0x30 + (*sp % 10);
c2b217ea1135f070da3856d3276895b3026e932aMark Andrews sp++;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews tl -= 4;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews continue;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt /*
9a36fb86f5019f25705d25ea729d03fcf8ecaa95Mark Andrews * Escape double quote and backslash. If we are not
9a36fb86f5019f25705d25ea729d03fcf8ecaa95Mark Andrews * enclosing the string in double quotes also escape
9a36fb86f5019f25705d25ea729d03fcf8ecaa95Mark Andrews * at sign and semicolon.
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt */
9a36fb86f5019f25705d25ea729d03fcf8ecaa95Mark Andrews if (*sp == 0x22 || *sp == 0x5c ||
9a36fb86f5019f25705d25ea729d03fcf8ecaa95Mark Andrews (!quote && (*sp == 0x40 || *sp == 0x3b))) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (tl < 2)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *tp++ = '\\';
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews tl--;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (tl < 1)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *tp++ = *sp++;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews tl--;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt if (quote) {
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt if (tl < 1)
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt return (ISC_R_NOSPACE);
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt *tp++ = '"';
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt tl--;
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt }
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews isc_buffer_add(target, (unsigned int)(tp - (char *)region.base));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(source, *source->base + 1);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewstxt_fromtext(isc_textregion_t *source, isc_buffer_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t tregion;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews isc_boolean_t escape;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews unsigned int n, nrem;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews char *s;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews unsigned char *t;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews int d;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews int c;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tregion);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews s = source->base;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews n = source->length;
f0ff273b530afa730025e1c5ad311950f7ff4328Mark Andrews t = tregion.base;
f0ff273b530afa730025e1c5ad311950f7ff4328Mark Andrews nrem = tregion.length;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews escape = ISC_FALSE;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (nrem < 1)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Length byte.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews nrem--;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews t++;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Maximum text string length.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (nrem > 255)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews nrem = 255;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews while (n-- != 0) {
ad493ef9ddb5a3e78e9d99f57abe75552f36a8f4Andreas Gustafsson c = (*s++) & 0xff;
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence if (escape && (d = decvalue((char)c)) != -1) {
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews c = d;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (n == 0)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews return (DNS_R_SYNTAX);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews n--;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if ((d = decvalue(*s++)) != -1)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews c = c * 10 + d;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews else
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews return (DNS_R_SYNTAX);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (n == 0)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews return (DNS_R_SYNTAX);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews n--;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if ((d = decvalue(*s++)) != -1)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews c = c * 10 + d;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews else
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews return (DNS_R_SYNTAX);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (c > 255)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews return (DNS_R_SYNTAX);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews } else if (!escape && c == '\\') {
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews escape = ISC_TRUE;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews continue;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews }
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews escape = ISC_FALSE;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (nrem == 0)
a5a30ae7c0636a57d8575acb98fdf906c0ea818fMark Andrews return ((tregion.length <= 256U) ?
a5a30ae7c0636a57d8575acb98fdf906c0ea818fMark Andrews ISC_R_NOSPACE : DNS_R_SYNTAX);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews *t++ = c;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews nrem--;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews }
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (escape)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews return (DNS_R_SYNTAX);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews *tregion.base = (unsigned char)(t - tregion.base - 1);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews isc_buffer_add(target, *tregion.base + 1);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewstxt_fromwire(isc_buffer_t *source, isc_buffer_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int n;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t sregion;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t tregion;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_activeregion(source, &sregion);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (sregion.length == 0)
c707e2b9861dfa3f86b3520b9c3630db70cb020cEvan Hunt return (ISC_R_UNEXPECTEDEND);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews n = *sregion.base + 1;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (n > sregion.length)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDEND);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tregion);
bfb2a81b65579882a80855c279cedc45aebd62e8Mark Andrews if (n > tregion.length)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
7e9d637131516486630290d36c4c0db544cb700eMark Andrews if (tregion.base != sregion.base)
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(tregion.base, sregion.base, n);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_forward(source, n);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_add(target, n);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt/*
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt * Conversion of TXT-like rdata fields without length limits.
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt */
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupontstatic isc_result_t
7712d1660a308ec3de17f1ddbbf801eb0d663f3eEvan Huntmultitxt_totext(isc_region_t *source, isc_buffer_t *target) {
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont unsigned int tl;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont unsigned int n0, n;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont unsigned char *sp;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont char *tp;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont isc_region_t region;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont isc_buffer_availableregion(target, &region);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont sp = source->base;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont tp = (char *)region.base;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont tl = region.length;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (tl < 1)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (ISC_R_NOSPACE);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont *tp++ = '"';
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont tl--;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont do {
7712d1660a308ec3de17f1ddbbf801eb0d663f3eEvan Hunt n = source->length;
7712d1660a308ec3de17f1ddbbf801eb0d663f3eEvan Hunt n0 = source->length - 1;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont while (n--) {
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (*sp < 0x20 || *sp >= 0x7f) {
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (tl < 4)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (ISC_R_NOSPACE);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont *tp++ = 0x5c;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont *tp++ = 0x30 + ((*sp / 100) % 10);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont *tp++ = 0x30 + ((*sp / 10) % 10);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont *tp++ = 0x30 + (*sp % 10);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont sp++;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont tl -= 4;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont continue;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont }
59d940391ce90963cd3f4b22201b3fca2ffda22aMark Andrews /* double quote, backslash */
59d940391ce90963cd3f4b22201b3fca2ffda22aMark Andrews if (*sp == 0x22 || *sp == 0x5c) {
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (tl < 2)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (ISC_R_NOSPACE);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont *tp++ = '\\';
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont tl--;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont }
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (tl < 1)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (ISC_R_NOSPACE);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont *tp++ = *sp++;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont tl--;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont }
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont isc_region_consume(source, n0 + 1);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont } while (source->length != 0);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (tl < 1)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (ISC_R_NOSPACE);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont *tp++ = '"';
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont tl--;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews isc_buffer_add(target, (unsigned int)(tp - (char *)region.base));
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (ISC_R_SUCCESS);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont}
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupontstatic isc_result_t
7712d1660a308ec3de17f1ddbbf801eb0d663f3eEvan Huntmultitxt_fromtext(isc_textregion_t *source, isc_buffer_t *target) {
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont isc_region_t tregion;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont isc_boolean_t escape;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont unsigned int n, nrem;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont char *s;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont unsigned char *t0, *t;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont int d;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont int c;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont s = source->base;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont n = source->length;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont escape = ISC_FALSE;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont do {
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont isc_buffer_availableregion(target, &tregion);
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt t0 = t = tregion.base;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont nrem = tregion.length;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (nrem < 1)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (ISC_R_NOSPACE);
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont while (n != 0) {
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont --n;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont c = (*s++) & 0xff;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (escape && (d = decvalue((char)c)) != -1) {
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont c = d;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (n == 0)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (DNS_R_SYNTAX);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont n--;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if ((d = decvalue(*s++)) != -1)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont c = c * 10 + d;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont else
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (DNS_R_SYNTAX);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (n == 0)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (DNS_R_SYNTAX);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont n--;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if ((d = decvalue(*s++)) != -1)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont c = c * 10 + d;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont else
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (DNS_R_SYNTAX);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (c > 255)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (DNS_R_SYNTAX);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont } else if (!escape && c == '\\') {
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont escape = ISC_TRUE;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont continue;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont }
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont escape = ISC_FALSE;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont *t++ = c;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont nrem--;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (nrem == 0)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont break;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont }
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont if (escape)
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (DNS_R_SYNTAX);
2383eb527269d333df4222da20e4b422c3662daaEvan Hunt
ab973ec40cc7a79bbf930085b1293824caf73e7fFrancis Dupont isc_buffer_add(target, (unsigned int)(t - t0));
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont } while (n != 0);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (ISC_R_SUCCESS);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont}
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_boolean_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsname_prefix(dns_name_t *name, dns_name_t *origin, dns_name_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews int l1, l2;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (origin == NULL)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews goto return_false;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (dns_name_compare(origin, dns_rootname) == 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews goto return_false;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (!dns_name_issubdomain(name, origin))
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews goto return_false;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews l1 = dns_name_countlabels(name);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews l2 = dns_name_countlabels(origin);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (l1 == l2)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews goto return_false;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
38b84a1fcfdbda4d1d0fdca409004ae83be2ace8Mark Andrews /* Master files should be case preserving. */
38b84a1fcfdbda4d1d0fdca409004ae83be2ace8Mark Andrews dns_name_getlabelsequence(name, l1 - l2, l2, target);
38b84a1fcfdbda4d1d0fdca409004ae83be2ace8Mark Andrews if (!dns_name_caseequal(origin, target))
38b84a1fcfdbda4d1d0fdca409004ae83be2ace8Mark Andrews goto return_false;
38b84a1fcfdbda4d1d0fdca409004ae83be2ace8Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_getlabelsequence(name, 0, l1 - l2, target);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (ISC_TRUE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsreturn_false:
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *target = *name;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (ISC_FALSE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencestr_totext(const char *source, isc_buffer_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int l;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews l = strlen(source);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (l > region.length)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(region.base, source, l);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_add(target, l);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellingtonstatic isc_result_t
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellingtoninet_totext(int af, isc_region_t *src, isc_buffer_t *target) {
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington char tmpbuf[64];
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington /* Note - inet_ntop doesn't do size checking on its input. */
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington if (inet_ntop(af, src->base, tmpbuf, sizeof(tmpbuf)) == NULL)
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington return (ISC_R_NOSPACE);
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington if (strlen(tmpbuf) > isc_buffer_availablelength(target))
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington return (ISC_R_NOSPACE);
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington isc_buffer_putstr(target, tmpbuf);
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington return (ISC_R_SUCCESS);
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington}
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_boolean_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsbuffer_empty(isc_buffer_t *source) {
26b0f58b6c4d65bc8b131debf40b8c376c2978bfBob Halley return((source->current == source->active) ? ISC_TRUE : ISC_FALSE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrencebuffer_fromregion(isc_buffer_t *buffer, isc_region_t *region) {
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_init(buffer, region->base, region->length);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_add(buffer, region->length);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_buffer_setactive(buffer, region->length);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrewsuint32_tobuffer(isc_uint32_t value, isc_buffer_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (region.length < 4)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
e4653123ecc6cdbfc0b9eda6e98e44af3b1f9a08Mark Andrews isc_buffer_putuint32(target, value);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrewsuint16_tobuffer(isc_uint32_t value, isc_buffer_t *target) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
1c3191528684f3dd93ebb122298c2f8ebfc6d397Mark Andrews if (value > 0xffff)
34b394b43e2207e8f8f3703f0402422121455638David Lawrence return (ISC_R_RANGE);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (region.length < 2)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence isc_buffer_putuint16(target, (isc_uint16_t)value);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafssonuint8_tobuffer(isc_uint32_t value, isc_buffer_t *target) {
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson isc_region_t region;
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson if (value > 0xff)
34b394b43e2207e8f8f3703f0402422121455638David Lawrence return (ISC_R_RANGE);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &region);
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson if (region.length < 1)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence isc_buffer_putuint8(target, (isc_uint8_t)value);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson}
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafssonstatic isc_result_t
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafssonname_tobuffer(dns_name_t *name, isc_buffer_t *target) {
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson isc_region_t r;
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson dns_name_toregion(name, &r);
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson return (isc_buffer_copyregion(target, &r));
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson}
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrewsstatic isc_uint32_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsuint32_fromregion(isc_region_t *region) {
2da53322f30495e9bcf30f3776def2da329d3343Mark Andrews isc_uint32_t value;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
035504dbd8ca5949e8380b860873b3385a4e61e5Mark Andrews REQUIRE(region->length >= 4);
c62d9ac65fe6e098e9e538ce5c9edeeb456115a4Ondřej Surý value = (isc_uint32_t)region->base[0] << 24;
c62d9ac65fe6e098e9e538ce5c9edeeb456115a4Ondřej Surý value |= (isc_uint32_t)region->base[1] << 16;
c62d9ac65fe6e098e9e538ce5c9edeeb456115a4Ondřej Surý value |= (isc_uint32_t)region->base[2] << 8;
c62d9ac65fe6e098e9e538ce5c9edeeb456115a4Ondřej Surý value |= (isc_uint32_t)region->base[3];
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return(value);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic isc_uint16_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsuint16_consume_fromregion(isc_region_t *region) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_uint16_t r = uint16_fromregion(region);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_region_consume(region, 2);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return r;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrewsstatic isc_uint16_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsuint16_fromregion(isc_region_t *region) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
035504dbd8ca5949e8380b860873b3385a4e61e5Mark Andrews REQUIRE(region->length >= 2);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return ((region->base[0] << 8) | region->base[1]);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafssonstatic isc_uint8_t
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafssonuint8_fromregion(isc_region_t *region) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson REQUIRE(region->length >= 1);
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson return (region->base[0]);
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson}
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic isc_uint8_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsuint8_consume_fromregion(isc_region_t *region) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_uint8_t r = uint8_fromregion(region);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_region_consume(region, 1);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return r;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsmem_tobuffer(isc_buffer_t *target, void *base, unsigned int length) {
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_region_t tr;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
8e73941f33fad57111142a62d99717abc001912eMark Andrews if (length == 0U)
8e73941f33fad57111142a62d99717abc001912eMark Andrews return (ISC_R_SUCCESS);
8e73941f33fad57111142a62d99717abc001912eMark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tr);
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington if (length > tr.length)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
7e9d637131516486630290d36c4c0db544cb700eMark Andrews if (tr.base != base)
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(tr.base, base, length);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_buffer_add(target, length);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews}
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic int
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewshexvalue(char value) {
d4422ec231e58b60693620cf298276e47f04f0ecMark Andrews const char *s;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence unsigned char c;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence c = (unsigned char)value;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence if (!isascii(c))
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (-1);
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence if (isupper(c))
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence c = tolower(c);
cbef026164ceabccb2e85403434b722d77f7b5eeMark Andrews if ((s = strchr(hexdigits, c)) == NULL)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (-1);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews return (int)(s - hexdigits);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrewsstatic int
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrewsdecvalue(char value) {
d4422ec231e58b60693620cf298276e47f04f0ecMark Andrews const char *s;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence /*
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence * isascii() is valid for full range of int values, no need to
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence * mask or cast.
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence */
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence if (!isascii(value))
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews return (-1);
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews if ((s = strchr(decdigits, value)) == NULL)
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews return (-1);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews return (int)(s - decdigits);
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews}
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsstatic const char atob_digits[86] =
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" \
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence "abcdefghijklmnopqrstu";
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews/*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Subroutines to convert between 8 bit binary bytes and printable ASCII.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Computes the number of bytes, and three kinds of simple checksums.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Incoming bytes are collected into 32-bit words, then printed in base 85:
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * exp(85,5) > exp(2,32)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * The ASCII characters used are between '!' and 'u';
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * 'z' encodes 32-bit zero; 'x' is used to mark the end of encoded data.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews *
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Originally by Paul Rutter (philabs!per) and Joe Orost (petsd!joe) for
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * the atob/btoa programs, released with the compress program, in mod.sources.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Modified by Mike Schwartz 8/19/86 for use in BIND.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Modified to be re-entrant 3/2/99.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsstruct state {
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews isc_int32_t Ceor;
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews isc_int32_t Csum;
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews isc_int32_t Crot;
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews isc_int32_t word;
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews isc_int32_t bcount;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews};
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews#define Ceor state->Ceor
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews#define Csum state->Csum
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews#define Crot state->Crot
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews#define word state->word
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews#define bcount state->bcount
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews#define times85(x) ((((((x<<2)+x)<<2)+x)<<2)+x)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t byte_atob(int c, isc_buffer_t *target,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews struct state *state);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t putbyte(int c, isc_buffer_t *, struct state *state);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t byte_btoa(int c, isc_buffer_t *, struct state *state);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence/*
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Decode ASCII-encoded byte c into binary representation and
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * place into *bufp, advancing bufp.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsbyte_atob(int c, isc_buffer_t *target, struct state *state) {
d4422ec231e58b60693620cf298276e47f04f0ecMark Andrews const char *s;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (c == 'z') {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (bcount != 0)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return(DNS_R_SYNTAX);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews else {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(putbyte(0, target, state));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(putbyte(0, target, state));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(putbyte(0, target, state));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(putbyte(0, target, state));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else if ((s = strchr(atob_digits, c)) != NULL) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (bcount == 0) {
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews word = (isc_int32_t)(s - atob_digits);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews ++bcount;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else if (bcount < 4) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews word = times85(word);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews word += (isc_int32_t)(s - atob_digits);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews ++bcount;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews word = times85(word);
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews word += (isc_int32_t)(s - atob_digits);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(putbyte((word >> 24) & 0xff, target, state));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(putbyte((word >> 16) & 0xff, target, state));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(putbyte((word >> 8) & 0xff, target, state));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(putbyte(word & 0xff, target, state));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews word = 0;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews bcount = 0;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return(DNS_R_SYNTAX);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return(ISC_R_SUCCESS);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews}
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence/*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Compute checksum info and place c into target.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsputbyte(int c, isc_buffer_t *target, struct state *state) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_region_t tr;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Ceor ^= c;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Csum += c;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Csum += 1;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if ((Crot & 0x80000000)) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Crot <<= 1;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Crot += 1;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Crot <<= 1;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Crot += c;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tr);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (tr.length < 1)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tr.base[0] = c;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_buffer_add(target, 1);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews}
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence/*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Read the ASCII-encoded data from inbuf, of length inbuflen, and convert
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * it into T_UNSPEC (binary data) in outbuf, not to exceed outbuflen bytes;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * outbuflen must be divisible by 4. (Note: this is because outbuf is filled
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * in 4 bytes at a time. If the actual data doesn't end on an even 4-byte
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * boundary, there will be no problem...it will be padded with 0 bytes, and
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * numbytes will indicate the correct number of bytes. The main point is
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * that since the buffer is filled in 4 bytes at a time, even if there is
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * not a full 4 bytes of data at the end, there has to be room to 0-pad the
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * data, so the buffer must be of size divisible by 4). Place the number of
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * output bytes in numbytes, and return a failure/success status.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsatob_tobuffer(isc_lex_t *lexer, isc_buffer_t *target) {
df8c9ee4819c97089664ccc035eb2aa7569034fdDavid Lawrence long oeor, osum, orot;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews struct state statebuf, *state= &statebuf;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_token_t token;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews char c;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews char *e;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Ceor = Csum = Crot = word = bcount = 0;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews while (token.value.as_textregion.length != 0) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if ((c = token.value.as_textregion.base[0]) == 'x') {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews break;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(byte_atob(c, target, state));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_textregion_consume(&token.value.as_textregion, 1);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Number of bytes.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
984d2bb9e5aaca7c946bc78354c12b1dd75ed00aMukund Sivaraman if ((token.value.as_ulong % 4) != 0U) {
984d2bb9e5aaca7c946bc78354c12b1dd75ed00aMukund Sivaraman unsigned long padding = 4 - (token.value.as_ulong % 4);
984d2bb9e5aaca7c946bc78354c12b1dd75ed00aMukund Sivaraman if (isc_buffer_usedlength(target) < padding)
984d2bb9e5aaca7c946bc78354c12b1dd75ed00aMukund Sivaraman return (DNS_R_SYNTAX);
984d2bb9e5aaca7c946bc78354c12b1dd75ed00aMukund Sivaraman isc_buffer_subtract(target, padding);
984d2bb9e5aaca7c946bc78354c12b1dd75ed00aMukund Sivaraman }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Checksum.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews oeor = strtol(DNS_AS_STR(token), &e, 16);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (*e != 0)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return (DNS_R_SYNTAX);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Checksum.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews osum = strtol(DNS_AS_STR(token), &e, 16);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (*e != 0)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return (DNS_R_SYNTAX);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Checksum.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews orot = strtol(DNS_AS_STR(token), &e, 16);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (*e != 0)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return (DNS_R_SYNTAX);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if ((oeor != Ceor) || (osum != Csum) || (orot != Crot))
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return(DNS_R_BADCKSUM);
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington return (ISC_R_SUCCESS);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews}
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence/*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Encode binary byte c into ASCII representation and place into *bufp,
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * advancing bufp.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsbyte_btoa(int c, isc_buffer_t *target, struct state *state) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_region_t tr;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tr);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Ceor ^= c;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Csum += c;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Csum += 1;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if ((Crot & 0x80000000)) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Crot <<= 1;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Crot += 1;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Crot <<= 1;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Crot += c;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews word <<= 8;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews word |= c;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (bcount == 3) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (word == 0) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (tr.length < 1)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tr.base[0] = 'z';
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_buffer_add(target, 1);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews register int tmp = 0;
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews register isc_int32_t tmpword = word;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (tmpword < 0) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Because some don't support u_long.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater tmp = 32;
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater tmpword -= (isc_int32_t)(85 * 85 * 85 * 85 * 32);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (tmpword < 0) {
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater tmp = 64;
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater tmpword -= (isc_int32_t)(85 * 85 * 85 * 85 * 32);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (tr.length < 5)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater tr.base[0] = atob_digits[(tmpword /
83ac7ce833930a5c6cb92ad9c04a58e775579e73Bob Halley (isc_int32_t)(85 * 85 * 85 * 85))
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews + tmp];
83ac7ce833930a5c6cb92ad9c04a58e775579e73Bob Halley tmpword %= (isc_int32_t)(85 * 85 * 85 * 85);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tr.base[1] = atob_digits[tmpword / (85 * 85 * 85)];
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tmpword %= (85 * 85 * 85);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tr.base[2] = atob_digits[tmpword / (85 * 85)];
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tmpword %= (85 * 85);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tr.base[3] = atob_digits[tmpword / 85];
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tmpword %= 85;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tr.base[4] = atob_digits[tmpword];
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_buffer_add(target, 5);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews bcount = 0;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews bcount += 1;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews}
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews/*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Encode the binary data from inbuf, of length inbuflen, into a
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * target. Return success/failure status
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsbtoa_totext(unsigned char *inbuf, int inbuflen, isc_buffer_t *target) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews int inc;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews struct state statebuf, *state = &statebuf;
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson char buf[sizeof("x 2000000000 ffffffff ffffffff ffffffff")];
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews Ceor = Csum = Crot = word = bcount = 0;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews for (inc = 0; inc < inbuflen; inbuf++, inc++)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(byte_btoa(*inbuf, target, state));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews while (bcount != 0)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(byte_btoa(0, target, state));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Put byte count and checksum information at end of buffer,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * delimited by 'x'
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
806c235ecf533b98d068b3f8df9d7abbe1e30cf9Mark Andrews snprintf(buf, sizeof(buf), "x %d %x %x %x", inbuflen, Ceor, Csum, Crot);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return (str_totext(buf, target));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews}
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrewsstatic void
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencedefault_fromtext_callback(dns_rdatacallbacks_t *callbacks, const char *fmt,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence ...)
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence{
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews va_list ap;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence UNUSED(callbacks);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews va_start(ap, fmt);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews vfprintf(stderr, fmt, ap);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews va_end(ap);
861cef13977886aca57ba95c2c93039b87bbbc43Brian Wellington fprintf(stderr, "\n");
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews}
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrewsstatic void
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrewsfromtext_warneof(isc_lex_t *lexer, dns_rdatacallbacks_t *callbacks) {
b6a0341bcb113e93bd0bc41a9f9a1fc117444da6Mark Andrews if (isc_lex_isfile(lexer) && callbacks != NULL) {
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews const char *name = isc_lex_getsourcename(lexer);
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews if (name == NULL)
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews name = "UNKNOWN";
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews (*callbacks->warn)(callbacks,
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews "%s:%lu: file does not end with newline",
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews name, isc_lex_getsourceline(lexer));
b6a0341bcb113e93bd0bc41a9f9a1fc117444da6Mark Andrews }
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews}
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewsstatic void
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrewswarn_badmx(isc_token_t *token, isc_lex_t *lexer,
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_rdatacallbacks_t *callbacks)
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews{
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews const char *file;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews unsigned long line;
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews if (lexer != NULL) {
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews file = isc_lex_getsourcename(lexer);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews line = isc_lex_getsourceline(lexer);
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater (*callbacks->warn)(callbacks, "%s:%u: warning: '%s': %s",
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews file, line, DNS_AS_STR(*token),
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews dns_result_totext(DNS_R_MXISADDRESS));
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews }
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews}
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsstatic void
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewswarn_badname(dns_name_t *name, isc_lex_t *lexer,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_rdatacallbacks_t *callbacks)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews{
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews const char *file;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews unsigned long line;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews char namebuf[DNS_NAME_FORMATSIZE];
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (lexer != NULL) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews file = isc_lex_getsourcename(lexer);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews line = isc_lex_getsourceline(lexer);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_name_format(name, namebuf, sizeof(namebuf));
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater (*callbacks->warn)(callbacks, "%s:%u: warning: %s: %s",
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews file, line, namebuf,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_result_totext(DNS_R_BADNAME));
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews }
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrewsstatic void
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromtext_error(void (*callback)(dns_rdatacallbacks_t *, const char *, ...),
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence dns_rdatacallbacks_t *callbacks, const char *name,
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence unsigned long line, isc_token_t *token, isc_result_t result)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews{
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (name == NULL)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews name = "UNKNOWN";
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (token != NULL) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews switch (token->type) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews case isc_tokentype_eol:
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence (*callback)(callbacks, "%s: %s:%lu: near eol: %s",
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews "dns_rdata_fromtext", name, line,
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_result_totext(result));
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews break;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews case isc_tokentype_eof:
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence (*callback)(callbacks, "%s: %s:%lu: near eof: %s",
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews "dns_rdata_fromtext", name, line,
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_result_totext(result));
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews break;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews case isc_tokentype_number:
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence (*callback)(callbacks, "%s: %s:%lu: near %lu: %s",
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews "dns_rdata_fromtext", name, line,
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews token->value.as_ulong,
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_result_totext(result));
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews break;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews case isc_tokentype_string:
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews case isc_tokentype_qstring:
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence (*callback)(callbacks, "%s: %s:%lu: near '%s': %s",
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews "dns_rdata_fromtext", name, line,
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews DNS_AS_STR(*token),
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_result_totext(result));
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews break;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews default:
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence (*callback)(callbacks, "%s: %s:%lu: %s",
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews "dns_rdata_fromtext", name, line,
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_result_totext(result));
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews break;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews }
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews } else {
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence (*callback)(callbacks, "dns_rdata_fromtext: %s:%lu: %s",
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews name, line, dns_result_totext(result));
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews }
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews}
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halleydns_rdatatype_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdata_covers(dns_rdata_t *rdata) {
47ed81386442f9db64f05ccb85c97256ecf27109Mukund Sivaraman if (rdata->type == dns_rdatatype_rrsig)
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews return (covers_rrsig(rdata));
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley return (covers_sig(rdata));
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley}
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
ebd68da027cfa8da0fb536c3db11bb88292f41c7Andreas Gustafssonisc_boolean_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdatatype_ismeta(dns_rdatatype_t type) {
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_META) != 0)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff return (ISC_TRUE);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff return (ISC_FALSE);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff}
ebd68da027cfa8da0fb536c3db11bb88292f41c7Andreas Gustafsson
ebd68da027cfa8da0fb536c3db11bb88292f41c7Andreas Gustafssonisc_boolean_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdatatype_issingleton(dns_rdatatype_t type) {
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graff if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_SINGLETON)
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graff != 0)
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graff return (ISC_TRUE);
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graff return (ISC_FALSE);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff}
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graffisc_boolean_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdatatype_notquestion(dns_rdatatype_t type) {
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_NOTQUESTION)
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff != 0)
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff return (ISC_TRUE);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff return (ISC_FALSE);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff}
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graffisc_boolean_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdatatype_questiononly(dns_rdatatype_t type) {
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_QUESTIONONLY)
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff != 0)
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff return (ISC_TRUE);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff return (ISC_FALSE);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff}
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graff
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrewsisc_boolean_t
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrewsdns_rdatatype_atparent(dns_rdatatype_t type) {
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_ATPARENT) != 0)
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews return (ISC_TRUE);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews return (ISC_FALSE);
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews}
0b09763c354ec91fb352b6b4cea383bd0195b2d8Mark Andrews
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graffisc_boolean_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdataclass_ismeta(dns_rdataclass_t rdclass) {
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff if (rdclass == dns_rdataclass_reserved0
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff || rdclass == dns_rdataclass_none
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff || rdclass == dns_rdataclass_any)
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff return (ISC_TRUE);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence return (ISC_FALSE); /* Assume it is not a meta class. */
f8aae502686e2448c48f56697c212a50e2a1cbaeAndreas Gustafsson}
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafsson
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafssonisc_boolean_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdatatype_isdnssec(dns_rdatatype_t type) {
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_DNSSEC) != 0)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff return (ISC_TRUE);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff return (ISC_FALSE);
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafsson}
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafsson
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafssonisc_boolean_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdatatype_iszonecutauth(dns_rdatatype_t type) {
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff if ((dns_rdatatype_attributes(type)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff & (DNS_RDATATYPEATTR_DNSSEC | DNS_RDATATYPEATTR_ZONECUTAUTH))
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff != 0)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff return (ISC_TRUE);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff return (ISC_FALSE);
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafsson}
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafssonisc_boolean_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdatatype_isknown(dns_rdatatype_t type) {
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_UNKNOWN)
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson == 0)
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson return (ISC_TRUE);
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson return (ISC_FALSE);
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson}
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉void
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉dns_rdata_exists(dns_rdata_t *rdata, dns_rdatatype_t type) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE(rdata != NULL);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE(DNS_RDATA_INITIALIZED(rdata));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->data = NULL;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->length = 0;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->flags = DNS_RDATA_UPDATE;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->type = type;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->rdclass = dns_rdataclass_any;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉}
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉void
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉dns_rdata_notexist(dns_rdata_t *rdata, dns_rdatatype_t type) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE(rdata != NULL);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE(DNS_RDATA_INITIALIZED(rdata));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->data = NULL;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->length = 0;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->flags = DNS_RDATA_UPDATE;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->type = type;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->rdclass = dns_rdataclass_none;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉}
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉void
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉dns_rdata_deleterrset(dns_rdata_t *rdata, dns_rdatatype_t type) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE(rdata != NULL);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE(DNS_RDATA_INITIALIZED(rdata));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->data = NULL;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->length = 0;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->flags = DNS_RDATA_UPDATE;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->type = type;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->rdclass = dns_rdataclass_any;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉}
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉void
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉dns_rdata_makedelete(dns_rdata_t *rdata) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE(rdata != NULL);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 rdata->rdclass = dns_rdataclass_none;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉}
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉const char *
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉dns_rdata_updateop(dns_rdata_t *rdata, dns_section_t section) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE(rdata != NULL);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE(DNS_RDATA_INITIALIZED(rdata));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 switch (section) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 case DNS_SECTION_PREREQUISITE:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 switch (rdata->rdclass) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 case dns_rdataclass_none:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 switch (rdata->type) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 case dns_rdatatype_any:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return ("domain doesn't exist");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 default:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return ("rrset doesn't exist");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 case dns_rdataclass_any:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 switch (rdata->type) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 case dns_rdatatype_any:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return ("domain exists");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 default:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return ("rrset exists (value independent)");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 default:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return ("rrset exists (value dependent)");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 case DNS_SECTION_UPDATE:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 switch (rdata->rdclass) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 case dns_rdataclass_none:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return ("delete");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 case dns_rdataclass_any:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 switch (rdata->type) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 case dns_rdatatype_any:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return ("delete all rrsets");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 default:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return ("delete rrset");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 default:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return ("add");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return ("invalid");
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉}