rdata.c revision 6d12fdf96621801e80f3f4c2a8a569fe48766a20
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 1998, 1999, 2000 Internet Software Consortium.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * SOFTWARE.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence/* $Id: rdata.c,v 1.98 2000/06/01 18:25:34 tale Exp $ */
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <config.h>
de153390f5a1f6d4fa86af91d4cae772d9846ca0Mark Andrews#include <ctype.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff
822f6cdabb1edd44472c7a758b5cae71376fa9beBrian Wellington#include <isc/base64.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <isc/lex.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/mem.h>
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence#include <isc/string.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>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/keyflags.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
eb6bd543c7d072efdca509eb17f8f301c1467b53Mark Andrews#define RETERR(x) do { \
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence isc_result_t _r = (x); \
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence if (_r != ISC_R_SUCCESS) \
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence return (_r); \
eb6bd543c7d072efdca509eb17f8f301c1467b53Mark Andrews } while (0)
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define ARGS_FROMTEXT int rdclass, int type, \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence isc_lex_t *lexer, dns_name_t *origin, \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence isc_boolean_t downcase, isc_buffer_t *target
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define ARGS_TOTEXT dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence isc_buffer_t *target
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define ARGS_FROMWIRE int rdclass, int type, \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence isc_buffer_t *source, dns_decompress_t *dctx, \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence isc_boolean_t downcase, 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
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#define ARGS_FROMSTRUCT int rdclass, int 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
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson/*
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * 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 {
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson dns_name_t *origin; /* Current origin, or NULL. */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson unsigned int flags; /* DNS_STYLEFLAG_* */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson unsigned int width; /* Width of rdata column. */
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence const char *linebreak; /* Line break string. */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson} dns_rdata_textctx_t;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencetxt_totext(isc_region_t *source, 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
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
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
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencegettoken(isc_lex_t *lexer, isc_token_t *token, isc_tokentype_t expect,
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_boolean_t eol);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencemem_tobuffer(isc_buffer_t *target, void *base, unsigned int length);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic int
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencecompare_region(isc_region_t *r1, isc_region_t *r2);
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
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencedefault_fromtext_callback(dns_rdatacallbacks_t *callbacks, const char *, ...);
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
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
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)
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews 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) {
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews void *new;
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews if (mctx == NULL)
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews return (source);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews new = isc_mem_allocate(mctx, length);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews if (new != NULL)
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews memcpy(new, source, length);
f6407f9a0b890bebbfd5f738d9c4aef3d3315fe9Michael Graff
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews return (new);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews}
2002be4f65776451676df6ee21a2e28f52bcad6dMark 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
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews#define RCODENAMES \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews /* standard rcodes */ \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews { dns_rcode_noerror, "NOERROR", 0}, \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews { dns_rcode_formerr, "FORMERR", 0}, \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews { dns_rcode_servfail, "SERVFAIL", 0}, \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews { dns_rcode_nxdomain, "NXDOMAIN", 0}, \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews { dns_rcode_notimp, "NOTIMP", 0}, \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews { dns_rcode_refused, "REFUSED", 0}, \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews { dns_rcode_yxdomain, "YXDOMAIN", 0}, \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews { dns_rcode_yxrrset, "YXRRSET", 0}, \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews { dns_rcode_nxrrset, "NXRRSET", 0}, \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews { dns_rcode_notauth, "NOTAUTH", 0}, \
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington { dns_rcode_notzone, "NOTZONE", 0},
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington#define ERCODENAMES \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews /* extended rcodes */ \
613991eef6bb79b9703382aff26cddd0281da915Bob Halley { dns_rcode_badvers, "BADVERS", 0}, \
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews { 0, NULL, 0 }
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington#define TSIGRCODENAMES \
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington /* extended rcodes */ \
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington { dns_tsigerror_badsig, "BADSIG", 0}, \
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington { dns_tsigerror_badkey, "BADKEY", 0}, \
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington { dns_tsigerror_badtime, "BADTIME", 0}, \
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington { dns_tsigerror_badmode, "BADMODE", 0}, \
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington { dns_tsigerror_badname, "BADNAME", 0}, \
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington { dns_tsigerror_badalg, "BADALG", 0}, \
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington { 0, NULL, 0 }
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews#define CERTNAMES \
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews { 1, "SKIX", 0}, \
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews { 2, "SPKI", 0}, \
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews { 3, "PGP", 0}, \
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews { 253, "URI", 0}, \
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews { 254, "OID", 0}, \
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews { 0, NULL, 0}
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson/* RFC2535 section 7 */
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews#define SECALGNAMES \
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews { 1, "RSAMD5", 0 }, \
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews { 2, "DH", 0 }, \
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews { 3, "DSA", 0 }, \
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews { 4, "ECC", 0 }, \
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews { 252, "INDIRECT", 0 }, \
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews { 253, "PRIVATEDNS", 0 }, \
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews { 254, "PRIVATEOID", 0 }, \
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews { 0, NULL, 0}
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson/* RFC2535 section 7.1 */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson#define SECPROTONAMES \
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { 0, "NONE", 0 }, \
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { 1, "TLS", 0 }, \
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { 2, "EMAIL", 0 }, \
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { 3, "DNSSEC", 0 }, \
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { 4, "IPSEC", 0 }, \
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { 255, "ALL", 0 }, \
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { 0, NULL, 0}
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graffstruct tbl {
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews unsigned int value;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence const char *name;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence int flags;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff};
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellingtonstatic struct tbl rcodes[] = { RCODENAMES ERCODENAMES };
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellingtonstatic struct tbl tsigrcodes[] = { RCODENAMES TSIGRCODENAMES };
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graffstatic struct tbl certs[] = { CERTNAMES };
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graffstatic struct tbl secalgs[] = { SECALGNAMES };
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graffstatic struct tbl secprotos[] = { SECPROTONAMES };
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafssonstatic struct keyflag {
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence const char *name;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson unsigned int value;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson unsigned int mask;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson} keyflags[] = {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "NOCONF", 0x4000, 0xC000 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "NOAUTH", 0x8000, 0xC000 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "NOKEY", 0xC000, 0xC000 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "FLAG2", 0x2000, 0x2000 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "EXTEND", 0x1000, 0x1000 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "FLAG4", 0x0800, 0x0800 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "FLAG5", 0x0400, 0x0400 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "USER", 0x0000, 0x0300 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "ZONE", 0x0100, 0x0300 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "HOST", 0x0200, 0x0300 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "NTYP3", 0x0300, 0x0300 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "FLAG8", 0x0080, 0x0080 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "FLAG9", 0x0040, 0x0040 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "FLAG10", 0x0020, 0x0020 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "FLAG11", 0x0010, 0x0010 },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG0", 0x0000, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG1", 0x0001, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG2", 0x0002, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG3", 0x0003, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG4", 0x0004, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG5", 0x0005, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG6", 0x0006, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG7", 0x0007, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG8", 0x0008, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG9", 0x0009, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG10", 0x000A, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG11", 0x000B, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG12", 0x000C, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG13", 0x000D, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG14", 0x000E, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { "SIG15", 0x000F, 0x000F },
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson { NULL, 0, 0 }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson};
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark 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;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_LINK_INIT(rdata, link);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews /* ISC_LIST_INIT(rdata->list); */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark 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);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(rdata1->data != NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(rdata2->data != NULL);
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);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews result = compare_region(&r1, &r2);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark 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{
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(rdata != NULL);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(r != NULL);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rdata->data = r->base;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rdata->length = r->length;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley rdata->rdclass = rdclass;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews rdata->type = type;
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);
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,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews dns_decompress_t *dctx, isc_boolean_t downcase,
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;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(dctx != NULL);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ss = *source;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews st = *target;
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews /* XXX */
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff region.base = (unsigned char *)(target->base) + target->used;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews FROMWIRESWITCH
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (use_default)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews (void)NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark 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
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (rdata && result == ISC_R_SUCCESS) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews region.length = target->used - st.used;
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,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews 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);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews st = *target;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews TOWIRESWITCH
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (use_default) {
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tr);
f0a5bb8f86631ce638cb2b6c65bbb9bcf9b0cdc0Bob Halley if (tr.length < rdata->length)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
f0a5bb8f86631ce638cb2b6c65bbb9bcf9b0cdc0Bob Halley memcpy(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
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,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews dns_name_t *origin, isc_boolean_t downcase,
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_boolean_t use_default = ISC_FALSE;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_token_t token;
f305d86668bfd4d4727c3e0f70e7e97a2fa1b772Bob Halley unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF |
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson ISC_LEXOPT_DNSMULTILINE | ISC_LEXOPT_ESCAPE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews char *name;
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence unsigned long line;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence void (*callback)(dns_rdatacallbacks_t *, const char *, ...);
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews isc_result_t iresult;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence REQUIRE(origin == NULL || dns_name_isabsolute(origin) == ISC_TRUE);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews st = *target;
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff region.base = (unsigned char *)(target->base) + target->used;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews FROMTEXTSWITCH
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (use_default)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews (void)NULL;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (callbacks == NULL)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews callback = NULL;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews else
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews callback = callbacks->error;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (callback == NULL)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews callback = default_fromtext_callback;
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);
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews iresult = isc_lex_gettoken(lexer, options, &token);
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews if (iresult != ISC_R_SUCCESS) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_SUCCESS) {
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews switch (iresult) {
035504dbd8ca5949e8380b860873b3385a4e61e5Mark Andrews case ISC_R_NOMEMORY:
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = ISC_R_NOMEMORY;
035504dbd8ca5949e8380b860873b3385a4e61e5Mark Andrews break;
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews case ISC_R_NOSPACE:
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = ISC_R_NOSPACE;
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews break;
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews default:
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
c0d0a59d1b665423b8a0d1829d0f0da121cb3473Andreas Gustafsson "isc_lex_gettoken() failed: %s",
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews isc_result_totext(result));
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = ISC_R_UNEXPECTED;
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews break;
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews }
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews }
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;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews } else
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews break;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews } while (1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (rdata != NULL && result == ISC_R_SUCCESS) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews region.length = target->used - st.used;
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
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;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
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 */
f8aae502686e2448c48f56697c212a50e2a1cbaeAndreas Gustafsson if (rdata->length == 0)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
f8aae502686e2448c48f56697c212a50e2a1cbaeAndreas Gustafsson
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews TOTEXTSWITCH
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (use_default)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews (void)NULL;
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{
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Set up formatting options for single-line output.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson dns_rdata_textctx_t tctx;
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,
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson char *linebreak, isc_buffer_t *target)
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson{
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Set up formatting options for formatted output.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson dns_rdata_textctx_t tctx;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson tctx.origin = origin;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson tctx.flags = flags;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson if ((flags & DNS_STYLEFLAG_MULTILINE) != 0) {
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson tctx.width = width;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson tctx.linebreak = linebreak;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson } else {
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson tctx.width = 60; /* Used for base64 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;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
19d365e4448f1782611280b020987988b7ac3210Mark Andrews REQUIRE(source != NULL);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff region.base = (unsigned char *)(target->base) + target->used;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews st = *target;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews FROMSTRUCTSWITCH
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (use_default)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews (void)NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (rdata != NULL && result == ISC_R_SUCCESS) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews region.length = target->used - st.used;
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);
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);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley ADDITIONALDATASWITCH
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (use_default)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley (void)NULL;
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;
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);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley DIGESTSWITCH
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley if (use_default)
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley (void)NULL;
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley return (result);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley}
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
6324997211a5e2d82528dcde98e8981190a35faeMichael Graffunsigned int
6324997211a5e2d82528dcde98e8981190a35faeMichael Graffdns_rdatatype_attributes(dns_rdatatype_t type)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff{
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff if (type > 255)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff return (DNS_RDATATYPEATTR_UNKNOWN);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff return (typeattr[type].flags);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff}
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson#define NUMBERSIZE sizeof("037777777777") /* 2^32-1 octal + NUL */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafssondns_mnemonic_fromtext(unsigned int *valuep, isc_textregion_t *source,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson struct tbl *table, unsigned int max)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson{
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson int i;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
88ba491496daf4463a2c898be8a6c47775a6d048Mark Andrews if (isdigit(source->base[0] & 0xff) &&
88ba491496daf4463a2c898be8a6c47775a6d048Mark Andrews source->length <= NUMBERSIZE - 1) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson unsigned int n;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson char *e;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson char buffer[NUMBERSIZE];
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson /*
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * We have a potential number. Try to parse it with strtoul().
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * strtoul() requires null termination, so we must make
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * a copy.
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson strncpy(buffer, source->base, NUMBERSIZE);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson INSIST(buffer[source->length] == '\0');
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson n = strtoul(buffer, &e, 10);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (*e == 0) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (n > max)
34b394b43e2207e8f8f3703f0402422121455638David Lawrence return (ISC_R_RANGE);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson *valuep = n;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * It was not a number after all; fall through.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson for (i = 0; table[i].name != NULL; i++) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson unsigned int n;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson n = strlen(table[i].name);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (n == source->length &&
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson strncasecmp(source->base, table[i].name, n) == 0) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson *valuep = table[i].value;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson return (DNS_R_UNKNOWN);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson}
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafssondns_mnemonic_totext(unsigned int value, isc_buffer_t *target,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson struct tbl *table)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson{
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson int i = 0;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson char buf[sizeof "4294967296"];
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson while (table[i].name != NULL) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (table[i].value == value) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson return (str_totext(table[i].name, target));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson i++;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson sprintf(buf, "%u", value);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson return (str_totext(buf, target));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson}
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff/*
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * This uses lots of hard coded values, but how often do we actually
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * add classes?
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdataclass_fromtext(dns_rdataclass_t *classp, isc_textregion_t *source) {
16996a04884731d647f43a5eb54f678581f09f68David Lawrence unsigned int attrs;
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews
16996a04884731d647f43a5eb54f678581f09f68David Lawrence /*
16996a04884731d647f43a5eb54f678581f09f68David Lawrence * Note: attrs is set and then used in the bit test with RESERVED
16996a04884731d647f43a5eb54f678581f09f68David Lawrence * because testing "(flags & RESERVED) != 0" generates
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence * warnings on IRIX about how the test always has the same value
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence * because it is all constants.
16996a04884731d647f43a5eb54f678581f09f68David Lawrence */
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence#define COMPARE(string, flags, type) \
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence if (((sizeof(string) - 1) == source->length) \
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence && (strcasecmp(source->base, string) == 0)) { \
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence *classp = type; \
16996a04884731d647f43a5eb54f678581f09f68David Lawrence attrs = flags; \
16996a04884731d647f43a5eb54f678581f09f68David Lawrence if ((attrs & RESERVED) != 0) \
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff return (ISC_R_NOTIMPLEMENTED); \
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff return (ISC_R_SUCCESS); \
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff }
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
fc024be774c7cdee938da018aa3994be746e36deDavid Lawrence switch (tolower((unsigned char)source->base[0])) {
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case 'a':
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff COMPARE("any", META, dns_rdataclass_any);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff break;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case 'c':
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff COMPARE("chaos", 0, dns_rdataclass_chaos);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff break;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case 'h':
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff COMPARE("hs", 0, dns_rdataclass_hs);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff break;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case 'i':
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff COMPARE("in", 0, dns_rdataclass_in);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff break;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case 'n':
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff COMPARE("none", META, dns_rdataclass_none);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff break;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case 'r':
16996a04884731d647f43a5eb54f678581f09f68David Lawrence COMPARE("reserved0", META|RESERVED, dns_rdataclass_reserved0);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff break;
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews }
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff#undef COMPARE
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews return (DNS_R_UNKNOWN);
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews}
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdataclass_totext(dns_rdataclass_t rdclass, isc_buffer_t *target) {
16996a04884731d647f43a5eb54f678581f09f68David Lawrence char buf[sizeof("RDCLASS4294967296")];
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff switch (rdclass) {
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case dns_rdataclass_any:
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff return (str_totext("ANY", target));
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case dns_rdataclass_chaos:
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff return (str_totext("CHAOS", target));
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case dns_rdataclass_hs:
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff return (str_totext("HS", target));
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case dns_rdataclass_in:
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff return (str_totext("IN", target));
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case dns_rdataclass_none:
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff return (str_totext("NONE", target));
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff case dns_rdataclass_reserved0:
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff return (str_totext("RESERVED0", target));
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff default:
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff sprintf(buf, "RDCLASS%u", rdclass);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff return (str_totext(buf, target));
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff }
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff}
79eec6934923f97a61edb8dbe2641ce56dc30085Bob Halley
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 /*
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff * 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 */
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff RDATATYPE_FROMTEXT_SW(hash, source->base, typep);
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews
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) {
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff char buf[sizeof "RRTYPE4294967296"];
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff if (type > 255) {
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff sprintf(buf, "RRTYPE%u", type);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff return (str_totext(buf, target));
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff }
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff return (str_totext(typeattr[type].name, target));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews}
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews
79eec6934923f97a61edb8dbe2641ce56dc30085Bob Halley/* XXXRTH Should we use a hash table here? */
79eec6934923f97a61edb8dbe2641ce56dc30085Bob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrewsdns_rcode_fromtext(dns_rcode_t *rcodep, isc_textregion_t *source) {
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington unsigned int value;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington RETERR(dns_mnemonic_fromtext(&value, source, rcodes, 0xffff));
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington *rcodep = value;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington return (ISC_R_SUCCESS);
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews}
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrewsdns_rcode_totext(dns_rcode_t rcode, isc_buffer_t *target) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson return (dns_mnemonic_totext(rcode, target, rcodes));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews}
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellingtonisc_result_t
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellingtondns_tsigrcode_fromtext(dns_rcode_t *rcodep, isc_textregion_t *source) {
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington unsigned int value;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington RETERR(dns_mnemonic_fromtext(&value, source, tsigrcodes, 0xffff));
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington *rcodep = value;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington return (ISC_R_SUCCESS);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington}
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellingtonisc_result_t
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellingtondns_tsigrcode_totext(dns_rcode_t rcode, isc_buffer_t *target) {
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington return (dns_mnemonic_totext(rcode, target, tsigrcodes));
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington}
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrewsdns_cert_fromtext(dns_cert_t *certp, isc_textregion_t *source) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson unsigned int value;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson RETERR(dns_mnemonic_fromtext(&value, source, certs, 0xffff));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson *certp = value;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson}
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafssondns_cert_totext(dns_cert_t cert, isc_buffer_t *target) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson return (dns_mnemonic_totext(cert, target, certs));
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews}
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafssondns_secalg_fromtext(dns_secalg_t *secalgp, isc_textregion_t *source) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson unsigned int value;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson RETERR(dns_mnemonic_fromtext(&value, source, secalgs, 0xff));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson *secalgp = value;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson}
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafssondns_secalg_totext(dns_secalg_t secalg, isc_buffer_t *target) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson return (dns_mnemonic_totext(secalg, target, secalgs));
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews}
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafssondns_secproto_fromtext(dns_secproto_t *secprotop, isc_textregion_t *source) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson unsigned int value;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson RETERR(dns_mnemonic_fromtext(&value, source, secprotos, 0xff));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson *secprotop = value;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson}
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafssondns_secproto_totext(dns_secproto_t secproto, isc_buffer_t *target) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson return (dns_mnemonic_totext(secproto, target, secprotos));
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews}
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafssondns_keyflags_fromtext(dns_keyflags_t *flagsp, isc_textregion_t *source)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson{
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson char *text, *end;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson unsigned int value, mask;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
88ba491496daf4463a2c898be8a6c47775a6d048Mark Andrews if (isdigit(source->base[0] & 0xff) &&
88ba491496daf4463a2c898be8a6c47775a6d048Mark Andrews source->length <= NUMBERSIZE - 1) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson unsigned int n;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson char *e;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson char buffer[NUMBERSIZE];
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson /*
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * We have a potential number. Try to parse it with strtoul().
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * strtoul() requires null termination, so we must make
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * a copy.
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson strncpy(buffer, source->base, NUMBERSIZE);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson INSIST(buffer[source->length] == '\0');
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson n = strtoul(buffer, &e, 0); /* Allow hex/octal. */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (*e == 0) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (n > 0xffff)
34b394b43e2207e8f8f3703f0402422121455638David Lawrence return (ISC_R_RANGE);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson *flagsp = n;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson /* It was not a number after all; fall through. */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson text = source->base;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson end = source->base + source->length;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson value = mask = 0;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson while (text < end) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson struct keyflag *p;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson unsigned int len;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson char *delim = memchr(text, '|', end - text);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (delim != NULL)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson len = delim - text;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson else
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson len = end - text;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson for (p = keyflags; p->name != NULL; p++) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (strncasecmp(p->name, text, len) == 0)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson break;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (p->name == NULL)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson return (DNS_R_UNKNOWN);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson value |= p->value;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson#ifdef notyet
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if ((mask & p->mask) != 0)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson warn("overlapping key flags");
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson#endif
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson mask |= p->mask;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson text += len;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (delim != NULL)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson text++; /* Skip "|" */
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson *flagsp = value;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews}
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
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
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewstxt_totext(isc_region_t *source, 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);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (tl < 1)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *tp++ = '"';
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews tl--;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews while (n--) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (*sp < 0x20 || *sp > 0x7f) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (tl < 4)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews sprintf(tp, "\\%03u", *sp++);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews tp += 4;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews tl -= 4;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews continue;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (*sp == 0x22 || *sp == 0x3b || *sp == 0x5c) {
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 }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (tl < 1)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *tp++ = '"';
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews tl--;
fe47f41b13620bfafc4f8cf65d5df24f1e568764Bob Halley isc_buffer_add(target, 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) {
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews 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;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (nrem == 0)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews *t++ = c;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews nrem--;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews }
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (escape)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews return (DNS_R_SYNTAX);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews *tregion.base = 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)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return(ISC_R_UNEXPECTEDEND);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews n = *sregion.base + 1;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (n > sregion.length)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDEND);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tregion);
bfb2a81b65579882a80855c279cedc45aebd62e8Mark Andrews if (n > tregion.length)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews memcpy(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
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);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (l1 == l2)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews goto return_false;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark 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
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews memcpy(region.base, source, l);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_add(target, l);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
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) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned long value;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
035504dbd8ca5949e8380b860873b3385a4e61e5Mark Andrews REQUIRE(region->length >= 4);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews value = region->base[0] << 24;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews value |= region->base[1] << 16;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews value |= region->base[2] << 8;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews value |= region->base[3];
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return(value);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrewsstatic isc_uint16_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsuint16_fromregion(isc_region_t *region) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
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) {
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson REQUIRE(region->length >= 1);
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson return (region->base[0]);
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson}
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsgettoken(isc_lex_t *lexer, isc_token_t *token, isc_tokentype_t expect,
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews isc_boolean_t eol)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews{
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews unsigned int options = ISC_LEXOPT_EOL | ISC_LEXOPT_EOF |
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson ISC_LEXOPT_DNSMULTILINE | ISC_LEXOPT_ESCAPE;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews isc_result_t result;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
2192b4497348ccab94ca6f3f779cec399c72a8efMark Andrews if (expect == isc_tokentype_qstring)
2192b4497348ccab94ca6f3f779cec399c72a8efMark Andrews options |= ISC_LEXOPT_QSTRING;
25870d4a37ab4bc8e675502b08335200167cc044Bob Halley else if (expect == isc_tokentype_number)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews options |= ISC_LEXOPT_NUMBER;
25870d4a37ab4bc8e675502b08335200167cc044Bob Halley result = isc_lex_gettoken(lexer, options, token);
25870d4a37ab4bc8e675502b08335200167cc044Bob Halley switch (result) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews case ISC_R_SUCCESS:
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews break;
035504dbd8ca5949e8380b860873b3385a4e61e5Mark Andrews case ISC_R_NOMEMORY:
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOMEMORY);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews case ISC_R_NOSPACE:
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews default:
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
c0d0a59d1b665423b8a0d1829d0f0da121cb3473Andreas Gustafsson "isc_lex_gettoken() failed: %s",
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews isc_result_totext(result));
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTED);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews }
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if (eol && ((token->type == isc_tokentype_eol) ||
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews (token->type == isc_tokentype_eof)))
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
2192b4497348ccab94ca6f3f779cec399c72a8efMark Andrews if (token->type == isc_tokentype_string &&
2192b4497348ccab94ca6f3f779cec399c72a8efMark Andrews expect == isc_tokentype_qstring)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if (token->type != expect) {
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_lex_ungettoken(lexer, token);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if (token->type == isc_tokentype_eol ||
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews token->type == isc_tokentype_eof)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDEND);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDTOKEN);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews}
44a966dff66061ac3f266c6b451a70733eb78e82Mark 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
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tr);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if (length > tr.length)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews memcpy(tr.base, base, length);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_buffer_add(target, length);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews}
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsstatic int
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewscompare_region(isc_region_t *r1, isc_region_t *r2) {
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews unsigned int l;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews int result;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews l = (r1->length < r2->length) ? r1->length : r2->length;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if ((result = memcmp(r1->base, r2->base, l)) != 0)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return ((result < 0) ? -1 : 1);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews else
904294c0c952227f7778fd0ba2ccea08c097b872Mark Andrews return ((r1->length == r2->length) ? 0 :
904294c0c952227f7778fd0ba2ccea08c097b872Mark Andrews (r1->length < r2->length) ? -1 : 1);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic int
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewshexvalue(char value) {
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews 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);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if ((s = strchr(hexdigits, value)) == NULL)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (-1);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews return (s - hexdigits);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews}
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrewsstatic int
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrewsdecvalue(char value) {
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews 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);
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews return (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/*
8abddcd3f24476b945419659e7cb73bcb970886bDavid 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) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews 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) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews word = s - atob_digits;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews ++bcount;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else if (bcount < 4) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews word = times85(word);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews word += s - atob_digits;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews ++bcount;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews word = times85(word);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews word += 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
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, 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 */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if ((token.value.as_ulong % 4) != 0)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_buffer_subtract(target, 4 - (token.value.as_ulong % 4));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Checksum.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
df8c9ee4819c97089664ccc035eb2aa7569034fdDavid Lawrence oeor = strtol(token.value.as_pointer, &e, 16);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (*e != 0)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return (DNS_R_SYNTAX);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Checksum.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
df8c9ee4819c97089664ccc035eb2aa7569034fdDavid Lawrence osum = strtol(token.value.as_pointer, &e, 16);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (*e != 0)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return (DNS_R_SYNTAX);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Checksum.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
df8c9ee4819c97089664ccc035eb2aa7569034fdDavid Lawrence orot = strtol(token.value.as_pointer, &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);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff 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;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (tmpword < 0) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Because some don't support u_long.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tmp = 32;
83ac7ce833930a5c6cb92ad9c04a58e775579e73Bob Halley tmpword -= (isc_int32_t)(85 * 85 * 85 * 85 * 32);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (tmpword < 0) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tmp = 64;
83ac7ce833930a5c6cb92ad9c04a58e775579e73Bob Halley tmpword -= (isc_int32_t)(85 * 85 * 85 * 85 * 32);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (tr.length < 5)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews 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;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews 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));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews while (bcount != 0)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews RETERR(byte_btoa(0, target, state));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Put byte count and checksum information at end of buffer,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * delimited by 'x'
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews sprintf(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);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews}
82d05588933a3c765aa8518fe455d6477d640b99Mark 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,
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews (char *)token->value.as_pointer,
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) {
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
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graffisc_boolean_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencedns_rdataclass_ismeta(dns_rdataclass_t rdclass) {
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff REQUIRE(rdclass < 65536);
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}
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson