]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- separate ldns into core ldns inside ldns/ subdirectory. No more
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 31 Oct 2013 15:09:26 +0000 (15:09 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 31 Oct 2013 15:09:26 +0000 (15:09 +0000)
  --with-ldns is needed and unbound does not rely on libldns.

git-svn-id: file:///svn/unbound/trunk@2998 be551aaa-1e26-0410-a405-d3ace91eadb9

268 files changed:
Makefile.in
compat/strlcat.c [new file with mode: 0644]
config.h.in
configure
configure.ac
daemon/cachedump.c
daemon/daemon.c
daemon/remote.c
daemon/stats.c
daemon/stats.h
daemon/unbound.c
daemon/worker.c
doc/Changelog
iterator/iter_delegpt.c
iterator/iter_fwd.c
iterator/iter_hints.c
iterator/iter_priv.c
iterator/iter_priv.h
iterator/iter_resptype.c
iterator/iter_scrub.c
iterator/iter_scrub.h
iterator/iter_utils.c
iterator/iter_utils.h
iterator/iterator.c
ldns/keyraw.c [new file with mode: 0644]
ldns/keyraw.h [new file with mode: 0644]
ldns/parse.c [new file with mode: 0644]
ldns/parse.h [new file with mode: 0644]
ldns/parseutil.c [new file with mode: 0644]
ldns/parseutil.h [new file with mode: 0644]
ldns/pkthdr.h [new file with mode: 0644]
ldns/rrdef.c [new file with mode: 0644]
ldns/rrdef.h [new file with mode: 0644]
ldns/sbuffer.c [new file with mode: 0644]
ldns/sbuffer.h [new file with mode: 0644]
ldns/str2wire.c [new file with mode: 0644]
ldns/str2wire.h [new file with mode: 0644]
ldns/wire2str.c [new file with mode: 0644]
ldns/wire2str.h [new file with mode: 0644]
libunbound/context.c
libunbound/context.h
libunbound/libunbound.c
libunbound/libworker.c
libunbound/libworker.h
services/cache/dns.c
services/cache/infra.c
services/cache/rrset.c
services/listen_dnsport.c
services/listen_dnsport.h
services/localzone.c
services/localzone.h
services/mesh.c
services/mesh.h
services/outside_network.c
services/outside_network.h
smallapp/unbound-anchor.c
smallapp/unbound-checkconf.c
smallapp/unbound-host.c
smallapp/worker_cb.c
testcode/asynclook.c
testcode/delayer.c
testcode/fake_event.c
testcode/harvest.c [deleted file]
testcode/ldns-testpkts.c [deleted file]
testcode/perf.c
testcode/pktview.c
testcode/readhex.c
testcode/readhex.h
testcode/replay.c
testcode/replay.h
testcode/signit.c
testcode/streamtcp.c
testcode/testbound.c
testcode/testpkts.c [new file with mode: 0644]
testcode/testpkts.h [moved from testcode/ldns-testpkts.h with 82% similarity]
testcode/unitanchor.c
testcode/unitdname.c
testcode/unitmain.c
testcode/unitmsgparse.c
testcode/unitneg.c
testcode/unitverify.c
testdata/autotrust_init.rpl
testdata/autotrust_init_ds.rpl
testdata/autotrust_init_fail.rpl
testdata/autotrust_init_failsig.rpl
testdata/autotrust_init_sigs.rpl
testdata/autotrust_init_zsk.rpl
testdata/autotrust_probefail.rpl
testdata/autotrust_probefailsig.rpl
testdata/autotrust_revtp.rpl
testdata/autotrust_revtp_read.rpl
testdata/autotrust_revtp_use.rpl
testdata/autotrust_valid_use.rpl
testdata/black_data.rpl
testdata/black_dnskey.rpl
testdata/black_ds.rpl
testdata/black_ds_entry.rpl
testdata/black_ent.rpl
testdata/black_key_entry.rpl
testdata/black_prime.rpl
testdata/black_prime_entry.rpl
testdata/dlv_anchor.rpl
testdata/dlv_ask_higher.rpl
testdata/dlv_below_ta.rpl
testdata/dlv_delegation.rpl
testdata/dlv_ds_lookup.rpl
testdata/dlv_insecure.rpl
testdata/dlv_insecure_negcache.rpl
testdata/dlv_keyretry.rpl
testdata/dlv_negnx.rpl
testdata/dlv_optout.rpl
testdata/dlv_unused.rpl
testdata/domain_insec_dlv.rpl
testdata/domain_insec_ds.rpl
testdata/fwddlv_parse.rpl
testdata/iter_class_any.rpl
testdata/iter_emptydp.rpl
testdata/iter_emptydp_for_glue.rpl
testdata/iter_primenoglue.rpl
testdata/local_nodefault.rpl
testdata/local_transparent_sametype.rpl
testdata/local_typetransparent.rpl
testdata/net_signed_servfail.rpl
testdata/nomem_cnametopos.rpl
testdata/test_sigs.rsasha256_draft
testdata/val_anchor_nx.rpl
testdata/val_anchor_nx_nosig.rpl
testdata/val_ans_dsent.rpl
testdata/val_ans_nx.rpl
testdata/val_any.rpl
testdata/val_any_cname.rpl
testdata/val_any_dname.rpl
testdata/val_cname_loop1.rpl
testdata/val_cname_loop2.rpl
testdata/val_cnameinsectopos.rpl
testdata/val_cnamenx_dblnsec.rpl
testdata/val_cnamenx_rcodenx.rpl
testdata/val_cnameqtype.rpl
testdata/val_cnametocloser.rpl
testdata/val_cnametocloser_nosig.rpl
testdata/val_cnametocnamewctoposwc.rpl
testdata/val_cnametodname.rpl
testdata/val_cnametodnametocnametopos.rpl
testdata/val_cnametoinsecure.rpl
testdata/val_cnametonodata.rpl
testdata/val_cnametonodata_nonsec.rpl
testdata/val_cnametonsec.rpl
testdata/val_cnametonx.rpl
testdata/val_cnametooptin.rpl
testdata/val_cnametooptout.rpl
testdata/val_cnametopos.rpl
testdata/val_cnametoposnowc.rpl
testdata/val_cnametoposwc.rpl
testdata/val_cnamewctonodata.rpl
testdata/val_cnamewctonx.rpl
testdata/val_cnamewctoposwc.rpl
testdata/val_dnametoolong.rpl
testdata/val_dnametopos.rpl
testdata/val_dnametoposwc.rpl
testdata/val_dnamewc.rpl
testdata/val_ds_afterprime.rpl
testdata/val_ds_cname.rpl
testdata/val_ds_cnamesub.rpl
testdata/val_ds_gost.crpl
testdata/val_ds_gost_downgrade.crpl
testdata/val_ds_sha2.crpl
testdata/val_ds_sha2_downgrade.crpl
testdata/val_dsnsec.rpl
testdata/val_entds.rpl
testdata/val_faildnskey.rpl
testdata/val_faildnskey_ok.rpl
testdata/val_fwdds.rpl
testdata/val_keyprefetch.rpl
testdata/val_keyprefetch_verify.rpl
testdata/val_mal_wc.rpl
testdata/val_negcache_ds.rpl
testdata/val_negcache_dssoa.rpl
testdata/val_nodata.rpl
testdata/val_nodata_ent.rpl
testdata/val_nodata_entwc.rpl
testdata/val_nodata_failsig.rpl
testdata/val_nodatawc.rpl
testdata/val_nodatawc_one.rpl
testdata/val_nokeyprime.rpl
testdata/val_nsec3_b1_nameerror.rpl
testdata/val_nsec3_b1_nameerror_nowc.rpl
testdata/val_nsec3_b21_nodataent.rpl
testdata/val_nsec3_b2_nodata.rpl
testdata/val_nsec3_b2_nodata_nons.rpl
testdata/val_nsec3_b3_optout.rpl
testdata/val_nsec3_b3_optout_negcache.rpl
testdata/val_nsec3_b4_wild.rpl
testdata/val_nsec3_b5_wcnodata.rpl
testdata/val_nsec3_cname_ds.rpl
testdata/val_nsec3_cname_par.rpl
testdata/val_nsec3_cname_sub.rpl
testdata/val_nsec3_cnametocnamewctoposwc.rpl
testdata/val_nsec3_iter_high.rpl
testdata/val_nsec3_nods.rpl
testdata/val_nsec3_nods_badsig.rpl
testdata/val_nsec3_nods_negcache.rpl
testdata/val_nsec3_optout_ad.rpl
testdata/val_nsec3_optout_cache.rpl
testdata/val_nsec3_wcany.rpl
testdata/val_nx.rpl
testdata/val_nx_nsec3_collision.rpl
testdata/val_nx_nsec3_params.rpl
testdata/val_nx_overreach.rpl
testdata/val_pos_truncns.rpl
testdata/val_positive.rpl
testdata/val_positive_wc.rpl
testdata/val_qds_badanc.rpl
testdata/val_qds_oneanc.rpl
testdata/val_qds_twoanc.rpl
testdata/val_refer_unsignadd.rpl
testdata/val_referd.rpl
testdata/val_referglue.rpl
testdata/val_rrsig.rpl
testdata/val_secds.rpl
testdata/val_secds_nosig.rpl
testdata/val_stub_noroot.rpl
testdata/val_stubds.rpl
testdata/val_ta_algo_dnskey.rpl
testdata/val_ta_algo_missing.rpl
testdata/val_twocname.rpl
testdata/val_unalgo_anchor.rpl
testdata/val_unalgo_dlv.rpl
testdata/val_unalgo_ds.rpl
testdata/val_unsec_cname.rpl
testdata/val_unsecds.rpl
testdata/val_unsecds_negcache.rpl
testdata/val_unsecds_qtypeds.rpl
testdata/val_wild_pos.rpl
util/config_file.c
util/configparser.c
util/configparser.h
util/data/dname.c
util/data/dname.h
util/data/msgencode.c
util/data/msgencode.h
util/data/msgparse.c
util/data/msgparse.h
util/data/msgreply.c
util/data/msgreply.h
util/data/packed_rrset.c
util/data/packed_rrset.h
util/log.c
util/log.h
util/module.h
util/net_help.c
util/netevent.c
util/netevent.h
util/random.c
validator/autotrust.c
validator/autotrust.h
validator/val_anchor.c
validator/val_anchor.h
validator/val_kentry.c
validator/val_neg.c
validator/val_neg.h
validator/val_nsec.c
validator/val_nsec3.c
validator/val_nsec3.h
validator/val_secalgo.c
validator/val_secalgo.h
validator/val_sigcrypt.c
validator/val_sigcrypt.h
validator/validator.c

index c2d485f28728299fc4b4265e41e630ba78c96c1d..9f4b78738d5652aef5cd2cd2d519c9edd253faa6 100644 (file)
@@ -16,7 +16,6 @@ datadir=@datadir@
 includedir=@includedir@
 doxygen=@doxygen@
 libtool=@libtool@
-ldnsdir=@ldnsdir@
 staticexe=@staticexe@
 EXEEXT=@EXEEXT@
 configfile=@ub_conf_file@
@@ -123,80 +122,83 @@ outside_network.lo
 COMMON_OBJ_ALL_SYMBOLS=@COMMON_OBJ_ALL_SYMBOLS@
 COMPAT_SRC=compat/ctime_r.c compat/fake-rfc2553.c compat/gmtime_r.c \
 compat/inet_aton.c compat/inet_ntop.c compat/inet_pton.c compat/malloc.c \
-compat/memcmp.c compat/memmove.c compat/snprintf.c compat/strlcpy.c \
-compat/strptime.c
+compat/memcmp.c compat/memmove.c compat/snprintf.c compat/strlcat.c \
+compat/strlcpy.c compat/strptime.c
 COMPAT_OBJ=$(LIBOBJS:.o=.lo)
 COMPAT_OBJ_WITHOUT_CTIME=$(LIBOBJ_WITHOUT_CTIME:.o=.lo)
+SLDNS_SRC=ldns/keyraw.c ldns/sbuffer.c ldns/wire2str.c ldns/parse.c \
+ldns/parseutil.c ldns/rrdef.c ldns/str2wire.c
+SLDNS_OBJ=keyraw.lo sbuffer.lo wire2str.lo parse.lo parseutil.lo rrdef.lo \
+str2wire.lo
 UNITTEST_SRC=testcode/unitanchor.c testcode/unitdname.c \
 testcode/unitlruhash.c testcode/unitmain.c testcode/unitmsgparse.c \
 testcode/unitneg.c testcode/unitregional.c testcode/unitslabhash.c \
-testcode/unitverify.c testcode/readhex.c testcode/ldns-testpkts.c
+testcode/unitverify.c testcode/readhex.c testcode/testpkts.c
 UNITTEST_OBJ=unitanchor.lo unitdname.lo unitlruhash.lo unitmain.lo \
 unitmsgparse.lo unitneg.lo unitregional.lo unitslabhash.lo unitverify.lo \
-readhex.lo ldns-testpkts.lo
-UNITTEST_OBJ_LINK=$(UNITTEST_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ)
+readhex.lo testpkts.lo
+UNITTEST_OBJ_LINK=$(UNITTEST_OBJ) worker_cb.lo $(COMMON_OBJ) $(SLDNS_OBJ) \
+$(COMPAT_OBJ)
 DAEMON_SRC=daemon/acl_list.c daemon/cachedump.c daemon/daemon.c \
 daemon/remote.c daemon/stats.c daemon/unbound.c daemon/worker.c @WIN_DAEMON_SRC@
 DAEMON_OBJ=acl_list.lo cachedump.lo daemon.lo remote.lo stats.lo unbound.lo \
 worker.lo @WIN_DAEMON_OBJ@
-DAEMON_OBJ_LINK=$(DAEMON_OBJ) $(COMMON_OBJ_ALL_SYMBOLS) \
+DAEMON_OBJ_LINK=$(DAEMON_OBJ) $(COMMON_OBJ_ALL_SYMBOLS) $(SLDNS_OBJ) \
 $(COMPAT_OBJ) @WIN_DAEMON_OBJ_LINK@
 CHECKCONF_SRC=smallapp/unbound-checkconf.c smallapp/worker_cb.c
 CHECKCONF_OBJ=unbound-checkconf.lo worker_cb.lo
-CHECKCONF_OBJ_LINK=$(CHECKCONF_OBJ) $(COMMON_OBJ_ALL_SYMBOLS) \
+CHECKCONF_OBJ_LINK=$(CHECKCONF_OBJ) $(COMMON_OBJ_ALL_SYMBOLS) $(SLDNS_OBJ) \
 $(COMPAT_OBJ) @WIN_CHECKCONF_OBJ_LINK@
 CONTROL_SRC=smallapp/unbound-control.c
 CONTROL_OBJ=unbound-control.lo 
 CONTROL_OBJ_LINK=$(CONTROL_OBJ) worker_cb.lo $(COMMON_OBJ_ALL_SYMBOLS) \
-$(COMPAT_OBJ) @WIN_CONTROL_OBJ_LINK@
+$(SLDNS_OBJ) $(COMPAT_OBJ) @WIN_CONTROL_OBJ_LINK@
 HOST_SRC=smallapp/unbound-host.c
 HOST_OBJ=unbound-host.lo
-HOST_OBJ_LINK=$(HOST_OBJ) $(COMPAT_OBJ_WITHOUT_CTIME) @WIN_HOST_OBJ_LINK@
+HOST_OBJ_LINK=$(HOST_OBJ) $(SLDNS_OBJ) $(COMPAT_OBJ_WITHOUT_CTIME) @WIN_HOST_OBJ_LINK@
 UBANCHOR_SRC=smallapp/unbound-anchor.c
 UBANCHOR_OBJ=unbound-anchor.lo
 UBANCHOR_OBJ_LINK=$(UBANCHOR_OBJ) \
 $(COMPAT_OBJ_WITHOUT_CTIME) @WIN_UBANCHOR_OBJ_LINK@
-TESTBOUND_SRC=testcode/testbound.c testcode/ldns-testpkts.c \
+TESTBOUND_SRC=testcode/testbound.c testcode/testpkts.c \
 daemon/worker.c daemon/acl_list.c daemon/daemon.c daemon/stats.c \
 testcode/replay.c testcode/fake_event.c
 TESTBOUND_OBJ=testbound.lo replay.lo fake_event.lo
-TESTBOUND_OBJ_LINK=$(TESTBOUND_OBJ) ldns-testpkts.lo worker.lo acl_list.lo \
-daemon.lo stats.lo $(COMMON_OBJ_WITHOUT_NETCALL) $(COMPAT_OBJ)
+TESTBOUND_OBJ_LINK=$(TESTBOUND_OBJ) testpkts.lo worker.lo acl_list.lo \
+daemon.lo stats.lo $(COMMON_OBJ_WITHOUT_NETCALL) $(SLDNS_OBJ) $(COMPAT_OBJ)
 LOCKVERIFY_SRC=testcode/lock_verify.c
 LOCKVERIFY_OBJ=lock_verify.lo
-LOCKVERIFY_OBJ_LINK=$(LOCKVERIFY_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ)
+LOCKVERIFY_OBJ_LINK=$(LOCKVERIFY_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ) \
+$(SLDNS_OBJ)
 PETAL_SRC=testcode/petal.c
 PETAL_OBJ=petal.lo
 PETAL_OBJ_LINK=$(PETAL_OBJ) $(COMPAT_OBJ_WITHOUT_CTIME)
 PKTVIEW_SRC=testcode/pktview.c testcode/readhex.c
 PKTVIEW_OBJ=pktview.lo
 PKTVIEW_OBJ_LINK=$(PKTVIEW_OBJ) worker_cb.lo readhex.lo $(COMMON_OBJ) \
-$(COMPAT_OBJ)
-SIGNIT_SRC=testcode/signit.c
-SIGNIT_OBJ=signit.lo
-SIGNIT_OBJ_LINK=$(SIGNIT_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ)
+$(COMPAT_OBJ) $(SLDNS_OBJ)
 MEMSTATS_SRC=testcode/memstats.c
 MEMSTATS_OBJ=memstats.lo
-MEMSTATS_OBJ_LINK=$(MEMSTATS_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ)
+MEMSTATS_OBJ_LINK=$(MEMSTATS_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ) \
+$(SLDNS_OBJ)
 ASYNCLOOK_SRC=testcode/asynclook.c
 ASYNCLOOK_OBJ=asynclook.lo
 ASYNCLOOK_OBJ_LINK=$(ASYNCLOOK_OBJ) log.lo locks.lo $(COMPAT_OBJ)
 STREAMTCP_SRC=testcode/streamtcp.c
 STREAMTCP_OBJ=streamtcp.lo
-STREAMTCP_OBJ_LINK=$(STREAMTCP_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ)
+STREAMTCP_OBJ_LINK=$(STREAMTCP_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ) \
+$(SLDNS_OBJ)
 PERF_SRC=testcode/perf.c
 PERF_OBJ=perf.lo
-PERF_OBJ_LINK=$(PERF_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ)
+PERF_OBJ_LINK=$(PERF_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ) $(SLDNS_OBJ)
 DELAYER_SRC=testcode/delayer.c
 DELAYER_OBJ=delayer.lo
-DELAYER_OBJ_LINK=$(DELAYER_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ)
-HARVEST_SRC=testcode/harvest.c
-HARVEST_OBJ=harvest.lo
-HARVEST_OBJ_LINK=$(HARVEST_OBJ) $(COMPAT_OBJ_WITHOUT_CTIME)
+DELAYER_OBJ_LINK=$(DELAYER_OBJ) worker_cb.lo $(COMMON_OBJ) $(COMPAT_OBJ) \
+$(SLDNS_OBJ)
 LIBUNBOUND_SRC=libunbound/context.c libunbound/libunbound.c \
 libunbound/libworker.c
 LIBUNBOUND_OBJ=context.lo libunbound.lo libworker.lo
-LIBUNBOUND_OBJ_LINK=$(LIBUNBOUND_OBJ) $(COMMON_OBJ) $(COMPAT_OBJ)
+LIBUNBOUND_OBJ_LINK=$(LIBUNBOUND_OBJ) $(COMMON_OBJ) $(SLDNS_OBJ) $(COMPAT_OBJ)
 
 # win apps or "" if not on windows
 WINAPPS=@WINAPPS@
@@ -216,19 +218,19 @@ RSRC_OBJ=rsrc_svcinst.o rsrc_svcuninst.o rsrc_anchorupd.o rsrc_unbound.o \
        rsrc_unbound_checkconf.o
 
 ALL_SRC=$(COMMON_SRC) $(UNITTEST_SRC) $(DAEMON_SRC) \
-       $(TESTBOUND_SRC) $(LOCKVERIFY_SRC) $(PKTVIEW_SRC) $(SIGNIT_SRC) \
+       $(TESTBOUND_SRC) $(LOCKVERIFY_SRC) $(PKTVIEW_SRC) \
        $(MEMSTATS_SRC) $(CHECKCONF_SRC) $(LIBUNBOUND_SRC) $(HOST_SRC) \
        $(ASYNCLOOK_SRC) $(STREAMTCP_SRC) $(PERF_SRC) $(DELAYER_SRC) \
-       $(HARVEST_SRC) $(CONTROL_SRC) $(UBANCHOR_SRC) $(PETAL_SRC) \
+       $(CONTROL_SRC) $(UBANCHOR_SRC) $(PETAL_SRC) \
        $(PYTHONMOD_SRC) $(PYUNBOUND_SRC) $(WIN_DAEMON_THE_SRC)\
-       $(SVCINST_SRC) $(SVCUNINST_SRC) $(ANCHORUPD_SRC)
+       $(SVCINST_SRC) $(SVCUNINST_SRC) $(ANCHORUPD_SRC) $(SLDNS_SRC)
 ALL_OBJ=$(COMMON_OBJ) $(UNITTEST_OBJ) $(DAEMON_OBJ) \
-       $(TESTBOUND_OBJ) $(LOCKVERIFY_OBJ) $(PKTVIEW_OBJ) $(SIGNIT_OBJ) \
+       $(TESTBOUND_OBJ) $(LOCKVERIFY_OBJ) $(PKTVIEW_OBJ) \
        $(MEMSTATS_OBJ) $(CHECKCONF_OBJ) $(LIBUNBOUND_OBJ) $(HOST_OBJ) \
        $(ASYNCLOOK_OBJ) $(STREAMTCP_OBJ) $(PERF_OBJ) $(DELAYER_OBJ) \
-       $(HARVEST_OBJ) $(CONTROL_OBJ) $(UBANCHOR_OBJ) $(PETAL_OBJ) \
+       $(CONTROL_OBJ) $(UBANCHOR_OBJ) $(PETAL_OBJ) \
        $(COMPAT_OBJ) $(PYUNBOUND_OBJ) \
-       $(SVCINST_OBJ) $(SVCUNINST_OBJ) $(ANCHORUPD_OBJ)
+       $(SVCINST_OBJ) $(SVCUNINST_OBJ) $(ANCHORUPD_OBJ) $(SLDNS_OBJ)
 
 COMPILE=$(LIBTOOL) --tag=CC --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS)
 LINK=$(LIBTOOL) --tag=CC --mode=link $(CC) $(staticexe) $(RUNTIME_PATH) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
@@ -262,9 +264,9 @@ rsrc_unbound_anchor.o:      $(srcdir)/winrc/rsrc_unbound_anchor.rc config.h
 rsrc_unbound_control.o:        $(srcdir)/winrc/rsrc_unbound_control.rc config.h
 rsrc_unbound_checkconf.o:      $(srcdir)/winrc/rsrc_unbound_checkconf.rc config.h
 
-TEST_BIN=asynclook$(EXEEXT) delayer$(EXEEXT) harvest$(EXEEXT) \
+TEST_BIN=asynclook$(EXEEXT) delayer$(EXEEXT) \
        lock-verify$(EXEEXT) memstats$(EXEEXT) perf$(EXEEXT) \
-       petal$(EXEEXT) pktview$(EXEEXT) signit$(EXEEXT) streamtcp$(EXEEXT) \
+       petal$(EXEEXT) pktview$(EXEEXT) streamtcp$(EXEEXT) \
        testbound$(EXEEXT) unittest$(EXEEXT)
 tests: all $(TEST_BIN)
 
@@ -324,9 +326,6 @@ petal$(EXEEXT):     $(PETAL_OBJ_LINK)
 pktview$(EXEEXT):      $(PKTVIEW_OBJ_LINK)
        $(LINK) -o $@ $(PKTVIEW_OBJ_LINK) -lssl $(LIBS)
 
-signit$(EXEEXT):       $(SIGNIT_OBJ_LINK)
-       $(LINK) -o $@ $(SIGNIT_OBJ_LINK) -lssl $(LIBS)
-
 memstats$(EXEEXT):     $(MEMSTATS_OBJ_LINK)
        $(LINK) -o $@ $(MEMSTATS_OBJ_LINK) -lssl $(LIBS)
 
@@ -342,8 +341,8 @@ perf$(EXEEXT):      $(PERF_OBJ_LINK)
 delayer$(EXEEXT):      $(DELAYER_OBJ_LINK)
        $(LINK) -o $@ $(DELAYER_OBJ_LINK) -lssl $(LIBS)
 
-harvest$(EXEEXT):      $(HARVEST_OBJ_LINK) libunbound.la
-       $(LINK) -o $@ $(HARVEST_OBJ_LINK) $(LIBS) -L. -L.libs -lunbound
+signit$(EXEEXT):       testcode/signit.c
+       $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ testcode/signit.c $(LDFLAGS) -lldns -lssl $(LIBS)
 
 unbound.h:     $(srcdir)/libunbound/unbound.h
        sed -e 's/@''UNBOUND_VERSION_MAJOR@/$(UNBOUND_VERSION_MAJOR)/' -e 's/@''UNBOUND_VERSION_MINOR@/$(UNBOUND_VERSION_MINOR)/' -e 's/@''UNBOUND_VERSION_MICRO@/$(UNBOUND_VERSION_MICRO)/' < $(srcdir)/libunbound/unbound.h > $@
@@ -352,11 +351,6 @@ unbound-control-setup:     $(srcdir)/smallapp/unbound-control-setup.sh
        sed -e 's:^DESTDIR=.*$$:DESTDIR=$(UNBOUND_RUN_DIR):' < $(srcdir)/smallapp/unbound-control-setup.sh > $@
        -chmod +x $@
 
-#testcode/ldns-testpkts.c:     $(ldnsdir)/examples/ldns-testpkts.c \
-#                      $(ldnsdir)/examples/ldns-testpkts.h
-#      cp $(ldnsdir)/examples/ldns-testpkts.c testcode/ldns-testpkts.c
-#      cp $(ldnsdir)/examples/ldns-testpkts.h testcode/ldns-testpkts.h
-
 # Python Module
 pythonmod.lo pythonmod.o: $(srcdir)/pythonmod/pythonmod.c config.h \
        pythonmod/interface.h \
@@ -414,7 +408,7 @@ realclean: clean
 
 .SUFFIXES: .lint
 .c.lint:
-       $(LINT) $(LINTFLAGS) -I. -I$(srcdir) -I$(ldnsdir)/include $<
+       $(LINT) $(LINTFLAGS) -I. -I$(srcdir) $<
        touch $@
 
 util/configparser.lint util/configlexer.lint pythonmod/pythonmod.lint libunbound/python/libunbound_wrap.lint:
@@ -573,188 +567,158 @@ depend:
 
 # Dependencies
 dns.lo dns.o: $(srcdir)/services/cache/dns.c config.h $(srcdir)/iterator/iter_delegpt.h $(srcdir)/util/log.h \
- $(srcdir)/validator/val_nsec.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
- $(srcdir)/services/cache/dns.h \
- $(srcdir)/util/data/msgreply.h $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h \
- $(srcdir)/util/data/dname.h $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/net_help.h \
- $(srcdir)/util/regional.h $(srcdir)/util/config_file.h
-infra.lo infra.o: $(srcdir)/services/cache/infra.c config.h \
- $(srcdir)/services/cache/infra.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/rtt.h \
- $(srcdir)/util/storage/slabhash.h $(srcdir)/util/storage/lookup3.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h $(srcdir)/iterator/iterator.h \
+ $(srcdir)/validator/val_nsec.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h \
+ $(srcdir)/util/locks.h $(srcdir)/services/cache/dns.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h $(srcdir)/util/data/dname.h \
+ $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h \
+ $(srcdir)/util/net_help.h $(srcdir)/util/regional.h $(srcdir)/util/config_file.h $(srcdir)/ldns/sbuffer.h
+infra.lo infra.o: $(srcdir)/services/cache/infra.c config.h $(srcdir)/ldns/rrdef.h \
+ $(srcdir)/services/cache/infra.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
+ $(srcdir)/util/rtt.h $(srcdir)/util/storage/slabhash.h $(srcdir)/util/storage/lookup3.h \
+ $(srcdir)/util/data/dname.h $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h $(srcdir)/iterator/iterator.h \
  $(srcdir)/services/outbound_list.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h
 rrset.lo rrset.o: $(srcdir)/services/cache/rrset.c config.h $(srcdir)/services/cache/rrset.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/storage/slabhash.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/config_file.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/storage/slabhash.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/config_file.h \
  $(srcdir)/util/data/msgreply.h $(srcdir)/util/regional.h $(srcdir)/util/alloc.h
 dname.lo dname.o: $(srcdir)/util/data/dname.c config.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/storage/lookup3.h
-msgencode.lo msgencode.o: $(srcdir)/util/data/msgencode.c config.h \
- $(srcdir)/util/data/msgencode.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/storage/lookup3.h $(srcdir)/ldns/sbuffer.h
+msgencode.lo msgencode.o: $(srcdir)/util/data/msgencode.c config.h $(srcdir)/util/data/msgencode.h \
  $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/regional.h $(srcdir)/util/net_help.h
-msgparse.lo msgparse.o: $(srcdir)/util/data/msgparse.c config.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lookup3.h $(srcdir)/util/regional.h
-msgreply.lo msgreply.o: $(srcdir)/util/data/msgreply.c config.h \
- $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h \
+ $(srcdir)/util/data/dname.h $(srcdir)/util/regional.h $(srcdir)/util/net_help.h $(srcdir)/ldns/sbuffer.h
+msgparse.lo msgparse.o: $(srcdir)/util/data/msgparse.c config.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/ldns/pkthdr.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/util/data/dname.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/storage/lookup3.h $(srcdir)/util/regional.h $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/parseutil.h \
+ $(srcdir)/ldns/wire2str.h
+msgreply.lo msgreply.o: $(srcdir)/util/data/msgreply.c config.h $(srcdir)/util/data/msgreply.h \
  $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/packed_rrset.h \
  $(srcdir)/util/storage/lookup3.h $(srcdir)/util/alloc.h $(srcdir)/util/netevent.h $(srcdir)/util/net_help.h \
- $(srcdir)/util/data/dname.h $(srcdir)/util/regional.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/data/msgencode.h
+ $(srcdir)/util/data/dname.h $(srcdir)/util/regional.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/util/data/msgencode.h $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/wire2str.h
 packed_rrset.lo packed_rrset.o: $(srcdir)/util/data/packed_rrset.c config.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/storage/lookup3.h $(srcdir)/util/alloc.h $(srcdir)/util/regional.h $(srcdir)/util/net_help.h
-iterator.lo iterator.o: $(srcdir)/iterator/iterator.c config.h \
- $(srcdir)/iterator/iterator.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
+ $(srcdir)/util/data/dname.h $(srcdir)/util/storage/lookup3.h $(srcdir)/util/alloc.h $(srcdir)/util/regional.h \
+ $(srcdir)/util/net_help.h $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/wire2str.h
+iterator.lo iterator.o: $(srcdir)/iterator/iterator.c config.h $(srcdir)/iterator/iterator.h \
  $(srcdir)/services/outbound_list.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h \
  $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/module.h \
- $(srcdir)/util/data/msgparse.h $(srcdir)/iterator/iter_utils.h $(srcdir)/iterator/iter_resptype.h \
- $(srcdir)/iterator/iter_hints.h $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h \
- $(srcdir)/iterator/iter_fwd.h $(srcdir)/iterator/iter_donotq.h $(srcdir)/iterator/iter_delegpt.h \
- $(srcdir)/iterator/iter_scrub.h $(srcdir)/iterator/iter_priv.h $(srcdir)/validator/val_neg.h \
- $(srcdir)/services/cache/dns.h $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h $(srcdir)/util/netevent.h \
- $(srcdir)/util/net_help.h $(srcdir)/util/regional.h $(srcdir)/util/data/dname.h $(srcdir)/util/data/msgencode.h \
- $(srcdir)/util/fptr_wlist.h $(srcdir)/util/tube.h $(srcdir)/services/mesh.h $(srcdir)/services/modstack.h \
- $(srcdir)/util/config_file.h
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/iterator/iter_utils.h \
+ $(srcdir)/iterator/iter_resptype.h $(srcdir)/iterator/iter_hints.h $(srcdir)/util/storage/dnstree.h \
+ $(srcdir)/util/rbtree.h $(srcdir)/iterator/iter_fwd.h $(srcdir)/iterator/iter_donotq.h \
+ $(srcdir)/iterator/iter_delegpt.h $(srcdir)/iterator/iter_scrub.h $(srcdir)/iterator/iter_priv.h \
+ $(srcdir)/validator/val_neg.h $(srcdir)/services/cache/dns.h $(srcdir)/services/cache/infra.h \
+ $(srcdir)/util/rtt.h $(srcdir)/util/netevent.h $(srcdir)/util/net_help.h $(srcdir)/util/regional.h \
+ $(srcdir)/util/data/dname.h $(srcdir)/util/data/msgencode.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/tube.h \
+ $(srcdir)/services/mesh.h $(srcdir)/services/modstack.h $(srcdir)/util/config_file.h $(srcdir)/ldns/wire2str.h \
+ $(srcdir)/ldns/parseutil.h $(srcdir)/ldns/sbuffer.h
 iter_delegpt.lo iter_delegpt.o: $(srcdir)/iterator/iter_delegpt.c config.h $(srcdir)/iterator/iter_delegpt.h \
- $(srcdir)/util/log.h \
- $(srcdir)/services/cache/dns.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/regional.h \
- $(srcdir)/util/data/dname.h $(srcdir)/util/net_help.h
+ $(srcdir)/util/log.h $(srcdir)/services/cache/dns.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/regional.h \
+ $(srcdir)/util/data/dname.h $(srcdir)/util/net_help.h $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/sbuffer.h
 iter_donotq.lo iter_donotq.o: $(srcdir)/iterator/iter_donotq.c config.h $(srcdir)/iterator/iter_donotq.h \
  $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h $(srcdir)/util/regional.h $(srcdir)/util/log.h \
- $(srcdir)/util/config_file.h \
- $(srcdir)/util/net_help.h
-iter_fwd.lo iter_fwd.o: $(srcdir)/iterator/iter_fwd.c config.h \
- $(srcdir)/iterator/iter_fwd.h \
+ $(srcdir)/util/config_file.h $(srcdir)/util/net_help.h
+iter_fwd.lo iter_fwd.o: $(srcdir)/iterator/iter_fwd.c config.h $(srcdir)/iterator/iter_fwd.h \
  $(srcdir)/util/rbtree.h $(srcdir)/iterator/iter_delegpt.h $(srcdir)/util/log.h $(srcdir)/util/config_file.h \
- $(srcdir)/util/net_help.h $(srcdir)/util/data/dname.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h
-iter_hints.lo iter_hints.o: $(srcdir)/iterator/iter_hints.c config.h \
- $(srcdir)/iterator/iter_hints.h \
+ $(srcdir)/util/net_help.h $(srcdir)/util/data/dname.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/str2wire.h
+iter_hints.lo iter_hints.o: $(srcdir)/iterator/iter_hints.c config.h $(srcdir)/iterator/iter_hints.h \
  $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h $(srcdir)/iterator/iter_delegpt.h $(srcdir)/util/log.h \
  $(srcdir)/util/config_file.h $(srcdir)/util/net_help.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h
-iter_priv.lo iter_priv.o: $(srcdir)/iterator/iter_priv.c config.h \
- $(srcdir)/iterator/iter_priv.h \
- $(srcdir)/util/rbtree.h \
- $(srcdir)/util/regional.h $(srcdir)/util/log.h $(srcdir)/util/config_file.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/net_help.h \
- $(srcdir)/util/storage/dnstree.h
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/str2wire.h \
+ $(srcdir)/ldns/wire2str.h
+iter_priv.lo iter_priv.o: $(srcdir)/iterator/iter_priv.c config.h $(srcdir)/iterator/iter_priv.h \
+ $(srcdir)/util/rbtree.h $(srcdir)/util/regional.h $(srcdir)/util/log.h $(srcdir)/util/config_file.h \
+ $(srcdir)/util/data/dname.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/net_help.h \
+ $(srcdir)/util/storage/dnstree.h $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/sbuffer.h
 iter_resptype.lo iter_resptype.o: $(srcdir)/iterator/iter_resptype.c config.h \
- $(srcdir)/iterator/iter_resptype.h \
- $(srcdir)/iterator/iter_delegpt.h $(srcdir)/util/log.h $(srcdir)/services/cache/dns.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/net_help.h $(srcdir)/util/data/dname.h
+ $(srcdir)/iterator/iter_resptype.h $(srcdir)/iterator/iter_delegpt.h $(srcdir)/util/log.h \
+ $(srcdir)/services/cache/dns.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/net_help.h \
+ $(srcdir)/util/data/dname.h $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/pkthdr.h
 iter_scrub.lo iter_scrub.o: $(srcdir)/iterator/iter_scrub.c config.h $(srcdir)/iterator/iter_scrub.h \
- $(srcdir)/iterator/iterator.h \
- $(srcdir)/services/outbound_list.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/module.h \
- $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/iterator/iterator.h $(srcdir)/services/outbound_list.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h \
  $(srcdir)/iterator/iter_priv.h $(srcdir)/util/rbtree.h $(srcdir)/services/cache/rrset.h \
  $(srcdir)/util/storage/slabhash.h $(srcdir)/util/net_help.h $(srcdir)/util/regional.h \
- $(srcdir)/util/config_file.h $(srcdir)/util/data/dname.h $(srcdir)/util/alloc.h
+ $(srcdir)/util/config_file.h $(srcdir)/util/data/dname.h $(srcdir)/util/alloc.h $(srcdir)/ldns/sbuffer.h
 iter_utils.lo iter_utils.o: $(srcdir)/iterator/iter_utils.c config.h $(srcdir)/iterator/iter_utils.h \
- $(srcdir)/iterator/iter_resptype.h \
- $(srcdir)/iterator/iterator.h \
- $(srcdir)/services/outbound_list.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/module.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/iterator/iter_hints.h $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h \
- $(srcdir)/iterator/iter_fwd.h $(srcdir)/iterator/iter_donotq.h $(srcdir)/iterator/iter_delegpt.h \
- $(srcdir)/iterator/iter_priv.h $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h \
- $(srcdir)/services/cache/dns.h $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h \
- $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h $(srcdir)/util/regional.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/random.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/tube.h \
- $(srcdir)/services/mesh.h $(srcdir)/services/modstack.h $(srcdir)/validator/val_anchor.h \
- $(srcdir)/validator/val_kcache.h $(srcdir)/validator/val_kentry.h $(srcdir)/validator/val_utils.h
+ $(srcdir)/iterator/iter_resptype.h $(srcdir)/iterator/iterator.h $(srcdir)/services/outbound_list.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/iterator/iter_hints.h $(srcdir)/util/storage/dnstree.h \
+ $(srcdir)/util/rbtree.h $(srcdir)/iterator/iter_fwd.h $(srcdir)/iterator/iter_donotq.h \
+ $(srcdir)/iterator/iter_delegpt.h $(srcdir)/iterator/iter_priv.h $(srcdir)/services/cache/infra.h \
+ $(srcdir)/util/rtt.h $(srcdir)/services/cache/dns.h $(srcdir)/services/cache/rrset.h \
+ $(srcdir)/util/storage/slabhash.h $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h \
+ $(srcdir)/util/regional.h $(srcdir)/util/data/dname.h $(srcdir)/util/random.h $(srcdir)/util/fptr_wlist.h \
+ $(srcdir)/util/netevent.h $(srcdir)/util/tube.h $(srcdir)/services/mesh.h $(srcdir)/services/modstack.h \
+ $(srcdir)/validator/val_anchor.h $(srcdir)/validator/val_kcache.h $(srcdir)/validator/val_kentry.h \
+ $(srcdir)/validator/val_utils.h $(srcdir)/validator/val_sigcrypt.h $(srcdir)/ldns/sbuffer.h
 listen_dnsport.lo listen_dnsport.o: $(srcdir)/services/listen_dnsport.c config.h \
- $(srcdir)/services/listen_dnsport.h $(srcdir)/util/netevent.h \
- $(srcdir)/services/outside_network.h \
- $(srcdir)/util/rbtree.h $(srcdir)/util/log.h $(srcdir)/util/config_file.h $(srcdir)/util/net_help.h
-localzone.lo localzone.o: $(srcdir)/services/localzone.c config.h \
- $(srcdir)/services/localzone.h \
- $(srcdir)/util/rbtree.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/regional.h $(srcdir)/util/config_file.h \
- $(srcdir)/util/data/dname.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgencode.h $(srcdir)/util/net_help.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/msgparse.h
-mesh.lo mesh.o: $(srcdir)/services/mesh.c config.h \
- $(srcdir)/services/mesh.h \
- $(srcdir)/util/rbtree.h $(srcdir)/util/netevent.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/module.h \
- $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/services/modstack.h \
- $(srcdir)/services/outbound_list.h $(srcdir)/services/cache/dns.h $(srcdir)/util/net_help.h \
- $(srcdir)/util/regional.h $(srcdir)/util/data/msgencode.h $(srcdir)/util/timehist.h $(srcdir)/util/fptr_wlist.h \
- $(srcdir)/util/tube.h $(srcdir)/util/alloc.h $(srcdir)/util/config_file.h
+ $(srcdir)/services/listen_dnsport.h $(srcdir)/util/netevent.h $(srcdir)/services/outside_network.h \
+ $(srcdir)/util/rbtree.h $(srcdir)/util/log.h $(srcdir)/util/config_file.h $(srcdir)/util/net_help.h \
+ $(srcdir)/ldns/sbuffer.h
+localzone.lo localzone.o: $(srcdir)/services/localzone.c config.h $(srcdir)/services/localzone.h \
+ $(srcdir)/util/rbtree.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/rrdef.h \
+ $(srcdir)/ldns/sbuffer.h $(srcdir)/util/regional.h $(srcdir)/util/config_file.h $(srcdir)/util/data/dname.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgencode.h \
+ $(srcdir)/util/net_help.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h
+mesh.lo mesh.o: $(srcdir)/services/mesh.c config.h $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h \
+ $(srcdir)/util/netevent.h $(srcdir)/util/data/msgparse.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
+ $(srcdir)/util/log.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/services/modstack.h $(srcdir)/services/outbound_list.h \
+ $(srcdir)/services/cache/dns.h $(srcdir)/util/net_help.h $(srcdir)/util/regional.h \
+ $(srcdir)/util/data/msgencode.h $(srcdir)/util/timehist.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/tube.h \
+ $(srcdir)/util/alloc.h $(srcdir)/util/config_file.h $(srcdir)/ldns/sbuffer.h
 modstack.lo modstack.o: $(srcdir)/services/modstack.c config.h $(srcdir)/services/modstack.h \
  $(srcdir)/util/module.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/fptr_wlist.h \
- $(srcdir)/util/netevent.h $(srcdir)/util/tube.h $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h \
- $(srcdir)/iterator/iterator.h $(srcdir)/services/outbound_list.h $(srcdir)/validator/validator.h \
- $(srcdir)/validator/val_utils.h
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/tube.h \
+ $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h $(srcdir)/iterator/iterator.h \
+ $(srcdir)/services/outbound_list.h $(srcdir)/validator/validator.h $(srcdir)/validator/val_utils.h
 outbound_list.lo outbound_list.o: $(srcdir)/services/outbound_list.c config.h \
  $(srcdir)/services/outbound_list.h $(srcdir)/services/outside_network.h $(srcdir)/util/rbtree.h \
- $(srcdir)/util/netevent.h \
+ $(srcdir)/util/netevent.h
 outside_network.lo outside_network.o: $(srcdir)/services/outside_network.c config.h \
- $(srcdir)/services/outside_network.h \
- $(srcdir)/util/rbtree.h $(srcdir)/util/netevent.h $(srcdir)/services/listen_dnsport.h \
- $(srcdir)/services/cache/infra.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/rtt.h $(srcdir)/util/data/msgparse.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgencode.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/net_help.h $(srcdir)/util/random.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/module.h \
- $(srcdir)/util/tube.h $(srcdir)/services/mesh.h $(srcdir)/services/modstack.h \
+ $(srcdir)/services/outside_network.h $(srcdir)/util/rbtree.h $(srcdir)/util/netevent.h \
+ $(srcdir)/services/listen_dnsport.h $(srcdir)/services/cache/infra.h $(srcdir)/util/storage/lruhash.h \
+ $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/rtt.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/data/msgencode.h $(srcdir)/util/data/dname.h $(srcdir)/util/net_help.h $(srcdir)/util/random.h \
+ $(srcdir)/util/fptr_wlist.h $(srcdir)/util/module.h $(srcdir)/util/tube.h $(srcdir)/services/mesh.h \
+ $(srcdir)/services/modstack.h $(srcdir)/ldns/sbuffer.h \
  
 alloc.lo alloc.o: $(srcdir)/util/alloc.c config.h $(srcdir)/util/alloc.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/regional.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/fptr_wlist.h \
- $(srcdir)/util/netevent.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/tube.h $(srcdir)/services/mesh.h \
- $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h
-config_file.lo config_file.o: $(srcdir)/util/config_file.c config.h \
- $(srcdir)/util/log.h \
+ $(srcdir)/util/regional.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h \
+ $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/tube.h \
+ $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h
+config_file.lo config_file.o: $(srcdir)/util/config_file.c config.h $(srcdir)/util/log.h \
  $(srcdir)/util/configyyrename.h $(srcdir)/util/config_file.h util/configparser.h \
  $(srcdir)/util/net_help.h $(srcdir)/util/data/msgparse.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
- $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/regional.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/tube.h \
- $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h $(srcdir)/util/data/dname.h \
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/regional.h $(srcdir)/util/fptr_wlist.h \
+ $(srcdir)/util/netevent.h $(srcdir)/util/tube.h $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h \
+ $(srcdir)/services/modstack.h $(srcdir)/util/data/dname.h $(srcdir)/ldns/wire2str.h $(srcdir)/ldns/parseutil.h \
  $(srcdir)/util/iana_ports.inc
 configlexer.lo configlexer.o: util/configlexer.c config.h $(srcdir)/util/configyyrename.h \
  $(srcdir)/util/config_file.h util/configparser.h
 configparser.lo configparser.o: util/configparser.c config.h $(srcdir)/util/configyyrename.h \
- $(srcdir)/util/config_file.h $(srcdir)/util/net_help.h $(srcdir)/util/log.h \
+ $(srcdir)/util/config_file.h $(srcdir)/util/net_help.h $(srcdir)/util/log.h
 fptr_wlist.lo fptr_wlist.o: $(srcdir)/util/fptr_wlist.c config.h $(srcdir)/util/fptr_wlist.h \
- $(srcdir)/util/netevent.h \
- $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/tube.h $(srcdir)/services/mesh.h \
- $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h $(srcdir)/util/mini_event.h $(srcdir)/util/rbtree.h \
- $(srcdir)/daemon/worker.h $(srcdir)/util/alloc.h $(srcdir)/daemon/stats.h $(srcdir)/util/timehist.h \
- $(srcdir)/daemon/remote.h \
+ $(srcdir)/util/netevent.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
+ $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/tube.h \
+ $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h $(srcdir)/util/mini_event.h \
+ $(srcdir)/util/rbtree.h $(srcdir)/daemon/worker.h $(srcdir)/util/alloc.h $(srcdir)/daemon/stats.h \
+ $(srcdir)/util/timehist.h $(srcdir)/daemon/remote.h \
  $(srcdir)/services/outside_network.h $(srcdir)/services/localzone.h $(srcdir)/services/cache/infra.h \
  $(srcdir)/util/rtt.h $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h \
  $(srcdir)/iterator/iterator.h $(srcdir)/services/outbound_list.h $(srcdir)/iterator/iter_fwd.h \
@@ -763,266 +727,235 @@ fptr_wlist.lo fptr_wlist.o: $(srcdir)/util/fptr_wlist.c config.h $(srcdir)/util/
  $(srcdir)/validator/val_neg.h $(srcdir)/validator/autotrust.h $(srcdir)/util/storage/dnstree.h \
  $(srcdir)/libunbound/libworker.h $(srcdir)/libunbound/context.h $(srcdir)/libunbound/unbound.h \
  $(srcdir)/util/config_file.h
-locks.lo locks.o: $(srcdir)/util/locks.c config.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
-log.lo log.o: $(srcdir)/util/log.c config.h $(srcdir)/util/log.h \
- $(srcdir)/util/locks.h
+locks.lo locks.o: $(srcdir)/util/locks.c config.h $(srcdir)/util/locks.h $(srcdir)/util/log.h
+log.lo log.o: $(srcdir)/util/log.c config.h $(srcdir)/util/log.h $(srcdir)/util/locks.h $(srcdir)/ldns/sbuffer.h
 mini_event.lo mini_event.o: $(srcdir)/util/mini_event.c config.h $(srcdir)/util/mini_event.h $(srcdir)/util/rbtree.h \
- $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h \
- $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/tube.h $(srcdir)/services/mesh.h \
- $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h
+ $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
+ $(srcdir)/util/log.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/tube.h \
+ $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h
 module.lo module.o: $(srcdir)/util/module.c config.h $(srcdir)/util/module.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
-netevent.lo netevent.o: $(srcdir)/util/netevent.c config.h \
- $(srcdir)/util/netevent.h $(srcdir)/util/log.h \
+ $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h
+netevent.lo netevent.o: $(srcdir)/util/netevent.c config.h $(srcdir)/util/netevent.h $(srcdir)/util/log.h \
  $(srcdir)/util/net_help.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
  $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h $(srcdir)/util/tube.h $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h \
- $(srcdir)/services/modstack.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/tube.h \
+ $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h $(srcdir)/ldns/sbuffer.h \
  $(srcdir)/util/mini_event.h $(srcdir)/util/rbtree.h
-net_help.lo net_help.o: $(srcdir)/util/net_help.c config.h \
- $(srcdir)/util/net_help.h $(srcdir)/util/log.h \
+net_help.lo net_help.o: $(srcdir)/util/net_help.c config.h $(srcdir)/util/net_help.h $(srcdir)/util/log.h \
  $(srcdir)/util/data/dname.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/module.h \
  $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/regional.h
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/regional.h $(srcdir)/ldns/parseutil.h \
+ $(srcdir)/ldns/wire2str.h \
 random.lo random.o: $(srcdir)/util/random.c config.h $(srcdir)/util/random.h $(srcdir)/util/log.h \
  
-rbtree.lo rbtree.o: $(srcdir)/util/rbtree.c config.h $(srcdir)/util/log.h \
- $(srcdir)/util/fptr_wlist.h \
+rbtree.lo rbtree.o: $(srcdir)/util/rbtree.c config.h $(srcdir)/util/log.h $(srcdir)/util/fptr_wlist.h \
  $(srcdir)/util/netevent.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
  $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/tube.h $(srcdir)/services/mesh.h \
- $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h
-regional.lo regional.o: $(srcdir)/util/regional.c config.h $(srcdir)/util/log.h \
- $(srcdir)/util/regional.h
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/tube.h \
+ $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h
+regional.lo regional.o: $(srcdir)/util/regional.c config.h $(srcdir)/util/log.h $(srcdir)/util/regional.h
 rtt.lo rtt.o: $(srcdir)/util/rtt.c config.h $(srcdir)/util/rtt.h
 dnstree.lo dnstree.o: $(srcdir)/util/storage/dnstree.c config.h $(srcdir)/util/storage/dnstree.h \
  $(srcdir)/util/rbtree.h $(srcdir)/util/data/dname.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
- $(srcdir)/util/log.h \
- $(srcdir)/util/net_help.h
+ $(srcdir)/util/log.h $(srcdir)/util/net_help.h
 lookup3.lo lookup3.o: $(srcdir)/util/storage/lookup3.c config.h $(srcdir)/util/storage/lookup3.h
 lruhash.lo lruhash.o: $(srcdir)/util/storage/lruhash.c config.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/fptr_wlist.h \
- $(srcdir)/util/netevent.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/tube.h $(srcdir)/services/mesh.h \
- $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h
+ $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/module.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/tube.h $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h \
+ $(srcdir)/services/modstack.h
 slabhash.lo slabhash.o: $(srcdir)/util/storage/slabhash.c config.h $(srcdir)/util/storage/slabhash.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
-timehist.lo timehist.o: $(srcdir)/util/timehist.c config.h $(srcdir)/util/timehist.h $(srcdir)/util/log.h \
-tube.lo tube.o: $(srcdir)/util/tube.c config.h $(srcdir)/util/tube.h $(srcdir)/util/log.h \
- $(srcdir)/util/net_help.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h
+timehist.lo timehist.o: $(srcdir)/util/timehist.c config.h $(srcdir)/util/timehist.h $(srcdir)/util/log.h
+tube.lo tube.o: $(srcdir)/util/tube.c config.h $(srcdir)/util/tube.h $(srcdir)/util/log.h $(srcdir)/util/net_help.h \
  $(srcdir)/util/netevent.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
  $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/services/mesh.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/services/mesh.h \
  $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h
 winsock_event.lo winsock_event.o: $(srcdir)/util/winsock_event.c config.h
-autotrust.lo autotrust.o: $(srcdir)/validator/autotrust.c config.h \
- $(srcdir)/validator/autotrust.h \
+autotrust.lo autotrust.o: $(srcdir)/validator/autotrust.c config.h $(srcdir)/validator/autotrust.h \
  $(srcdir)/util/rbtree.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h \
  $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/validator/val_anchor.h $(srcdir)/validator/val_utils.h \
  $(srcdir)/validator/val_sigcrypt.h $(srcdir)/util/data/dname.h $(srcdir)/util/module.h \
- $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/msgparse.h $(srcdir)/util/net_help.h \
- $(srcdir)/util/config_file.h $(srcdir)/util/regional.h $(srcdir)/util/random.h $(srcdir)/services/mesh.h \
- $(srcdir)/util/netevent.h $(srcdir)/services/modstack.h $(srcdir)/services/cache/rrset.h \
- $(srcdir)/util/storage/slabhash.h $(srcdir)/validator/val_kcache.h
-val_anchor.lo val_anchor.o: $(srcdir)/validator/val_anchor.c config.h \
- $(srcdir)/validator/val_anchor.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h \
+ $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h $(srcdir)/util/regional.h $(srcdir)/util/random.h \
+ $(srcdir)/services/mesh.h $(srcdir)/util/netevent.h $(srcdir)/services/modstack.h \
+ $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h $(srcdir)/validator/val_kcache.h \
+ $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/wire2str.h $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/keyraw.h \
+val_anchor.lo val_anchor.o: $(srcdir)/validator/val_anchor.c config.h $(srcdir)/validator/val_anchor.h \
  $(srcdir)/util/rbtree.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/validator/val_sigcrypt.h \
  $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h $(srcdir)/validator/autotrust.h \
- $(srcdir)/util/data/dname.h $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h
-validator.lo validator.o: $(srcdir)/validator/validator.c config.h \
- $(srcdir)/validator/validator.h \
+ $(srcdir)/util/data/dname.h $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h $(srcdir)/ldns/sbuffer.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/str2wire.h
+validator.lo validator.o: $(srcdir)/validator/validator.c config.h $(srcdir)/validator/validator.h \
  $(srcdir)/util/module.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
  $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/validator/val_utils.h $(srcdir)/validator/val_anchor.h $(srcdir)/util/rbtree.h \
- $(srcdir)/validator/val_kcache.h $(srcdir)/util/storage/slabhash.h $(srcdir)/validator/val_kentry.h \
- $(srcdir)/validator/val_nsec.h $(srcdir)/validator/val_nsec3.h $(srcdir)/validator/val_neg.h \
- $(srcdir)/validator/val_sigcrypt.h $(srcdir)/validator/autotrust.h $(srcdir)/services/cache/dns.h \
- $(srcdir)/util/data/dname.h $(srcdir)/util/net_help.h $(srcdir)/util/regional.h $(srcdir)/util/config_file.h \
- $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/tube.h $(srcdir)/services/mesh.h \
- $(srcdir)/services/modstack.h
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/validator/val_utils.h $(srcdir)/validator/val_anchor.h \
+ $(srcdir)/util/rbtree.h $(srcdir)/validator/val_kcache.h $(srcdir)/util/storage/slabhash.h \
+ $(srcdir)/validator/val_kentry.h $(srcdir)/validator/val_nsec.h $(srcdir)/validator/val_nsec3.h \
+ $(srcdir)/validator/val_neg.h $(srcdir)/validator/val_sigcrypt.h $(srcdir)/validator/autotrust.h \
+ $(srcdir)/services/cache/dns.h $(srcdir)/util/data/dname.h $(srcdir)/util/net_help.h $(srcdir)/util/regional.h \
+ $(srcdir)/util/config_file.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/tube.h \
+ $(srcdir)/services/mesh.h $(srcdir)/services/modstack.h $(srcdir)/ldns/wire2str.h
 val_kcache.lo val_kcache.o: $(srcdir)/validator/val_kcache.c config.h $(srcdir)/validator/val_kcache.h \
  $(srcdir)/util/storage/slabhash.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/validator/val_kentry.h \
- $(srcdir)/util/config_file.h $(srcdir)/util/data/dname.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
-val_kentry.lo val_kentry.o: $(srcdir)/validator/val_kentry.c config.h \
- $(srcdir)/validator/val_kentry.h \
+ $(srcdir)/validator/val_kentry.h $(srcdir)/util/config_file.h $(srcdir)/util/data/dname.h \
+ $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h
+val_kentry.lo val_kentry.o: $(srcdir)/validator/val_kentry.c config.h $(srcdir)/validator/val_kentry.h \
  $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/dname.h $(srcdir)/util/storage/lookup3.h $(srcdir)/util/regional.h $(srcdir)/util/net_help.h
+ $(srcdir)/util/data/dname.h $(srcdir)/util/storage/lookup3.h $(srcdir)/util/regional.h $(srcdir)/util/net_help.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/keyraw.h \
 val_neg.lo val_neg.o: $(srcdir)/validator/val_neg.c config.h \
- $(srcdir)/validator/val_neg.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/rbtree.h \
+ $(srcdir)/validator/val_neg.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/rbtree.h \
  $(srcdir)/validator/val_nsec.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/validator/val_nsec3.h \
- $(srcdir)/validator/val_utils.h $(srcdir)/util/data/dname.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h $(srcdir)/services/cache/rrset.h \
- $(srcdir)/util/storage/slabhash.h $(srcdir)/services/cache/dns.h
+ $(srcdir)/validator/val_nsec3.h $(srcdir)/validator/val_utils.h $(srcdir)/util/data/dname.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h \
+ $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h $(srcdir)/services/cache/dns.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/sbuffer.h
 val_nsec3.lo val_nsec3.o: $(srcdir)/validator/val_nsec3.c config.h \
  $(srcdir)/validator/val_nsec3.h $(srcdir)/util/rbtree.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/validator/validator.h \
- $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/validator/val_utils.h \
- $(srcdir)/validator/val_kentry.h $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h \
- $(srcdir)/util/regional.h $(srcdir)/util/net_help.h $(srcdir)/util/data/dname.h $(srcdir)/validator/val_nsec.h
-val_nsec.lo val_nsec.o: $(srcdir)/validator/val_nsec.c config.h \
- $(srcdir)/validator/val_nsec.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/validator/validator.h \
+ $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/validator/val_utils.h $(srcdir)/validator/val_kentry.h \
+ $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h $(srcdir)/util/regional.h \
+ $(srcdir)/util/net_help.h $(srcdir)/util/data/dname.h $(srcdir)/validator/val_nsec.h $(srcdir)/ldns/sbuffer.h
+val_nsec.lo val_nsec.o: $(srcdir)/validator/val_nsec.c config.h $(srcdir)/validator/val_nsec.h \
  $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
  $(srcdir)/validator/val_utils.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/net_help.h $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h
-val_secalgo.lo val_secalgo.o: $(srcdir)/validator/val_secalgo.c config.h \
- $(srcdir)/validator/val_secalgo.h \
+ $(srcdir)/util/net_help.h $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h
+val_secalgo.lo val_secalgo.o: $(srcdir)/validator/val_secalgo.c config.h $(srcdir)/validator/val_secalgo.h \
  $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/keyraw.h \
+ $(srcdir)/ldns/sbuffer.h \
  
 val_sigcrypt.lo val_sigcrypt.o: $(srcdir)/validator/val_sigcrypt.c config.h \
- $(srcdir)/validator/val_sigcrypt.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/validator/val_secalgo.h $(srcdir)/validator/validator.h $(srcdir)/util/module.h \
- $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/msgparse.h $(srcdir)/validator/val_utils.h \
- $(srcdir)/util/data/dname.h $(srcdir)/util/rbtree.h $(srcdir)/util/net_help.h $(srcdir)/util/regional.h \
+ $(srcdir)/validator/val_sigcrypt.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h \
+ $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/validator/val_secalgo.h $(srcdir)/validator/validator.h \
+ $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/validator/val_utils.h $(srcdir)/util/data/dname.h $(srcdir)/util/rbtree.h \
+ $(srcdir)/util/net_help.h $(srcdir)/util/regional.h $(srcdir)/ldns/keyraw.h \
+ $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/parseutil.h $(srcdir)/ldns/wire2str.h \
  
 val_utils.lo val_utils.o: $(srcdir)/validator/val_utils.c config.h $(srcdir)/validator/val_utils.h \
  $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/validator/validator.h \
- $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/validator/val_kentry.h \
+ $(srcdir)/validator/validator.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/validator/val_kentry.h \
  $(srcdir)/validator/val_sigcrypt.h $(srcdir)/validator/val_anchor.h $(srcdir)/util/rbtree.h \
  $(srcdir)/validator/val_nsec.h $(srcdir)/validator/val_neg.h $(srcdir)/services/cache/rrset.h \
  $(srcdir)/util/storage/slabhash.h $(srcdir)/services/cache/dns.h $(srcdir)/util/data/dname.h \
  $(srcdir)/util/net_help.h $(srcdir)/util/regional.h
 checklocks.lo checklocks.o: $(srcdir)/testcode/checklocks.c config.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
  $(srcdir)/testcode/checklocks.h
-unitanchor.lo unitanchor.o: $(srcdir)/testcode/unitanchor.c config.h \
- $(srcdir)/util/log.h $(srcdir)/util/data/dname.h \
+unitanchor.lo unitanchor.o: $(srcdir)/testcode/unitanchor.c config.h $(srcdir)/util/log.h $(srcdir)/util/data/dname.h \
  $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/testcode/unitmain.h \
- $(srcdir)/validator/val_anchor.h $(srcdir)/util/rbtree.h
-unitdname.lo unitdname.o: $(srcdir)/testcode/unitdname.c config.h \
- $(srcdir)/util/log.h \
- $(srcdir)/testcode/unitmain.h $(srcdir)/util/data/dname.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/locks.h
+ $(srcdir)/validator/val_anchor.h $(srcdir)/util/rbtree.h $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/rrdef.h
+unitdname.lo unitdname.o: $(srcdir)/testcode/unitdname.c config.h $(srcdir)/util/log.h $(srcdir)/testcode/unitmain.h \
+ $(srcdir)/util/data/dname.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/ldns/sbuffer.h \
+ $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/rrdef.h
 unitlruhash.lo unitlruhash.o: $(srcdir)/testcode/unitlruhash.c config.h $(srcdir)/testcode/unitmain.h \
- $(srcdir)/util/log.h \
- $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/locks.h $(srcdir)/util/storage/slabhash.h
+ $(srcdir)/util/log.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/storage/slabhash.h
 unitmain.lo unitmain.o: $(srcdir)/testcode/unitmain.c config.h \
- $(srcdir)/util/log.h $(srcdir)/testcode/unitmain.h \
- $(srcdir)/util/alloc.h $(srcdir)/util/locks.h $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h $(srcdir)/util/rtt.h \
- $(srcdir)/services/cache/infra.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/random.h
-unitmsgparse.lo unitmsgparse.o: $(srcdir)/testcode/unitmsgparse.c config.h \
- $(srcdir)/util/log.h $(srcdir)/testcode/unitmain.h \
- $(srcdir)/util/data/msgparse.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
- $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgencode.h \
- $(srcdir)/util/data/dname.h $(srcdir)/util/alloc.h $(srcdir)/util/regional.h $(srcdir)/util/net_help.h \
- $(srcdir)/testcode/readhex.h
-unitneg.lo unitneg.o: $(srcdir)/testcode/unitneg.c config.h $(srcdir)/util/log.h \
- $(srcdir)/util/net_help.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/keyraw.h \
+ $(srcdir)/util/log.h $(srcdir)/testcode/unitmain.h $(srcdir)/util/alloc.h $(srcdir)/util/locks.h $(srcdir)/util/net_help.h \
+ $(srcdir)/util/config_file.h $(srcdir)/util/rtt.h $(srcdir)/services/cache/infra.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/random.h
+unitmsgparse.lo unitmsgparse.o: $(srcdir)/testcode/unitmsgparse.c config.h $(srcdir)/util/log.h \
+ $(srcdir)/testcode/unitmain.h $(srcdir)/util/data/msgparse.h $(srcdir)/util/storage/lruhash.h \
+ $(srcdir)/util/locks.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgencode.h $(srcdir)/util/data/dname.h \
+ $(srcdir)/util/alloc.h $(srcdir)/util/regional.h $(srcdir)/util/net_help.h $(srcdir)/testcode/readhex.h \
+ $(srcdir)/testcode/testpkts.h $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/wire2str.h
+unitneg.lo unitneg.o: $(srcdir)/testcode/unitneg.c config.h $(srcdir)/util/log.h $(srcdir)/util/net_help.h \
  $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
- $(srcdir)/util/data/dname.h \
- $(srcdir)/testcode/unitmain.h $(srcdir)/validator/val_neg.h $(srcdir)/util/rbtree.h
+ $(srcdir)/util/data/dname.h $(srcdir)/testcode/unitmain.h $(srcdir)/validator/val_neg.h $(srcdir)/util/rbtree.h \
+ $(srcdir)/ldns/rrdef.h
 unitregional.lo unitregional.o: $(srcdir)/testcode/unitregional.c config.h $(srcdir)/testcode/unitmain.h \
- $(srcdir)/util/log.h \
- $(srcdir)/util/regional.h
+ $(srcdir)/util/log.h $(srcdir)/util/regional.h
 unitslabhash.lo unitslabhash.o: $(srcdir)/testcode/unitslabhash.c config.h $(srcdir)/testcode/unitmain.h \
- $(srcdir)/util/log.h \
- $(srcdir)/util/storage/slabhash.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h
+ $(srcdir)/util/log.h $(srcdir)/util/storage/slabhash.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h
 unitverify.lo unitverify.o: $(srcdir)/testcode/unitverify.c config.h $(srcdir)/util/log.h \
- $(srcdir)/testcode/unitmain.h \
- $(srcdir)/validator/val_sigcrypt.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/locks.h \
- $(srcdir)/validator/val_secalgo.h \
+ $(srcdir)/testcode/unitmain.h $(srcdir)/validator/val_sigcrypt.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/validator/val_secalgo.h \
  $(srcdir)/validator/val_nsec.h $(srcdir)/validator/val_nsec3.h $(srcdir)/util/rbtree.h \
  $(srcdir)/validator/validator.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/validator/val_utils.h $(srcdir)/testcode/ldns-testpkts.h \
- $(srcdir)/util/data/dname.h \
- $(srcdir)/util/regional.h $(srcdir)/util/alloc.h $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h
-readhex.lo readhex.o: $(srcdir)/testcode/readhex.c config.h $(srcdir)/testcode/readhex.h \
- $(srcdir)/util/log.h
-ldns-testpkts.lo ldns-testpkts.o: $(srcdir)/testcode/ldns-testpkts.c config.h \
- $(srcdir)/testcode/ldns-testpkts.h
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/validator/val_utils.h \
+ $(srcdir)/testcode/testpkts.h $(srcdir)/util/data/dname.h $(srcdir)/util/regional.h $(srcdir)/util/alloc.h \
+ $(srcdir)/util/net_help.h $(srcdir)/util/config_file.h $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/keyraw.h \
+ $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/wire2str.h
+readhex.lo readhex.o: $(srcdir)/testcode/readhex.c config.h $(srcdir)/testcode/readhex.h $(srcdir)/util/log.h \
+ $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/parseutil.h
+testpkts.lo testpkts.o: $(srcdir)/testcode/testpkts.c config.h $(srcdir)/testcode/testpkts.h \
+ $(srcdir)/util/net_help.h $(srcdir)/util/log.h $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/pkthdr.h \
+ $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/wire2str.h
 acl_list.lo acl_list.o: $(srcdir)/daemon/acl_list.c config.h $(srcdir)/daemon/acl_list.h \
  $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h $(srcdir)/util/regional.h $(srcdir)/util/log.h \
- $(srcdir)/util/config_file.h \
- $(srcdir)/util/net_help.h
+ $(srcdir)/util/config_file.h $(srcdir)/util/net_help.h
 cachedump.lo cachedump.o: $(srcdir)/daemon/cachedump.c config.h \
- $(srcdir)/daemon/cachedump.h \
- $(srcdir)/daemon/remote.h $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/alloc.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h $(srcdir)/daemon/stats.h \
- $(srcdir)/util/timehist.h $(srcdir)/util/module.h $(srcdir)/services/cache/rrset.h \
- $(srcdir)/util/storage/slabhash.h $(srcdir)/services/cache/dns.h $(srcdir)/services/cache/infra.h \
- $(srcdir)/util/rtt.h $(srcdir)/util/regional.h $(srcdir)/util/net_help.h $(srcdir)/util/data/dname.h \
- $(srcdir)/iterator/iterator.h $(srcdir)/services/outbound_list.h $(srcdir)/iterator/iter_delegpt.h \
- $(srcdir)/iterator/iter_utils.h $(srcdir)/iterator/iter_resptype.h $(srcdir)/iterator/iter_fwd.h \
- $(srcdir)/util/rbtree.h $(srcdir)/iterator/iter_hints.h $(srcdir)/util/storage/dnstree.h
+ $(srcdir)/daemon/cachedump.h $(srcdir)/daemon/remote.h $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h \
+ $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/alloc.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/daemon/stats.h $(srcdir)/util/timehist.h $(srcdir)/util/module.h \
+ $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h $(srcdir)/services/cache/dns.h \
+ $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h $(srcdir)/util/regional.h $(srcdir)/util/net_help.h \
+ $(srcdir)/util/data/dname.h $(srcdir)/iterator/iterator.h $(srcdir)/services/outbound_list.h \
+ $(srcdir)/iterator/iter_delegpt.h $(srcdir)/iterator/iter_utils.h $(srcdir)/iterator/iter_resptype.h \
+ $(srcdir)/iterator/iter_fwd.h $(srcdir)/util/rbtree.h $(srcdir)/iterator/iter_hints.h \
+ $(srcdir)/util/storage/dnstree.h $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/wire2str.h $(srcdir)/ldns/str2wire.h
 daemon.lo daemon.o: $(srcdir)/daemon/daemon.c config.h \
- $(srcdir)/daemon/daemon.h $(srcdir)/util/locks.h \
- $(srcdir)/util/log.h $(srcdir)/util/alloc.h $(srcdir)/services/modstack.h $(srcdir)/daemon/worker.h \
- $(srcdir)/util/netevent.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h $(srcdir)/daemon/stats.h \
- $(srcdir)/util/timehist.h $(srcdir)/util/module.h $(srcdir)/daemon/remote.h $(srcdir)/daemon/acl_list.h \
- $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h $(srcdir)/util/config_file.h \
- $(srcdir)/util/storage/lookup3.h $(srcdir)/util/storage/slabhash.h $(srcdir)/services/listen_dnsport.h \
- $(srcdir)/services/cache/rrset.h $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h \
- $(srcdir)/services/localzone.h $(srcdir)/util/random.h $(srcdir)/util/tube.h $(srcdir)/util/net_help.h
+ $(srcdir)/daemon/daemon.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/alloc.h $(srcdir)/services/modstack.h \
+ $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/daemon/stats.h $(srcdir)/util/timehist.h $(srcdir)/util/module.h \
+ $(srcdir)/daemon/remote.h \
+ $(srcdir)/daemon/acl_list.h $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h \
+ $(srcdir)/util/config_file.h $(srcdir)/util/storage/lookup3.h $(srcdir)/util/storage/slabhash.h \
+ $(srcdir)/services/listen_dnsport.h $(srcdir)/services/cache/rrset.h $(srcdir)/services/cache/infra.h \
+ $(srcdir)/util/rtt.h $(srcdir)/services/localzone.h $(srcdir)/util/random.h $(srcdir)/util/tube.h \
+ $(srcdir)/util/net_help.h $(srcdir)/ldns/keyraw.h
 remote.lo remote.o: $(srcdir)/daemon/remote.c config.h \
  $(srcdir)/daemon/remote.h \
  $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/alloc.h \
  $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h $(srcdir)/daemon/stats.h $(srcdir)/util/timehist.h $(srcdir)/util/module.h \
- $(srcdir)/daemon/daemon.h $(srcdir)/services/modstack.h $(srcdir)/daemon/cachedump.h \
- $(srcdir)/util/config_file.h $(srcdir)/util/net_help.h $(srcdir)/services/listen_dnsport.h \
- $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h $(srcdir)/services/cache/infra.h \
- $(srcdir)/util/rtt.h $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h $(srcdir)/services/localzone.h \
- $(srcdir)/util/fptr_wlist.h $(srcdir)/util/tube.h $(srcdir)/util/data/dname.h $(srcdir)/validator/validator.h \
- $(srcdir)/validator/val_utils.h $(srcdir)/validator/val_kcache.h $(srcdir)/validator/val_kentry.h \
- $(srcdir)/validator/val_anchor.h $(srcdir)/iterator/iterator.h $(srcdir)/services/outbound_list.h \
- $(srcdir)/iterator/iter_fwd.h $(srcdir)/iterator/iter_hints.h $(srcdir)/util/storage/dnstree.h \
- $(srcdir)/iterator/iter_delegpt.h $(srcdir)/services/outside_network.h
-stats.lo stats.o: $(srcdir)/daemon/stats.c config.h \
- $(srcdir)/daemon/stats.h \
- $(srcdir)/util/timehist.h $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/alloc.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h $(srcdir)/util/module.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/daemon/stats.h \
+ $(srcdir)/util/timehist.h $(srcdir)/util/module.h $(srcdir)/daemon/daemon.h $(srcdir)/services/modstack.h \
+ $(srcdir)/daemon/cachedump.h $(srcdir)/util/config_file.h $(srcdir)/util/net_help.h \
+ $(srcdir)/services/listen_dnsport.h $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h \
+ $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h \
+ $(srcdir)/services/localzone.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/tube.h $(srcdir)/util/data/dname.h \
+ $(srcdir)/validator/validator.h $(srcdir)/validator/val_utils.h $(srcdir)/validator/val_kcache.h \
+ $(srcdir)/validator/val_kentry.h $(srcdir)/validator/val_anchor.h $(srcdir)/iterator/iterator.h \
+ $(srcdir)/services/outbound_list.h $(srcdir)/iterator/iter_fwd.h $(srcdir)/iterator/iter_hints.h \
+ $(srcdir)/util/storage/dnstree.h $(srcdir)/iterator/iter_delegpt.h \
+ $(srcdir)/services/outside_network.h $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/parseutil.h \
+ $(srcdir)/ldns/wire2str.h $(srcdir)/ldns/sbuffer.h
+stats.lo stats.o: $(srcdir)/daemon/stats.c config.h $(srcdir)/daemon/stats.h $(srcdir)/util/timehist.h \
+ $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/alloc.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/module.h \
  $(srcdir)/daemon/daemon.h $(srcdir)/services/modstack.h $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h \
  $(srcdir)/services/outside_network.h $(srcdir)/util/config_file.h $(srcdir)/util/tube.h \
- $(srcdir)/util/net_help.h $(srcdir)/validator/validator.h $(srcdir)/validator/val_utils.h
-unbound.lo unbound.o: $(srcdir)/daemon/unbound.c config.h $(srcdir)/util/log.h \
- $(srcdir)/daemon/daemon.h $(srcdir)/util/locks.h \
- $(srcdir)/util/alloc.h $(srcdir)/services/modstack.h $(srcdir)/daemon/remote.h \
+ $(srcdir)/util/net_help.h $(srcdir)/validator/validator.h $(srcdir)/validator/val_utils.h \
+ $(srcdir)/ldns/sbuffer.h
+unbound.lo unbound.o: $(srcdir)/daemon/unbound.c config.h $(srcdir)/util/log.h $(srcdir)/daemon/daemon.h \
+ $(srcdir)/util/locks.h $(srcdir)/util/alloc.h $(srcdir)/services/modstack.h $(srcdir)/daemon/remote.h \
  $(srcdir)/util/config_file.h $(srcdir)/util/storage/slabhash.h $(srcdir)/util/storage/lruhash.h \
  $(srcdir)/services/listen_dnsport.h $(srcdir)/util/netevent.h $(srcdir)/services/cache/rrset.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/services/cache/infra.h \
- $(srcdir)/util/rtt.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/net_help.h \
- $(srcdir)/util/mini_event.h $(srcdir)/util/rbtree.h
-worker.lo worker.o: $(srcdir)/daemon/worker.c config.h \
- $(srcdir)/util/log.h $(srcdir)/util/net_help.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/util/net_help.h $(srcdir)/util/mini_event.h $(srcdir)/util/rbtree.h
+worker.lo worker.o: $(srcdir)/daemon/worker.c config.h $(srcdir)/util/log.h $(srcdir)/util/net_help.h \
  $(srcdir)/util/random.h $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/locks.h $(srcdir)/util/alloc.h \
  $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h $(srcdir)/daemon/stats.h $(srcdir)/util/timehist.h $(srcdir)/util/module.h \
- $(srcdir)/daemon/daemon.h $(srcdir)/services/modstack.h $(srcdir)/daemon/remote.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/daemon/stats.h \
+ $(srcdir)/util/timehist.h $(srcdir)/util/module.h $(srcdir)/daemon/daemon.h $(srcdir)/services/modstack.h \
+ $(srcdir)/daemon/remote.h \
  $(srcdir)/daemon/acl_list.h $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h \
  $(srcdir)/util/config_file.h $(srcdir)/util/regional.h $(srcdir)/util/storage/slabhash.h \
  $(srcdir)/services/listen_dnsport.h $(srcdir)/services/outside_network.h \
@@ -1030,24 +963,26 @@ worker.lo worker.o: $(srcdir)/daemon/worker.c config.h \
  $(srcdir)/util/rtt.h $(srcdir)/services/cache/dns.h $(srcdir)/services/mesh.h $(srcdir)/services/localzone.h \
  $(srcdir)/util/data/msgencode.h $(srcdir)/util/data/dname.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/tube.h \
  $(srcdir)/iterator/iter_fwd.h $(srcdir)/iterator/iter_hints.h $(srcdir)/validator/autotrust.h \
- $(srcdir)/validator/val_anchor.h
-testbound.lo testbound.o: $(srcdir)/testcode/testbound.c config.h $(srcdir)/testcode/ldns-testpkts.h \
- $(srcdir)/testcode/replay.h \
- $(srcdir)/util/netevent.h $(srcdir)/util/rbtree.h $(srcdir)/testcode/fake_event.h $(srcdir)/daemon/remote.h \
- $(srcdir)/util/config_file.h $(srcdir)/daemon/unbound.c $(srcdir)/util/log.h $(srcdir)/daemon/daemon.h \
- $(srcdir)/util/locks.h $(srcdir)/util/alloc.h $(srcdir)/services/modstack.h $(srcdir)/util/storage/slabhash.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/services/listen_dnsport.h $(srcdir)/services/cache/rrset.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h \
- $(srcdir)/util/data/msgreply.h $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h $(srcdir)/util/net_help.h \
- $(srcdir)/util/mini_event.h $(srcdir)/util/rbtree.h
-ldns-testpkts.lo ldns-testpkts.o: $(srcdir)/testcode/ldns-testpkts.c config.h \
- $(srcdir)/testcode/ldns-testpkts.h
-worker.lo worker.o: $(srcdir)/daemon/worker.c config.h \
- $(srcdir)/util/log.h $(srcdir)/util/net_help.h \
+ $(srcdir)/validator/val_anchor.h $(srcdir)/ldns/sbuffer.h
+testbound.lo testbound.o: $(srcdir)/testcode/testbound.c config.h $(srcdir)/testcode/testpkts.h \
+ $(srcdir)/testcode/replay.h $(srcdir)/util/netevent.h $(srcdir)/util/rbtree.h $(srcdir)/testcode/fake_event.h \
+ $(srcdir)/daemon/remote.h \
+ $(srcdir)/util/config_file.h $(srcdir)/ldns/keyraw.h $(srcdir)/daemon/unbound.c $(srcdir)/util/log.h \
+ $(srcdir)/daemon/daemon.h $(srcdir)/util/locks.h $(srcdir)/util/alloc.h $(srcdir)/services/modstack.h \
+ $(srcdir)/util/storage/slabhash.h $(srcdir)/util/storage/lruhash.h $(srcdir)/services/listen_dnsport.h \
+ $(srcdir)/services/cache/rrset.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/services/cache/infra.h \
+ $(srcdir)/util/rtt.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/module.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/net_help.h $(srcdir)/util/mini_event.h \
+ $(srcdir)/util/rbtree.h
+testpkts.lo testpkts.o: $(srcdir)/testcode/testpkts.c config.h $(srcdir)/testcode/testpkts.h \
+ $(srcdir)/util/net_help.h $(srcdir)/util/log.h $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/pkthdr.h \
+ $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/wire2str.h
+worker.lo worker.o: $(srcdir)/daemon/worker.c config.h $(srcdir)/util/log.h $(srcdir)/util/net_help.h \
  $(srcdir)/util/random.h $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/locks.h $(srcdir)/util/alloc.h \
  $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h $(srcdir)/daemon/stats.h $(srcdir)/util/timehist.h $(srcdir)/util/module.h \
- $(srcdir)/daemon/daemon.h $(srcdir)/services/modstack.h $(srcdir)/daemon/remote.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/daemon/stats.h \
+ $(srcdir)/util/timehist.h $(srcdir)/util/module.h $(srcdir)/daemon/daemon.h $(srcdir)/services/modstack.h \
+ $(srcdir)/daemon/remote.h \
  $(srcdir)/daemon/acl_list.h $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h \
  $(srcdir)/util/config_file.h $(srcdir)/util/regional.h $(srcdir)/util/storage/slabhash.h \
  $(srcdir)/services/listen_dnsport.h $(srcdir)/services/outside_network.h \
@@ -1055,171 +990,155 @@ worker.lo worker.o: $(srcdir)/daemon/worker.c config.h \
  $(srcdir)/util/rtt.h $(srcdir)/services/cache/dns.h $(srcdir)/services/mesh.h $(srcdir)/services/localzone.h \
  $(srcdir)/util/data/msgencode.h $(srcdir)/util/data/dname.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/tube.h \
  $(srcdir)/iterator/iter_fwd.h $(srcdir)/iterator/iter_hints.h $(srcdir)/validator/autotrust.h \
- $(srcdir)/validator/val_anchor.h
+ $(srcdir)/validator/val_anchor.h $(srcdir)/ldns/sbuffer.h
 acl_list.lo acl_list.o: $(srcdir)/daemon/acl_list.c config.h $(srcdir)/daemon/acl_list.h \
  $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h $(srcdir)/util/regional.h $(srcdir)/util/log.h \
- $(srcdir)/util/config_file.h \
- $(srcdir)/util/net_help.h
+ $(srcdir)/util/config_file.h $(srcdir)/util/net_help.h
 daemon.lo daemon.o: $(srcdir)/daemon/daemon.c config.h \
- $(srcdir)/daemon/daemon.h $(srcdir)/util/locks.h \
- $(srcdir)/util/log.h $(srcdir)/util/alloc.h $(srcdir)/services/modstack.h $(srcdir)/daemon/worker.h \
- $(srcdir)/util/netevent.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h $(srcdir)/daemon/stats.h \
- $(srcdir)/util/timehist.h $(srcdir)/util/module.h $(srcdir)/daemon/remote.h $(srcdir)/daemon/acl_list.h \
- $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h $(srcdir)/util/config_file.h \
- $(srcdir)/util/storage/lookup3.h $(srcdir)/util/storage/slabhash.h $(srcdir)/services/listen_dnsport.h \
- $(srcdir)/services/cache/rrset.h $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h \
- $(srcdir)/services/localzone.h $(srcdir)/util/random.h $(srcdir)/util/tube.h $(srcdir)/util/net_help.h
-stats.lo stats.o: $(srcdir)/daemon/stats.c config.h \
- $(srcdir)/daemon/stats.h \
- $(srcdir)/util/timehist.h $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/alloc.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h $(srcdir)/util/module.h \
+ $(srcdir)/daemon/daemon.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/alloc.h $(srcdir)/services/modstack.h \
+ $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/daemon/stats.h $(srcdir)/util/timehist.h $(srcdir)/util/module.h \
+ $(srcdir)/daemon/remote.h \
+ $(srcdir)/daemon/acl_list.h $(srcdir)/util/storage/dnstree.h $(srcdir)/util/rbtree.h \
+ $(srcdir)/util/config_file.h $(srcdir)/util/storage/lookup3.h $(srcdir)/util/storage/slabhash.h \
+ $(srcdir)/services/listen_dnsport.h $(srcdir)/services/cache/rrset.h $(srcdir)/services/cache/infra.h \
+ $(srcdir)/util/rtt.h $(srcdir)/services/localzone.h $(srcdir)/util/random.h $(srcdir)/util/tube.h \
+ $(srcdir)/util/net_help.h $(srcdir)/ldns/keyraw.h
+stats.lo stats.o: $(srcdir)/daemon/stats.c config.h $(srcdir)/daemon/stats.h $(srcdir)/util/timehist.h \
+ $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/alloc.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/module.h \
  $(srcdir)/daemon/daemon.h $(srcdir)/services/modstack.h $(srcdir)/services/mesh.h $(srcdir)/util/rbtree.h \
  $(srcdir)/services/outside_network.h $(srcdir)/util/config_file.h $(srcdir)/util/tube.h \
- $(srcdir)/util/net_help.h $(srcdir)/validator/validator.h $(srcdir)/validator/val_utils.h
-replay.lo replay.o: $(srcdir)/testcode/replay.c config.h $(srcdir)/util/log.h \
- $(srcdir)/util/net_help.h \
- $(srcdir)/util/config_file.h $(srcdir)/testcode/replay.h $(srcdir)/util/netevent.h \
- $(srcdir)/testcode/ldns-testpkts.h \
- $(srcdir)/util/rbtree.h \
- $(srcdir)/testcode/fake_event.h
+ $(srcdir)/util/net_help.h $(srcdir)/validator/validator.h $(srcdir)/validator/val_utils.h \
+ $(srcdir)/ldns/sbuffer.h
+replay.lo replay.o: $(srcdir)/testcode/replay.c config.h $(srcdir)/util/log.h $(srcdir)/util/net_help.h \
+ $(srcdir)/util/config_file.h $(srcdir)/testcode/replay.h $(srcdir)/util/netevent.h $(srcdir)/testcode/testpkts.h \
+ $(srcdir)/util/rbtree.h $(srcdir)/testcode/fake_event.h $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/rrdef.h
 fake_event.lo fake_event.o: $(srcdir)/testcode/fake_event.c config.h $(srcdir)/testcode/fake_event.h \
- $(srcdir)/util/netevent.h \
- $(srcdir)/util/net_help.h $(srcdir)/util/log.h \
- $(srcdir)/util/data/msgparse.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
- $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgencode.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/config_file.h $(srcdir)/services/listen_dnsport.h $(srcdir)/services/outside_network.h \
- $(srcdir)/util/rbtree.h $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h $(srcdir)/testcode/replay.h \
- $(srcdir)/testcode/ldns-testpkts.h \
- $(srcdir)/util/fptr_wlist.h \
- $(srcdir)/util/module.h $(srcdir)/util/tube.h $(srcdir)/services/mesh.h $(srcdir)/services/modstack.h
-lock_verify.lo lock_verify.o: $(srcdir)/testcode/lock_verify.c config.h $(srcdir)/util/log.h \
- $(srcdir)/util/rbtree.h $(srcdir)/util/locks.h \
- $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/module.h \
- $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/tube.h $(srcdir)/services/mesh.h \
- $(srcdir)/services/modstack.h
-pktview.lo pktview.o: $(srcdir)/testcode/pktview.c config.h \
- $(srcdir)/util/log.h $(srcdir)/util/data/dname.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/testcode/unitmain.h $(srcdir)/testcode/readhex.h
-readhex.lo readhex.o: $(srcdir)/testcode/readhex.c config.h $(srcdir)/testcode/readhex.h \
- $(srcdir)/util/log.h
-signit.lo signit.o: $(srcdir)/testcode/signit.c config.h \
- $(srcdir)/util/log.h $(srcdir)/util/config_file.h \
- $(srcdir)/util/net_help.h
-memstats.lo memstats.o: $(srcdir)/testcode/memstats.c config.h $(srcdir)/util/log.h \
- $(srcdir)/util/rbtree.h $(srcdir)/util/locks.h \
- $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/module.h \
- $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/tube.h $(srcdir)/services/mesh.h \
- $(srcdir)/services/modstack.h
+ $(srcdir)/util/netevent.h $(srcdir)/util/net_help.h $(srcdir)/util/log.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgencode.h \
+ $(srcdir)/util/data/dname.h $(srcdir)/util/config_file.h $(srcdir)/services/listen_dnsport.h \
+ $(srcdir)/services/outside_network.h $(srcdir)/util/rbtree.h $(srcdir)/services/cache/infra.h \
+ $(srcdir)/util/rtt.h $(srcdir)/testcode/replay.h $(srcdir)/testcode/testpkts.h $(srcdir)/util/fptr_wlist.h \
+ $(srcdir)/util/module.h $(srcdir)/util/tube.h $(srcdir)/services/mesh.h $(srcdir)/services/modstack.h \
+ $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/wire2str.h $(srcdir)/ldns/str2wire.h
+lock_verify.lo lock_verify.o: $(srcdir)/testcode/lock_verify.c config.h $(srcdir)/util/log.h $(srcdir)/util/rbtree.h \
+ $(srcdir)/util/locks.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/storage/lruhash.h \
+ $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/tube.h \
+ $(srcdir)/services/mesh.h $(srcdir)/services/modstack.h
+pktview.lo pktview.o: $(srcdir)/testcode/pktview.c config.h $(srcdir)/util/log.h $(srcdir)/util/data/dname.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/testcode/unitmain.h $(srcdir)/testcode/readhex.h $(srcdir)/ldns/sbuffer.h \
+ $(srcdir)/ldns/parseutil.h
+readhex.lo readhex.o: $(srcdir)/testcode/readhex.c config.h $(srcdir)/testcode/readhex.h $(srcdir)/util/log.h \
+ $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/parseutil.h
+memstats.lo memstats.o: $(srcdir)/testcode/memstats.c config.h $(srcdir)/util/log.h $(srcdir)/util/rbtree.h \
+ $(srcdir)/util/locks.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/netevent.h $(srcdir)/util/storage/lruhash.h \
+ $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/tube.h \
+ $(srcdir)/services/mesh.h $(srcdir)/services/modstack.h
 unbound-checkconf.lo unbound-checkconf.o: $(srcdir)/smallapp/unbound-checkconf.c config.h $(srcdir)/util/log.h \
- $(srcdir)/util/config_file.h \
- $(srcdir)/util/module.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/net_help.h \
- $(srcdir)/util/regional.h $(srcdir)/iterator/iterator.h $(srcdir)/services/outbound_list.h \
- $(srcdir)/iterator/iter_fwd.h $(srcdir)/util/rbtree.h $(srcdir)/iterator/iter_hints.h \
- $(srcdir)/util/storage/dnstree.h $(srcdir)/validator/validator.h $(srcdir)/validator/val_utils.h \
- $(srcdir)/services/localzone.h
-worker_cb.lo worker_cb.o: $(srcdir)/smallapp/worker_cb.c config.h $(srcdir)/util/log.h \
- $(srcdir)/services/mesh.h \
+ $(srcdir)/util/config_file.h $(srcdir)/util/module.h $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/net_help.h $(srcdir)/util/regional.h \
+ $(srcdir)/iterator/iterator.h $(srcdir)/services/outbound_list.h $(srcdir)/iterator/iter_fwd.h \
+ $(srcdir)/util/rbtree.h $(srcdir)/iterator/iter_hints.h $(srcdir)/util/storage/dnstree.h \
+ $(srcdir)/validator/validator.h $(srcdir)/validator/val_utils.h $(srcdir)/services/localzone.h \
+ $(srcdir)/ldns/sbuffer.h
+worker_cb.lo worker_cb.o: $(srcdir)/smallapp/worker_cb.c config.h $(srcdir)/util/log.h $(srcdir)/services/mesh.h \
  $(srcdir)/util/rbtree.h $(srcdir)/util/netevent.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h \
- $(srcdir)/util/module.h \
- $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/services/modstack.h
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h \
+ $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
+ $(srcdir)/services/modstack.h
 context.lo context.o: $(srcdir)/libunbound/context.c config.h $(srcdir)/libunbound/context.h \
- $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/alloc.h $(srcdir)/util/rbtree.h \
- $(srcdir)/services/modstack.h $(srcdir)/libunbound/unbound.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/util/module.h \
- $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/config_file.h \
- $(srcdir)/util/net_help.h $(srcdir)/services/localzone.h $(srcdir)/services/cache/rrset.h \
- $(srcdir)/util/storage/slabhash.h $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h
+ $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/alloc.h $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h \
+ $(srcdir)/libunbound/unbound.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h \
+ $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/util/config_file.h $(srcdir)/util/net_help.h $(srcdir)/services/localzone.h \
+ $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h $(srcdir)/services/cache/infra.h \
+ $(srcdir)/util/rtt.h $(srcdir)/ldns/sbuffer.h
 libunbound.lo libunbound.o: $(srcdir)/libunbound/libunbound.c $(srcdir)/libunbound/unbound.h \
  $(srcdir)/libunbound/unbound-event.h config.h $(srcdir)/libunbound/context.h $(srcdir)/util/locks.h \
- $(srcdir)/util/log.h \
- $(srcdir)/util/alloc.h $(srcdir)/util/rbtree.h \
- $(srcdir)/services/modstack.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h \
- $(srcdir)/libunbound/libworker.h \
+ $(srcdir)/util/log.h $(srcdir)/util/alloc.h $(srcdir)/util/rbtree.h $(srcdir)/services/modstack.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h $(srcdir)/libunbound/libworker.h \
  $(srcdir)/util/config_file.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/regional.h $(srcdir)/util/random.h $(srcdir)/util/net_help.h $(srcdir)/util/tube.h \
- $(srcdir)/services/localzone.h $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h \
- $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/regional.h \
+ $(srcdir)/util/random.h $(srcdir)/util/net_help.h $(srcdir)/util/tube.h $(srcdir)/services/localzone.h \
+ $(srcdir)/services/cache/infra.h $(srcdir)/util/rtt.h $(srcdir)/services/cache/rrset.h \
+ $(srcdir)/util/storage/slabhash.h $(srcdir)/ldns/sbuffer.h
 libworker.lo libworker.o: $(srcdir)/libunbound/libworker.c config.h \
  $(srcdir)/libunbound/libworker.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h \
  $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/libunbound/context.h $(srcdir)/util/alloc.h $(srcdir)/util/rbtree.h \
  $(srcdir)/services/modstack.h $(srcdir)/libunbound/unbound.h $(srcdir)/libunbound/unbound-event.h \
  $(srcdir)/services/outside_network.h $(srcdir)/util/netevent.h $(srcdir)/services/mesh.h \
- $(srcdir)/util/data/msgparse.h $(srcdir)/util/module.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/services/localzone.h $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h \
- $(srcdir)/services/outbound_list.h $(srcdir)/util/regional.h $(srcdir)/util/random.h \
- $(srcdir)/util/config_file.h $(srcdir)/util/storage/lookup3.h $(srcdir)/util/net_help.h \
+ $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/module.h \
+ $(srcdir)/util/data/msgreply.h $(srcdir)/services/localzone.h $(srcdir)/services/cache/rrset.h \
+ $(srcdir)/util/storage/slabhash.h $(srcdir)/services/outbound_list.h $(srcdir)/util/regional.h \
+ $(srcdir)/util/random.h $(srcdir)/util/config_file.h $(srcdir)/util/storage/lookup3.h $(srcdir)/util/net_help.h \
  $(srcdir)/util/data/dname.h $(srcdir)/util/data/msgencode.h $(srcdir)/util/tube.h $(srcdir)/iterator/iter_fwd.h \
- $(srcdir)/iterator/iter_hints.h $(srcdir)/util/storage/dnstree.h
+ $(srcdir)/iterator/iter_hints.h $(srcdir)/util/storage/dnstree.h $(srcdir)/ldns/sbuffer.h \
+ $(srcdir)/ldns/str2wire.h
 unbound-host.lo unbound-host.o: $(srcdir)/smallapp/unbound-host.c config.h $(srcdir)/libunbound/unbound.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/wire2str.h
 asynclook.lo asynclook.o: $(srcdir)/testcode/asynclook.c config.h $(srcdir)/libunbound/unbound.h \
- $(srcdir)/libunbound/context.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/alloc.h $(srcdir)/util/rbtree.h \
+ $(srcdir)/libunbound/context.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/alloc.h $(srcdir)/util/rbtree.h \
  $(srcdir)/services/modstack.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/storage/lruhash.h \
-streamtcp.lo streamtcp.o: $(srcdir)/testcode/streamtcp.c config.h \
- $(srcdir)/util/locks.h $(srcdir)/util/log.h \
+ $(srcdir)/ldns/rrdef.h
+streamtcp.lo streamtcp.o: $(srcdir)/testcode/streamtcp.c config.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
  $(srcdir)/util/net_help.h $(srcdir)/util/data/msgencode.h $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/dname.h
-perf.lo perf.o: $(srcdir)/testcode/perf.c config.h \
- $(srcdir)/util/log.h $(srcdir)/util/locks.h \
- $(srcdir)/util/net_help.h $(srcdir)/util/data/msgencode.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/dname.h $(srcdir)/ldns/sbuffer.h \
+ $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/wire2str.h \
+perf.lo perf.o: $(srcdir)/testcode/perf.c config.h $(srcdir)/util/log.h $(srcdir)/util/locks.h $(srcdir)/util/net_help.h \
+ $(srcdir)/util/data/msgencode.h $(srcdir)/util/data/msgreply.h $(srcdir)/util/storage/lruhash.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h \
+ $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/wire2str.h $(srcdir)/ldns/str2wire.h
 delayer.lo delayer.o: $(srcdir)/testcode/delayer.c config.h $(srcdir)/util/net_help.h $(srcdir)/util/log.h \
- $(srcdir)/util/config_file.h
-harvest.lo harvest.o: $(srcdir)/testcode/harvest.c config.h \
- $(srcdir)/libunbound/unbound.h
+ $(srcdir)/util/config_file.h $(srcdir)/ldns/sbuffer.h
 unbound-control.lo unbound-control.o: $(srcdir)/smallapp/unbound-control.c config.h \
- $(srcdir)/util/log.h \
- $(srcdir)/util/config_file.h \
- $(srcdir)/util/locks.h $(srcdir)/util/net_help.h
+ $(srcdir)/util/log.h $(srcdir)/util/config_file.h $(srcdir)/util/locks.h $(srcdir)/util/net_help.h
 unbound-anchor.lo unbound-anchor.o: $(srcdir)/smallapp/unbound-anchor.c config.h $(srcdir)/libunbound/unbound.h \
+ $(srcdir)/ldns/rrdef.h \
  
 petal.lo petal.o: $(srcdir)/testcode/petal.c config.h \
  
 pythonmod_utils.lo pythonmod_utils.o: $(srcdir)/pythonmod/pythonmod_utils.c config.h $(srcdir)/util/module.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/util/netevent.h \
- $(srcdir)/util/net_help.h $(srcdir)/services/cache/dns.h $(srcdir)/services/cache/rrset.h \
- $(srcdir)/util/storage/slabhash.h $(srcdir)/util/regional.h
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h \
+ $(srcdir)/util/netevent.h $(srcdir)/util/net_help.h $(srcdir)/services/cache/dns.h \
+ $(srcdir)/services/cache/rrset.h $(srcdir)/util/storage/slabhash.h $(srcdir)/util/regional.h
 win_svc.lo win_svc.o: $(srcdir)/winrc/win_svc.c config.h $(srcdir)/winrc/win_svc.h $(srcdir)/winrc/w_inst.h \
- $(srcdir)/daemon/daemon.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
- $(srcdir)/util/alloc.h \
- $(srcdir)/services/modstack.h $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/data/msgreply.h \
- $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h \
- $(srcdir)/util/data/msgparse.h \
- $(srcdir)/daemon/stats.h \
- $(srcdir)/util/timehist.h $(srcdir)/util/module.h $(srcdir)/daemon/remote.h \
+ $(srcdir)/daemon/daemon.h $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/alloc.h $(srcdir)/services/modstack.h \
+ $(srcdir)/daemon/worker.h $(srcdir)/util/netevent.h $(srcdir)/util/data/msgreply.h \
+ $(srcdir)/util/storage/lruhash.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/data/msgparse.h \
+ $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/rrdef.h $(srcdir)/daemon/stats.h $(srcdir)/util/timehist.h $(srcdir)/util/module.h \
+ $(srcdir)/daemon/remote.h \
  $(srcdir)/util/config_file.h $(srcdir)/util/winsock_event.h
 w_inst.lo w_inst.o: $(srcdir)/winrc/w_inst.c config.h $(srcdir)/winrc/w_inst.h $(srcdir)/winrc/win_svc.h
 unbound-service-install.lo unbound-service-install.o: $(srcdir)/winrc/unbound-service-install.c config.h \
  $(srcdir)/winrc/w_inst.h
 unbound-service-remove.lo unbound-service-remove.o: $(srcdir)/winrc/unbound-service-remove.c config.h \
  $(srcdir)/winrc/w_inst.h
-anchor-update.lo anchor-update.o: $(srcdir)/winrc/anchor-update.c config.h \
- $(srcdir)/libunbound/unbound.h
-ctime_r.lo ctime_r.o: $(srcdir)/compat/ctime_r.c config.h $(srcdir)/util/locks.h $(srcdir)/util/log.h \
+anchor-update.lo anchor-update.o: $(srcdir)/winrc/anchor-update.c config.h $(srcdir)/libunbound/unbound.h
+keyraw.lo keyraw.o: $(srcdir)/ldns/keyraw.c config.h $(srcdir)/ldns/keyraw.h \
+ $(srcdir)/ldns/rrdef.h \
+sbuffer.lo sbuffer.o: $(srcdir)/ldns/sbuffer.c config.h $(srcdir)/ldns/sbuffer.h
+wire2str.lo wire2str.o: $(srcdir)/ldns/wire2str.c config.h $(srcdir)/ldns/wire2str.h $(srcdir)/ldns/str2wire.h \
+ $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/pkthdr.h $(srcdir)/ldns/parseutil.h $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/keyraw.h \
  
+parse.lo parse.o: $(srcdir)/ldns/parse.c config.h $(srcdir)/ldns/parse.h $(srcdir)/ldns/parseutil.h \
+ $(srcdir)/ldns/sbuffer.h
+parseutil.lo parseutil.o: $(srcdir)/ldns/parseutil.c config.h $(srcdir)/ldns/parseutil.h
+rrdef.lo rrdef.o: $(srcdir)/ldns/rrdef.c config.h $(srcdir)/ldns/rrdef.h $(srcdir)/ldns/parseutil.h
+str2wire.lo str2wire.o: $(srcdir)/ldns/str2wire.c config.h $(srcdir)/ldns/str2wire.h $(srcdir)/ldns/rrdef.h \
+ $(srcdir)/ldns/wire2str.h $(srcdir)/ldns/sbuffer.h $(srcdir)/ldns/parse.h $(srcdir)/ldns/parseutil.h
+ctime_r.lo ctime_r.o: $(srcdir)/compat/ctime_r.c config.h $(srcdir)/util/locks.h $(srcdir)/util/log.h
 fake-rfc2553.lo fake-rfc2553.o: $(srcdir)/compat/fake-rfc2553.c $(srcdir)/compat/fake-rfc2553.h config.h
 gmtime_r.lo gmtime_r.o: $(srcdir)/compat/gmtime_r.c config.h
 inet_aton.lo inet_aton.o: $(srcdir)/compat/inet_aton.c config.h
@@ -1229,5 +1148,6 @@ malloc.lo malloc.o: $(srcdir)/compat/malloc.c config.h
 memcmp.lo memcmp.o: $(srcdir)/compat/memcmp.c config.h
 memmove.lo memmove.o: $(srcdir)/compat/memmove.c config.h
 snprintf.lo snprintf.o: $(srcdir)/compat/snprintf.c config.h
+strlcat.lo strlcat.o: $(srcdir)/compat/strlcat.c config.h
 strlcpy.lo strlcpy.o: $(srcdir)/compat/strlcpy.c config.h
 strptime.lo strptime.o: $(srcdir)/compat/strptime.c config.h
diff --git a/compat/strlcat.c b/compat/strlcat.c
new file mode 100644 (file)
index 0000000..0bea925
--- /dev/null
@@ -0,0 +1,73 @@
+/* compat/strlcat.c */
+
+/*-
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* OPENBSD ORIGINAL: lib/libc/string/strlcat.c */
+
+#include "config.h"
+#ifndef HAVE_STRLCAT
+
+#include <sys/types.h>
+#include <string.h>
+
+/*
+ * Appends src to string dst of size siz (unlike strncat, siz is the
+ * full size of dst, not space left).  At most siz-1 characters
+ * will be copied.  Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
+ * If retval >= siz, truncation occurred.
+ */
+size_t
+strlcat(char *dst, const char *src, size_t siz)
+{
+       char *d = dst;
+       const char *s = src;
+       size_t n = siz;
+       size_t dlen;
+
+       /* Find the end of dst and adjust bytes left but don't go past end */
+       while (n-- != 0 && *d != '\0')
+               d++;
+       dlen = d - dst;
+       n = siz - dlen;
+
+       if (n == 0)
+               return(dlen + strlen(s));
+       while (*s != '\0') {
+               if (n != 1) {
+                       *d++ = *s;
+                       n--;
+               }
+               s++;
+       }
+       *d = '\0';
+
+       return(dlen + (s - src));       /* count does not include NUL */
+}
+
+#endif /* !HAVE_STRLCAT */
index 46f38edf35d40225914334e5995522b6362c18c2..9ae30fe681c1c8b53ef88329691552e98789ed15 100644 (file)
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
+/* Define to 1 if you have the `endprotoent' function. */
+#undef HAVE_ENDPROTOENT
+
+/* Define to 1 if you have the `endservent' function. */
+#undef HAVE_ENDSERVENT
+
 /* Define to 1 if you have the `event_base_free' function. */
 #undef HAVE_EVENT_BASE_FREE
 
 /* Define to 1 if you have the `kill' function. */
 #undef HAVE_KILL
 
-/* Define to 1 if you have the `ldns_key_EVP_unload_gost' function. */
-#undef HAVE_LDNS_KEY_EVP_UNLOAD_GOST
-
-/* Define to 1 if you have the <ldns/ldns.h> header file. */
-#undef HAVE_LDNS_LDNS_H
-
-/* Define to 1 if you have the `ldns' library (-lldns). */
-#undef HAVE_LIBLDNS
-
 /* Define to 1 if you have the `localtime_r' function. */
 #undef HAVE_LOCALTIME_R
 
 /* Define to 1 if you have the <string.h> header file. */
 #undef HAVE_STRING_H
 
+/* Define to 1 if you have the `strlcat' function. */
+#undef HAVE_STRLCAT
+
 /* Define to 1 if you have the `strlcpy' function. */
 #undef HAVE_STRLCPY
 
 /* Shared data */
 #undef SHARE_DIR
 
+/* The size of `time_t', as computed by sizeof. */
+#undef SIZEOF_TIME_T
+
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
 #  define NDEBUG
 #endif
 
+/** Use small-ldns codebase */
+#define USE_SLDNS 1
+#ifdef HAVE_SSL
+#  define LDNS_BUILD_CONFIG_HAVE_SSL 1
+#endif
+
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
@@ -796,6 +805,12 @@ void *memmove(void *dest, const void *src, size_t n);
 #endif
 
 
+#ifndef HAVE_STRLCAT
+#define strlcat strlcat_unbound
+size_t strlcat(char *dst, const char *src, size_t siz);
+#endif
+
+
 #ifndef HAVE_STRLCPY
 #define strlcpy strlcpy_unbound
 size_t strlcpy(char *dst, const char *src, size_t siz);
index daf78e944ff8ae4681ded57bb3c3db2e71011a54..1f0868bc94d1cc6935604c6d1142c26b52f3b050 100755 (executable)
--- a/configure
+++ b/configure
@@ -632,7 +632,6 @@ ac_includes_default="\
 #endif"
 
 ac_subst_vars='LTLIBOBJS
-ldnsdir
 ALLTARGET
 SOURCEFILE
 SOURCEDETERMINE
@@ -827,7 +826,6 @@ enable_static_exe
 enable_lock_checks
 enable_allsymbols
 with_libunbound_only
-with_ldns
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1528,7 +1526,6 @@ Optional Packages:
                           outgoing port ranges.
   --with-libexpat=path    specify explicit path for libexpat.
   --with-libunbound-only  do not build daemon and tool programs
-  --with-ldns=PATH        specify prefix of path of ldns library to use
 
 Some influential environment variables:
   CC          C compiler command
@@ -2036,6 +2033,189 @@ $as_echo "$ac_res" >&6; }
 
 } # ac_fn_c_check_type
 
+# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES
+# --------------------------------------------
+# Tries to find the compile-time value of EXPR in a program that includes
+# INCLUDES, setting VAR accordingly. Returns whether the value could be
+# computed
+ac_fn_c_compute_int ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if test "$cross_compiling" = yes; then
+    # Depending upon the size, compute the lo and hi bounds.
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) >= 0)];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_lo=0 ac_mid=0
+  while :; do
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) <= $ac_mid)];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=$ac_mid; break
+else
+  as_fn_arith $ac_mid + 1 && ac_lo=$as_val
+                       if test $ac_lo -le $ac_mid; then
+                         ac_lo= ac_hi=
+                         break
+                       fi
+                       as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) < 0)];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=-1 ac_mid=-1
+  while :; do
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) >= $ac_mid)];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_lo=$ac_mid; break
+else
+  as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val
+                       if test $ac_mid -le $ac_hi; then
+                         ac_lo= ac_hi=
+                         break
+                       fi
+                       as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  ac_lo= ac_hi=
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+# Binary search between lo and hi bounds.
+while test "x$ac_lo" != "x$ac_hi"; do
+  as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+static int test_array [1 - 2 * !(($2) <= $ac_mid)];
+test_array [0] = 0;
+return test_array [0];
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_hi=$ac_mid
+else
+  as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+case $ac_lo in #((
+?*) eval "$3=\$ac_lo"; ac_retval=0 ;;
+'') ac_retval=1 ;;
+esac
+  else
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+static long int longval () { return $2; }
+static unsigned long int ulongval () { return $2; }
+#include <stdio.h>
+#include <stdlib.h>
+int
+main ()
+{
+
+  FILE *f = fopen ("conftest.val", "w");
+  if (! f)
+    return 1;
+  if (($2) < 0)
+    {
+      long int i = longval ();
+      if (i != ($2))
+       return 1;
+      fprintf (f, "%ld", i);
+    }
+  else
+    {
+      unsigned long int i = ulongval ();
+      if (i != ($2))
+       return 1;
+      fprintf (f, "%lu", i);
+    }
+  /* Do not output a trailing newline, as this causes \r\n confusion
+     on some platforms.  */
+  return ferror (f) || fclose (f) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  echo >>conftest.val; read $3 <conftest.val; ac_retval=0
+else
+  ac_retval=1
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+rm -f conftest.val
+
+  fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_compute_int
+
 # ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
 # ---------------------------------------------
 # Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
@@ -13885,6 +14065,53 @@ rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
 fi
 
 
+# The cast to long int works around a bug in the HP C Compiler
+# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
+# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
+# This bug is HP SR number 8606223364.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of time_t" >&5
+$as_echo_n "checking size of time_t... " >&6; }
+if ${ac_cv_sizeof_time_t+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (time_t))" "ac_cv_sizeof_time_t"        "
+$ac_includes_default
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+"; then :
+
+else
+  if test "$ac_cv_type_time_t" = yes; then
+     { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error 77 "cannot compute sizeof (time_t)
+See \`config.log' for more details" "$LINENO" 5; }
+   else
+     ac_cv_sizeof_time_t=0
+   fi
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_time_t" >&5
+$as_echo "$ac_cv_sizeof_time_t" >&6; }
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define SIZEOF_TIME_T $ac_cv_sizeof_time_t
+_ACEOF
+
+
+
 # add option to disable the evil rpath
 
 # Check whether --enable-rpath was given.
@@ -17738,7 +17965,7 @@ if test "$ac_res" != no; then :
 
 fi
 
-for ac_func in tzset sigprocmask fcntl getpwnam getrlimit setrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev socketpair glob initgroups strftime localtime_r setusercontext _beginthreadex
+for ac_func in tzset sigprocmask fcntl getpwnam getrlimit setrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev socketpair glob initgroups strftime localtime_r setusercontext _beginthreadex endservent endprotoent
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -17859,6 +18086,20 @@ esac
 fi
 
 
+ac_fn_c_check_func "$LINENO" "strlcat" "ac_cv_func_strlcat"
+if test "x$ac_cv_func_strlcat" = xyes; then :
+  $as_echo "#define HAVE_STRLCAT 1" >>confdefs.h
+
+else
+  case " $LIBOBJS " in
+  *" strlcat.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS strlcat.$ac_objext"
+ ;;
+esac
+
+fi
+
+
 ac_fn_c_check_func "$LINENO" "strlcpy" "ac_cv_func_strlcpy"
 if test "x$ac_cv_func_strlcpy" = xyes; then :
   $as_echo "#define HAVE_STRLCPY 1" >>confdefs.h
 
 
 
-# check this after all other compilation checks, since the linking of the lib
-# may break checks after this.
-
-# Check whether --with-ldns was given.
-if test "${with_ldns+set}" = set; then :
-  withval=$with_ldns;
-       if test "$withval" != "yes"; then
-               if test "$withval" != "/usr" -a "$withval" != ""; then
-                       CPPFLAGS="-I$withval/include $CPPFLAGS"
-                       LDFLAGS="-L$withval/lib $LDFLAGS"
-
-       if test "x$enable_rpath" = xyes; then
-               if echo "$withval/lib" | grep "^/" >/dev/null; then
-                       RUNTIME_PATH="$RUNTIME_PATH -R$withval/lib"
-               fi
-       fi
-
-               fi
-               ldnsdir="$withval"
-
-       fi
-
-fi
-
-
-# check if ldns is good enough
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ldns_rr_new in -lldns" >&5
-$as_echo_n "checking for ldns_rr_new in -lldns... " >&6; }
-if ${ac_cv_lib_ldns_ldns_rr_new+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lldns  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char ldns_rr_new ();
-int
-main ()
-{
-return ldns_rr_new ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_ldns_ldns_rr_new=yes
-else
-  ac_cv_lib_ldns_ldns_rr_new=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ldns_ldns_rr_new" >&5
-$as_echo "$ac_cv_lib_ldns_ldns_rr_new" >&6; }
-if test "x$ac_cv_lib_ldns_ldns_rr_new" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBLDNS 1
-_ACEOF
-
-  LIBS="-lldns $LIBS"
-
-else
-
-       as_fn_error $? "No ldns library found, install the ldns library into system lib dir or use --with-ldns=path to other location.  The --with-ldns can point to the make-dir of ldns.  Install the package ldns or download source http://www.nlnetlabs.nl/projects/ldns" "$LINENO" 5
-
-fi
-
-ac_fn_c_check_func "$LINENO" "ldns_buffer_copy" "ac_cv_func_ldns_buffer_copy"
-if test "x$ac_cv_func_ldns_buffer_copy" = xyes; then :
-
-fi
-
-if test $USE_NSS = "no"; then
-    ac_fn_c_check_func "$LINENO" "ldns_key_buf2rsa_raw" "ac_cv_func_ldns_key_buf2rsa_raw"
-if test "x$ac_cv_func_ldns_key_buf2rsa_raw" = xyes; then :
-
-fi
-
-else
-        ac_cv_func_ldns_key_buf2rsa_raw="yes"
-fi
-ac_fn_c_check_func "$LINENO" "ldns_get_random" "ac_cv_func_ldns_get_random"
-if test "x$ac_cv_func_ldns_get_random" = xyes; then :
-
-fi
-
-ac_fn_c_check_func "$LINENO" "ldns_b32_ntop_extended_hex" "ac_cv_func_ldns_b32_ntop_extended_hex"
-if test "x$ac_cv_func_ldns_b32_ntop_extended_hex" = xyes; then :
-
-fi
-
-if test x$use_gost = xyes -a x$USE_NSS = xno; then
-    ac_fn_c_check_func "$LINENO" "ldns_key_EVP_load_gost_id" "ac_cv_func_ldns_key_EVP_load_gost_id"
-if test "x$ac_cv_func_ldns_key_EVP_load_gost_id" = xyes; then :
-
-fi
-
-    for ac_func in ldns_key_EVP_unload_gost
-do :
-  ac_fn_c_check_func "$LINENO" "ldns_key_EVP_unload_gost" "ac_cv_func_ldns_key_EVP_unload_gost"
-if test "x$ac_cv_func_ldns_key_EVP_unload_gost" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_LDNS_KEY_EVP_UNLOAD_GOST 1
-_ACEOF
-
-fi
-done
-
-else
-        ac_cv_func_ldns_key_EVP_load_gost_id="yes"
-fi
-if test x$use_ecdsa = xyes; then
-    ac_fn_c_check_decl "$LINENO" "LDNS_ECDSAP384SHA384" "ac_cv_have_decl_LDNS_ECDSAP384SHA384" "
-$ac_includes_default
-#ifdef HAVE_SYS_SOCKET_H
-#  include <sys/socket.h>
-#endif
-#ifdef HAVE_WS2TCPIP_H
-#  include <ws2tcpip.h>
-#endif
-#include <ldns/ldns.h>
-
-"
-if test "x$ac_cv_have_decl_LDNS_ECDSAP384SHA384" = xyes; then :
-
-fi
-
-else
-    ac_cv_have_decl_LDNS_ECDSAP384SHA384="yes"
-fi
-for ac_header in ldns/ldns.h
-do :
-  ac_fn_c_check_header_compile "$LINENO" "ldns/ldns.h" "ac_cv_header_ldns_ldns_h" "$ac_includes_default
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>
-#endif
-
-#ifdef HAVE_WS2TCPIP_H
-#include <ws2tcpip.h>
-#endif
-
-"
-if test "x$ac_cv_header_ldns_ldns_h" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_LDNS_LDNS_H 1
-_ACEOF
-
-else
-
-       as_fn_error $? "No ldns include file found, install the ldns library development files.  Install package ldns-dev or ldns-devel or download source http://www.nlnetlabs.nl/projects/ldns" "$LINENO" 5
-
-fi
-
-done
-
-if test $ac_cv_func_ldns_buffer_copy = yes \
-    -a $ac_cv_func_ldns_key_buf2rsa_raw = yes \
-    -a $ac_cv_func_ldns_get_random = yes \
-    -a $ac_cv_header_ldns_ldns_h = yes \
-    -a $ac_cv_func_ldns_b32_ntop_extended_hex = yes \
-    -a $ac_cv_func_ldns_key_EVP_load_gost_id = yes \
-    -a $ac_cv_have_decl_LDNS_ECDSAP384SHA384 = yes; then
-        :
-else
-    as_fn_error $? "ldns library is not recent, update the ldns library, install it into system lib dir or use --with-ldns=path to other location.  The --with-ldns can point to the make-dir of ldns.  Package libldns or download source http://www.nlnetlabs.nl/projects/ldns" "$LINENO" 5
-fi
-
 
   { $as_echo "$as_me:${as_lineno-$LINENO}: Stripping extension flags..." >&5
 $as_echo "$as_me: Stripping extension flags..." >&6;}
index b0ee08c9cc5d3576793fda9087cc3cf18e17a339..bbbe77d221b6c5c499fab62f60af7caeed5a3ca0 100644 (file)
@@ -296,6 +296,20 @@ ACX_TYPE_IN_ADDR_T
 ACX_TYPE_IN_PORT_T
 ACX_CHECK_MEMCMP_SIGNED
 
+AC_CHECK_SIZEOF(time_t,,[
+AC_INCLUDES_DEFAULT
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+])
+
 # add option to disable the evil rpath
 ACX_ARG_RPATH
 AC_SUBST(RUNTIME_PATH)
@@ -928,7 +942,7 @@ AC_INCLUDES_DEFAULT
 #endif
 ])
 AC_SEARCH_LIBS([setusercontext], [util])
-AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev socketpair glob initgroups strftime localtime_r setusercontext _beginthreadex])
+AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev socketpair glob initgroups strftime localtime_r setusercontext _beginthreadex endservent endprotoent])
 AC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])])
 AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])])
 
@@ -940,6 +954,7 @@ AC_REPLACE_FUNCS(inet_aton)
 AC_REPLACE_FUNCS(inet_pton)
 AC_REPLACE_FUNCS(inet_ntop)
 AC_REPLACE_FUNCS(snprintf)
+AC_REPLACE_FUNCS(strlcat)
 AC_REPLACE_FUNCS(strlcpy)
 AC_REPLACE_FUNCS(memmove)
 AC_REPLACE_FUNCS(gmtime_r)
@@ -1025,92 +1040,6 @@ AC_ARG_WITH(libunbound-only, AC_HELP_STRING([--with-libunbound-only],
 ])
 AC_SUBST(ALLTARGET)
 
-# check this after all other compilation checks, since the linking of the lib
-# may break checks after this.
-AC_ARG_WITH(ldns, AC_HELP_STRING([--with-ldns=PATH], 
-       [specify prefix of path of ldns library to use]), 
-       [
-       if test "$withval" != "yes"; then
-               if test "$withval" != "/usr" -a "$withval" != ""; then
-                       CPPFLAGS="-I$withval/include $CPPFLAGS"
-                       LDFLAGS="-L$withval/lib $LDFLAGS"
-                       ACX_RUNTIME_PATH_ADD([$withval/lib])
-               fi
-               ldnsdir="$withval"
-               AC_SUBST(ldnsdir)
-       fi
-])
-
-# check if ldns is good enough
-AC_CHECK_LIB(ldns, ldns_rr_new,,[
-       AC_MSG_ERROR([No ldns library found, install the ldns library into system lib dir or use --with-ldns=path to other location.  The --with-ldns can point to the make-dir of ldns.  Install the package ldns or download source http://www.nlnetlabs.nl/projects/ldns])
-])
-AC_CHECK_FUNC(ldns_buffer_copy)
-if test $USE_NSS = "no"; then
-    AC_CHECK_FUNC(ldns_key_buf2rsa_raw)
-else
-    dnl ignore test
-    ac_cv_func_ldns_key_buf2rsa_raw="yes"
-fi
-AC_CHECK_FUNC(ldns_get_random)
-AC_CHECK_FUNC(ldns_b32_ntop_extended_hex)
-if test x$use_gost = xyes -a x$USE_NSS = xno; then
-    AC_CHECK_FUNC(ldns_key_EVP_load_gost_id)
-    AC_CHECK_FUNCS([ldns_key_EVP_unload_gost])
-else
-    dnl ignore test
-    ac_cv_func_ldns_key_EVP_load_gost_id="yes"
-fi
-if test x$use_ecdsa = xyes; then
-    AC_CHECK_DECL([LDNS_ECDSAP384SHA384], [], [], [
-AC_INCLUDES_DEFAULT
-#ifdef HAVE_SYS_SOCKET_H
-#  include <sys/socket.h>
-#endif
-#ifdef HAVE_WS2TCPIP_H
-#  include <ws2tcpip.h>
-#endif
-#include <ldns/ldns.h>
-    ])
-else
-    ac_cv_have_decl_LDNS_ECDSAP384SHA384="yes"
-fi
-AC_CHECK_HEADERS([ldns/ldns.h],,[
-       AC_MSG_ERROR([No ldns include file found, install the ldns library development files.  Install package ldns-dev or ldns-devel or download source http://www.nlnetlabs.nl/projects/ldns])
-       ], [AC_INCLUDES_DEFAULT
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>
-#endif
-
-#ifdef HAVE_WS2TCPIP_H
-#include <ws2tcpip.h>
-#endif
-])
-if test $ac_cv_func_ldns_buffer_copy = yes \
-    -a $ac_cv_func_ldns_key_buf2rsa_raw = yes \
-    -a $ac_cv_func_ldns_get_random = yes \
-    -a $ac_cv_header_ldns_ldns_h = yes \
-    -a $ac_cv_func_ldns_b32_ntop_extended_hex = yes \
-    -a $ac_cv_func_ldns_key_EVP_load_gost_id = yes \
-    -a $ac_cv_have_decl_LDNS_ECDSAP384SHA384 = yes; then
-    dnl ldns was found
-    :
-else
-    AC_MSG_ERROR([ldns library is not recent, update the ldns library, install it into system lib dir or use --with-ldns=path to other location.  The --with-ldns can point to the make-dir of ldns.  Package libldns or download source http://www.nlnetlabs.nl/projects/ldns])
-fi
-
 ACX_STRIP_EXT_FLAGS
 LDFLAGS="$LATE_LDFLAGS $LDFLAGS"
 
@@ -1126,6 +1055,12 @@ dnl includes
 #  define NDEBUG
 #endif
 
+/** Use small-ldns codebase */
+#define USE_SLDNS 1
+#ifdef HAVE_SSL
+#  define LDNS_BUILD_CONFIG_HAVE_SSL 1
+#endif
+
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
@@ -1180,6 +1115,7 @@ AHX_CONFIG_INET_PTON(unbound)
 AHX_CONFIG_INET_NTOP(unbound)
 AHX_CONFIG_INET_ATON(unbound)
 AHX_CONFIG_MEMMOVE(unbound)
+AHX_CONFIG_STRLCAT(unbound)
 AHX_CONFIG_STRLCPY(unbound)
 AHX_CONFIG_GMTIME_R(unbound)
 AHX_CONFIG_W32_SLEEP
index df6a40188bea325680db418586ac468c13c58d69..622371a19e772f19822d2ec1cd6133b5c6986676 100644 (file)
@@ -40,7 +40,7 @@
  * to text format.
  */
 #include "config.h"
-#include <ldns/ldns.h>
+#include <openssl/ssl.h>
 #include "daemon/cachedump.h"
 #include "daemon/remote.h"
 #include "daemon/worker.h"
 #include "iterator/iter_utils.h"
 #include "iterator/iter_fwd.h"
 #include "iterator/iter_hints.h"
-
-/** convert to ldns rr */
-static ldns_rr*
-to_rr(struct ub_packed_rrset_key* k, struct packed_rrset_data* d, 
-       time_t now, size_t i, uint16_t type)
-{
-       ldns_rr* rr = ldns_rr_new();
-       ldns_rdf* rdf;
-       ldns_status status;
-       size_t pos;
-       log_assert(i < d->count + d->rrsig_count);
-       if(!rr) {
-               return NULL;
-       }
-       ldns_rr_set_type(rr, type);
-       ldns_rr_set_class(rr, ntohs(k->rk.rrset_class));
-       if(d->rr_ttl[i] < now)
-               ldns_rr_set_ttl(rr, 0);
-       else    ldns_rr_set_ttl(rr, d->rr_ttl[i] - now);
-       pos = 0;
-       status = ldns_wire2dname(&rdf, k->rk.dname, k->rk.dname_len, &pos);
-       if(status != LDNS_STATUS_OK) {
-               /* we drop detailed error in status */
-               ldns_rr_free(rr);
-               return NULL;
-       }
-       ldns_rr_set_owner(rr, rdf);
-       pos = 0;
-       status = ldns_wire2rdf(rr, d->rr_data[i], d->rr_len[i], &pos);
-       if(status != LDNS_STATUS_OK) {
-               /* we drop detailed error in status */
-               ldns_rr_free(rr);
-               return NULL;
-       }
-       return rr;
-}
+#include "ldns/sbuffer.h"
+#include "ldns/wire2str.h"
+#include "ldns/str2wire.h"
 
 /** dump one rrset zonefile line */
 static int
-dump_rrset_line(SSL* ssl, struct ub_packed_rrset_key* k,
-        struct packed_rrset_data* d, time_t now, size_t i, uint16_t type)
+dump_rrset_line(SSL* ssl, struct ub_packed_rrset_key* k, time_t now, size_t i)
 {
-       char* s;
-       ldns_rr* rr = to_rr(k, d, now, i, type);
-       if(!rr) {
-               return ssl_printf(ssl, "BADRR\n");
-       }
-       s = ldns_rr2str(rr);
-       ldns_rr_free(rr);
-       if(!s) {
+       char s[65535];
+       if(!packed_rr_to_string(k, i, now, s, sizeof(s))) {
                return ssl_printf(ssl, "BADRR\n");
        }
-       if(!ssl_printf(ssl, "%s", s)) {
-               free(s);
-               return 0;
-       }
-       free(s);
-       return 1;
+       return ssl_printf(ssl, "%s\n", s);
 }
 
 /** dump rrset key and data info */
@@ -134,16 +89,10 @@ dump_rrset(SSL* ssl, struct ub_packed_rrset_key* k,
                (int)d->trust, (int)d->security
                )) 
                return 0;
-       for(i=0; i<d->count; i++) {
-               if(!dump_rrset_line(ssl, k, d, now, i, ntohs(k->rk.type)))
+       for(i=0; i<d->count + d->rrsig_count; i++) {
+               if(!dump_rrset_line(ssl, k, now, i))
                        return 0;
        }
-       for(i=0; i<d->rrsig_count; i++) {
-               if(!dump_rrset_line(ssl, k, d, now, i+d->count, 
-                       LDNS_RR_TYPE_RRSIG))
-                       return 0;
-       }
-       
        return 1;
 }
 
@@ -189,20 +138,10 @@ dump_rrset_cache(SSL* ssl, struct worker* worker)
 static int
 dump_msg_ref(SSL* ssl, struct ub_packed_rrset_key* k)
 {
-       ldns_rdf* rdf;
-       ldns_status status;
-       size_t pos;
        char* nm, *tp, *cl;
-
-       pos = 0;
-       status = ldns_wire2dname(&rdf, k->rk.dname, k->rk.dname_len, &pos);
-       if(status != LDNS_STATUS_OK) {
-               return ssl_printf(ssl, "BADREF\n");
-       }
-       nm = ldns_rdf2str(rdf);
-       ldns_rdf_deep_free(rdf);
-       tp = ldns_rr_type2str(ntohs(k->rk.type));
-       cl = ldns_rr_class2str(ntohs(k->rk.rrset_class));
+       nm = ldns_wire2str_dname(k->rk.dname, k->rk.dname_len);
+       tp = ldns_wire2str_type(ntohs(k->rk.type));
+       cl = ldns_wire2str_class(ntohs(k->rk.rrset_class));
        if(!nm || !cl || !tp) {
                free(nm);
                free(tp);
@@ -229,21 +168,12 @@ dump_msg(SSL* ssl, struct query_info* k, struct reply_info* d,
 {
        size_t i;
        char* nm, *tp, *cl;
-       ldns_rdf* rdf;
-       ldns_status status;
-       size_t pos;
        if(!k || !d) return 1;
        if(d->ttl < now) return 1; /* expired */
        
-       pos = 0;
-       status = ldns_wire2dname(&rdf, k->qname, k->qname_len, &pos);
-       if(status != LDNS_STATUS_OK) {
-               return 1; /* skip this entry */
-       }
-       nm = ldns_rdf2str(rdf);
-       ldns_rdf_deep_free(rdf);
-       tp = ldns_rr_type2str(k->qtype);
-       cl = ldns_rr_class2str(k->qclass);
+       nm = ldns_wire2str_dname(k->qname, k->qname_len);
+       tp = ldns_wire2str_type(k->qtype);
+       cl = ldns_wire2str_class(k->qclass);
        if(!nm || !tp || !cl) {
                free(nm);
                free(tp);
@@ -389,8 +319,9 @@ load_rr(SSL* ssl, ldns_buffer* buf, struct regional* region,
        struct ub_packed_rrset_key* rk, struct packed_rrset_data* d,
        unsigned int i, int is_rrsig, int* go_on, time_t now)
 {
-       ldns_rr* rr;
-       ldns_status status;
+       uint8_t rr[LDNS_RR_BUF_SIZE];
+       size_t rr_len = sizeof(rr), dname_len = 0;
+       int status;
 
        /* read the line */
        if(!ssl_read_buf(ssl, buf))
@@ -399,66 +330,43 @@ load_rr(SSL* ssl, ldns_buffer* buf, struct regional* region,
                *go_on = 0;
                return 1;
        }
-       status = ldns_rr_new_frm_str(&rr, (char*)ldns_buffer_begin(buf),
-               LDNS_DEFAULT_TTL, NULL, NULL);
-       if(status != LDNS_STATUS_OK) {
+       status = ldns_str2wire_rr_buf((char*)ldns_buffer_begin(buf), rr,
+               &rr_len, &dname_len, 3600, NULL, 0, NULL, 0);
+       if(status != 0) {
                log_warn("error cannot parse rr: %s: %s",
-                       ldns_get_errorstr_by_id(status),
+                       ldns_get_errorstr_parse(status),
                        (char*)ldns_buffer_begin(buf));
                return 0;
        }
-       if(is_rrsig && ldns_rr_get_type(rr) != LDNS_RR_TYPE_RRSIG) {
+       if(is_rrsig && ldns_wirerr_get_type(rr, rr_len, dname_len)
+               != LDNS_RR_TYPE_RRSIG) {
                log_warn("error expected rrsig but got %s",
                        (char*)ldns_buffer_begin(buf));
                return 0;
        }
 
        /* convert ldns rr into packed_rr */
-       d->rr_ttl[i] = ldns_rr_ttl(rr) + now;
+       d->rr_ttl[i] = (time_t)ldns_wirerr_get_ttl(rr, rr_len, dname_len) + now;
        ldns_buffer_clear(buf);
-       ldns_buffer_skip(buf, 2);
-       status = ldns_rr_rdata2buffer_wire(buf, rr);
-       if(status != LDNS_STATUS_OK) {
-               log_warn("error cannot rr2wire: %s",
-                       ldns_get_errorstr_by_id(status));
-               ldns_rr_free(rr);
-               return 0;
-       }
-       ldns_buffer_flip(buf);
-       ldns_buffer_write_u16_at(buf, 0, ldns_buffer_limit(buf) - 2);
-
-       d->rr_len[i] = ldns_buffer_limit(buf);
+       d->rr_len[i] = ldns_wirerr_get_rdatalen(rr, rr_len, dname_len)+2;
        d->rr_data[i] = (uint8_t*)regional_alloc_init(region, 
-               ldns_buffer_begin(buf), ldns_buffer_limit(buf));
+               ldns_wirerr_get_rdatawl(rr, rr_len, dname_len), d->rr_len[i]);
        if(!d->rr_data[i]) {
-               ldns_rr_free(rr);
                log_warn("error out of memory");
                return 0;
        }
 
        /* if first entry, fill the key structure */
        if(i==0) {
-               rk->rk.type = htons(ldns_rr_get_type(rr));
-               rk->rk.rrset_class = htons(ldns_rr_get_class(rr));
-               ldns_buffer_clear(buf);
-               status = ldns_dname2buffer_wire(buf, ldns_rr_owner(rr));
-               if(status != LDNS_STATUS_OK) {
-                       log_warn("error cannot dname2buffer: %s",
-                               ldns_get_errorstr_by_id(status));
-                       ldns_rr_free(rr);
-                       return 0;
-               }
-               ldns_buffer_flip(buf);
-               rk->rk.dname_len = ldns_buffer_limit(buf);
-               rk->rk.dname = regional_alloc_init(region, 
-                       ldns_buffer_begin(buf), ldns_buffer_limit(buf));
+               rk->rk.type = htons(ldns_wirerr_get_type(rr, rr_len, dname_len));
+               rk->rk.rrset_class = htons(ldns_wirerr_get_class(rr, rr_len, dname_len));
+               rk->rk.dname_len = dname_len;
+               rk->rk.dname = regional_alloc_init(region, rr, dname_len);
                if(!rk->rk.dname) {
                        log_warn("error out of memory");
-                       ldns_rr_free(rr);
                        return 0;
                }
        }
-       ldns_rr_free(rr);
 
        return 1;
 }
@@ -618,13 +526,13 @@ load_rrset_cache(SSL* ssl, struct worker* worker)
 
 /** read qinfo from next three words */
 static char*
-load_qinfo(char* str, struct query_info* qinfo, ldns_buffer* buf, 
-       struct regional* region)
+load_qinfo(char* str, struct query_info* qinfo, struct regional* region)
 {
        /* s is part of the buf */
        char* s = str;
-       ldns_rr* rr;
-       ldns_status status;
+       uint8_t rr[LDNS_RR_BUF_SIZE];
+       size_t rr_len = sizeof(rr), dname_len = 0;
+       int status;
 
        /* skip three words */
        s = strchr(str, ' ');
@@ -638,26 +546,17 @@ load_qinfo(char* str, struct query_info* qinfo, ldns_buffer* buf,
        s++;
 
        /* parse them */
-       status = ldns_rr_new_question_frm_str(&rr, str, NULL, NULL);
-       if(status != LDNS_STATUS_OK) {
+       status = ldns_str2wire_rr_question_buf(str, rr, &rr_len, &dname_len,
+               NULL, 0, NULL, 0);
+       if(status != 0) {
                log_warn("error cannot parse: %s %s",
-                       ldns_get_errorstr_by_id(status), str);
-               return NULL;
-       }
-       qinfo->qtype = ldns_rr_get_type(rr);
-       qinfo->qclass = ldns_rr_get_class(rr);
-       ldns_buffer_clear(buf);
-       status = ldns_dname2buffer_wire(buf, ldns_rr_owner(rr));
-       ldns_rr_free(rr);
-       if(status != LDNS_STATUS_OK) {
-               log_warn("error cannot dname2wire: %s", 
-                       ldns_get_errorstr_by_id(status));
+                       ldns_get_errorstr_parse(status), str);
                return NULL;
        }
-       ldns_buffer_flip(buf);
-       qinfo->qname_len = ldns_buffer_limit(buf);
-       qinfo->qname = (uint8_t*)regional_alloc_init(region, 
-               ldns_buffer_begin(buf), ldns_buffer_limit(buf));
+       qinfo->qtype = ldns_wirerr_get_type(rr, rr_len, dname_len);
+       qinfo->qclass = ldns_wirerr_get_class(rr, rr_len, dname_len);
+       qinfo->qname_len = dname_len;
+       qinfo->qname = (uint8_t*)regional_alloc_init(region, rr, dname_len);
        if(!qinfo->qname) {
                log_warn("error out of memory");
                return NULL;
@@ -685,7 +584,7 @@ load_ref(SSL* ssl, ldns_buffer* buf, struct worker* worker,
                return 1;
        }
 
-       s = load_qinfo(s, &qinfo, buf, region);
+       s = load_qinfo(s, &qinfo, region);
        if(!s) {
                return 0;
        }
@@ -731,7 +630,7 @@ load_msg(SSL* ssl, ldns_buffer* buf, struct worker* worker)
                return 0;
        }
        s += 4;
-       s = load_qinfo(s, &qinf, buf, region);
+       s = load_qinfo(s, &qinf, region);
        if(!s) {
                return 0;
        }
index b91683feb916268261b0b9f20b98775542c84902..658e65dec3767f2f3bc46c3b7b83a32f51bbcfd2 100644 (file)
@@ -61,7 +61,6 @@
 #include "nss.h"
 #endif
 
-#include <ldns/ldns.h>
 #include "daemon/daemon.h"
 #include "daemon/worker.h"
 #include "daemon/remote.h"
@@ -80,6 +79,7 @@
 #include "util/random.h"
 #include "util/tube.h"
 #include "util/net_help.h"
+#include "ldns/keyraw.h"
 #include <signal.h>
 
 /** How many quit requests happened. */
index 615050225c5f83547c214b9c8b308825fa05a68e..3b76c0e298611a85014a9cf6bb6a6f4a2a94b33a 100644 (file)
@@ -47,7 +47,6 @@
 #include <openssl/err.h>
 #endif
 #include <ctype.h>
-#include <ldns/ldns.h>
 #include "daemon/remote.h"
 #include "daemon/worker.h"
 #include "daemon/daemon.h"
 #include "iterator/iter_delegpt.h"
 #include "services/outbound_list.h"
 #include "services/outside_network.h"
+#include "ldns/str2wire.h"
+#include "ldns/parseutil.h"
+#include "ldns/wire2str.h"
+#include "ldns/sbuffer.h"
 
 #ifdef HAVE_SYS_TYPES_H
 #  include <sys/types.h>
@@ -912,17 +915,20 @@ do_stats(SSL* ssl, struct daemon_remote* rc, int reset)
 static int
 parse_arg_name(SSL* ssl, char* str, uint8_t** res, size_t* len, int* labs)
 {
-       ldns_rdf* rdf;
+       uint8_t nm[LDNS_MAX_DOMAINLEN+1];
+       size_t nmlen = sizeof(nm);
+       int status;
        *res = NULL;
        *len = 0;
        *labs = 0;
-       rdf = ldns_dname_new_frm_str(str);
-       if(!rdf) {
-               ssl_printf(ssl, "error cannot parse name %s\n", str);
+       status = ldns_str2wire_dname_buf(str, nm, &nmlen);
+       if(status != 0) {
+               ssl_printf(ssl, "error cannot parse name %s at %d: %s\n", str,
+                       LDNS_WIREPARSE_OFFSET(status),
+                       ldns_get_errorstr_parse(status));
                return 0;
        }
-       *res = memdup(ldns_rdf_data(rdf), ldns_rdf_size(rdf));
-       ldns_rdf_deep_free(rdf);
+       *res = memdup(nm, nmlen);
        if(!*res) {
                ssl_printf(ssl, "error out of memory\n");
                return 0;
@@ -1022,8 +1028,7 @@ do_zone_remove(SSL* ssl, struct worker* worker, char* arg)
 static void
 do_data_add(SSL* ssl, struct worker* worker, char* arg)
 {
-       if(!local_zones_add_RR(worker->daemon->local_zones, arg,
-               worker->env.scratch_buffer)) {
+       if(!local_zones_add_RR(worker->daemon->local_zones, arg)) {
                ssl_printf(ssl,"error in syntax or out of memory, %s\n", arg);
                return;
        }
@@ -1388,9 +1393,9 @@ ssl_print_name_dp(SSL* ssl, char* str, uint8_t* nm, uint16_t dclass,
        struct delegpt_addr* a;
        int f = 0;
        if(str) { /* print header for forward, stub */
-               char* c = ldns_rr_class2str(dclass);
+               char* c = ldns_wire2str_class(dclass);
                dname_str(nm, buf);
-               if(!ssl_printf(ssl, "%s %s %s: ", buf, c, str)) {
+               if(!ssl_printf(ssl, "%s %s %s: ", buf, (c?c:"CLASS??"), str)) {
                        free(c);
                        return 0;
                }
@@ -1780,10 +1785,11 @@ get_mesh_status(struct mesh_area* mesh, struct mesh_state* m,
                if(m->sub_set.count == 0)
                        snprintf(buf, len, " (empty_list)");
                RBTREE_FOR(sub, struct mesh_state_ref*, &m->sub_set) {
-                       char* t = ldns_rr_type2str(sub->s->s.qinfo.qtype);
-                       char* c = ldns_rr_class2str(sub->s->s.qinfo.qclass);
+                       char* t = ldns_wire2str_type(sub->s->s.qinfo.qtype);
+                       char* c = ldns_wire2str_class(sub->s->s.qinfo.qclass);
                        dname_str(sub->s->s.qinfo.qname, nm);
-                       snprintf(buf, len, " %s %s %s", t, c, nm);
+                       snprintf(buf, len, " %s %s %s", (t?t:"TYPE??"),
+                               (c?c:"CLASS??"), nm);
                        l = strlen(buf);
                        buf += l; len -= l;
                        free(t);
@@ -1812,13 +1818,14 @@ do_dump_requestlist(SSL* ssl, struct worker* worker)
        mesh = worker->env.mesh;
        if(!mesh) return;
        RBTREE_FOR(m, struct mesh_state*, &mesh->all) {
-               char* t = ldns_rr_type2str(m->s.qinfo.qtype);
-               char* c = ldns_rr_class2str(m->s.qinfo.qclass);
+               char* t = ldns_wire2str_type(m->s.qinfo.qtype);
+               char* c = ldns_wire2str_class(m->s.qinfo.qclass);
                dname_str(m->s.qinfo.qname, buf);
                get_mesh_age(m, timebuf, sizeof(timebuf), &worker->env);
                get_mesh_status(mesh, m, statbuf, sizeof(statbuf));
                if(!ssl_printf(ssl, "%3d %4s %2s %s %s %s\n", 
-                       num, t, c, buf, timebuf, statbuf)) {
+                       num, (t?t:"TYPE??"), (c?c:"CLASS??"), buf, timebuf,
+                       statbuf)) {
                        free(t);
                        free(c);
                        return;
@@ -1978,17 +1985,25 @@ do_list_local_data(SSL* ssl, struct worker* worker)
        struct local_zone* z;
        struct local_data* d;
        struct local_rrset* p;
+       char* s = (char*)ldns_buffer_begin(worker->env.scratch_buffer);
+       size_t slen = ldns_buffer_capacity(worker->env.scratch_buffer);
        lock_quick_lock(&zones->lock);
        RBTREE_FOR(z, struct local_zone*, &zones->ztree) {
                lock_rw_rdlock(&z->lock);
                RBTREE_FOR(d, struct local_data*, &z->data) {
                        for(p = d->rrsets; p; p = p->next) {
-                               ldns_rr_list* rr = packed_rrset_to_rr_list(
-                                       p->rrset, worker->env.scratch_buffer);
-                               char* str = ldns_rr_list2str(rr);
-                               (void)ssl_printf(ssl, "%s", str);
-                               free(str);
-                               ldns_rr_list_free(rr);
+                               struct packed_rrset_data* d =
+                                       (struct packed_rrset_data*)p->rrset->entry.data;
+                               size_t i;
+                               for(i=0; i<d->count + d->rrsig_count; i++) {
+                                       if(!packed_rr_to_string(p->rrset, i,
+                                               0, s, slen)) {
+                                               if(!ssl_printf(ssl, "BADRR\n"))
+                                                       return;
+                                       }
+                                       if(!ssl_printf(ssl, "%s\n", s))
+                                               return;
+                               }
                        }
                }
                lock_rw_unlock(&z->lock);
index 9a1a7d2617edd84a43d5688da94895896ff4bda2..707273fe479a0d9779f22427d028e30175759c37 100644 (file)
@@ -40,7 +40,6 @@
  * numbers. These 'statistics' may be of interest to the operator.
  */
 #include "config.h"
-#include <ldns/wire2host.h>
 #include "daemon/stats.h"
 #include "daemon/worker.h"
 #include "daemon/daemon.h"
@@ -51,6 +50,7 @@
 #include "util/timehist.h"
 #include "util/net_help.h"
 #include "validator/validator.h"
+#include "ldns/sbuffer.h"
 
 /** add timers and the values do not overflow or become negative */
 static void
index c0fc1cc15443869a973c291754585f12cc4baa0c..b8513afdb0e023fe9242260ca3b16956213377d1 100644 (file)
 #ifndef DAEMON_STATS_H
 #define DAEMON_STATS_H
 #include "util/timehist.h"
-#include <ldns/buffer.h>
 struct worker;
 struct config_file;
 struct comm_point;
 struct comm_reply;
 struct edns_data;
+struct ldns_buffer;
 
 /** number of qtype that is stored for in array */
 #define STATS_QTYPE_NUM 256
@@ -230,6 +230,6 @@ void server_stats_insquery(struct server_stats* stats, struct comm_point* c,
  * @param stats: the stats
  * @param buf: buffer with rcode. If buffer is length0: not counted.
  */
-void server_stats_insrcode(struct server_stats* stats, ldns_buffer* buf);
+void server_stats_insrcode(struct server_stats* stats, struct ldns_buffer* buf);
 
 #endif /* DAEMON_STATS_H */
index 28ea17355bf1073b84e28a55a7fc8b769c5f64cb..8de3f6b980d82e52fb1004a4d3b1da4527afe43a 100644 (file)
@@ -162,8 +162,8 @@ static void usage()
 #endif
        printf("Version %s\n", PACKAGE_VERSION);
        get_event_sys(&evnm, &evsys, &evmethod);
-       printf("linked libs: %s %s (it uses %s), ldns %s, %s\n", 
-               evnm, evsys, evmethod, ldns_version(), 
+       printf("linked libs: %s %s (it uses %s), %s\n", 
+               evnm, evsys, evmethod,
 #ifdef HAVE_SSL
                SSLeay_version(SSLEAY_VERSION)
 #elif defined(HAVE_NSS)
index c7620962c98c7cdc5c9ce3818934a0bfce35b99c..a6d3c70632f2c46ce4e153da304b01f386ce0c93 100644 (file)
@@ -40,7 +40,6 @@
  * pending requests.
  */
 #include "config.h"
-#include <ldns/wire2host.h>
 #include "util/log.h"
 #include "util/net_help.h"
 #include "util/random.h"
@@ -70,6 +69,7 @@
 #include "iterator/iter_hints.h"
 #include "validator/autotrust.h"
 #include "validator/val_anchor.h"
+#include "ldns/sbuffer.h"
 
 #ifdef HAVE_SYS_TYPES_H
 #  include <sys/types.h>
index 9e071d1b4590d9063f3a194b2c37f3e96524dd45..72a0af6d69fb02abaa536173c7160b8e51d66c7f 100644 (file)
@@ -3,6 +3,8 @@
          interface port 53 can be used at the same time, and one of the
          daemons is unbound.
        - iana portlist update.
+       - separate ldns into core ldns inside ldns/ subdirectory.  No more
+         --with-ldns is needed and unbound does not rely on libldns.
 
 22 Oct 2013: Wouter
        - Patch from Neel Goyal: Add an API call to set an event base on an
index c204ddfec745e1f01fb173168f06ec04915c0a6a..7a5aea4935a2736f3a94658b7b9ad95cf17beda4 100644 (file)
@@ -47,6 +47,8 @@
 #include "util/data/packed_rrset.h"
 #include "util/data/msgreply.h"
 #include "util/net_help.h"
+#include "ldns/rrdef.h"
+#include "ldns/sbuffer.h"
 
 struct delegpt* 
 delegpt_create(struct regional* region)
index b84e5eff60d0944a09690e5ef43fcf01f14ec6c9..75e7a9f12c2b8cb1bab24573b130c525edbdf5ad 100644 (file)
  * Keep track of forward zones and config settings.
  */
 #include "config.h"
-#include <ldns/rdata.h>
-#include <ldns/dname.h>
-#include <ldns/rr.h>
 #include "iterator/iter_fwd.h"
 #include "iterator/iter_delegpt.h"
 #include "util/log.h"
 #include "util/config_file.h"
 #include "util/net_help.h"
 #include "util/data/dname.h"
+#include "ldns/rrdef.h"
+#include "ldns/str2wire.h"
 
 int
 fwd_cmp(const void* k1, const void* k2)
@@ -180,22 +179,23 @@ static struct delegpt*
 read_fwds_name(struct config_stub* s)
 {
        struct delegpt* dp;
-       ldns_rdf* rdf;
+       uint8_t* dname;
+       size_t dname_len;
        if(!s->name) {
                log_err("forward zone without a name (use name \".\" to forward everything)");
                return NULL;
        }
-       rdf = ldns_dname_new_frm_str(s->name);
-       if(!rdf) {
+       dname = ldns_str2wire_dname(s->name, &dname_len);
+       if(!dname) {
                log_err("cannot parse forward zone name %s", s->name);
                return NULL;
        }
-       if(!(dp=delegpt_create_mlc(ldns_rdf_data(rdf)))) {
-               ldns_rdf_deep_free(rdf);
+       if(!(dp=delegpt_create_mlc(dname))) {
+               free(dname);
                log_err("out of memory");
                return NULL;
        }
-       ldns_rdf_deep_free(rdf);
+       free(dname);
        return dp;
 }
 
@@ -204,21 +204,22 @@ static int
 read_fwds_host(struct config_stub* s, struct delegpt* dp)
 {
        struct config_strlist* p;
-       ldns_rdf* rdf;
+       uint8_t* dname;
+       size_t dname_len;
        for(p = s->hosts; p; p = p->next) {
                log_assert(p->str);
-               rdf = ldns_dname_new_frm_str(p->str);
-               if(!rdf) {
+               dname = ldns_str2wire_dname(p->str, &dname_len);
+               if(!dname) {
                        log_err("cannot parse forward %s server name: '%s'", 
                                s->name, p->str);
                        return 0;
                }
-               if(!delegpt_add_ns_mlc(dp, ldns_rdf_data(rdf), 0)) {
-                       ldns_rdf_deep_free(rdf);
+               if(!delegpt_add_ns_mlc(dp, dname, 0)) {
+                       free(dname);
                        log_err("out of memory");
                        return 0;
                }
-               ldns_rdf_deep_free(rdf);
+               free(dname);
        }
        return 1;
 }
@@ -290,19 +291,20 @@ static int
 make_stub_holes(struct iter_forwards* fwd, struct config_file* cfg)
 {
        struct config_stub* s;
+       uint8_t* dname;
+       size_t dname_len;
        for(s = cfg->stubs; s; s = s->next) {
-               ldns_rdf* rdf = ldns_dname_new_frm_str(s->name);
-               if(!rdf) {
+               dname = ldns_str2wire_dname(s->name, &dname_len);
+               if(!dname) {
                        log_err("cannot parse stub name '%s'", s->name);
                        return 0;
                }
-               if(!fwd_add_stub_hole(fwd, LDNS_RR_CLASS_IN,
-                               ldns_rdf_data(rdf))) {
-                       ldns_rdf_deep_free(rdf);
+               if(!fwd_add_stub_hole(fwd, LDNS_RR_CLASS_IN, dname)) {
+                       free(dname);
                        log_err("out of memory");
                        return 0;
                }
-               ldns_rdf_deep_free(rdf);
+               free(dname);
        }
        return 1;
 }
index cde3a7e1bac3d8f4ab6aa646beaa4dbadf0d7192..960c98e059d099893da4db85b864f72c5f07bd4b 100644 (file)
  * Keep track of stub and root hints, and read those from config.
  */
 #include "config.h"
-#include <ldns/dname.h>
-#include <ldns/rr.h>
 #include "iterator/iter_hints.h"
 #include "iterator/iter_delegpt.h"
 #include "util/log.h"
 #include "util/config_file.h"
 #include "util/net_help.h"
 #include "util/data/dname.h"
+#include "ldns/rrdef.h"
+#include "ldns/str2wire.h"
+#include "ldns/wire2str.h"
 
 struct iter_hints* 
 hints_create(void)
@@ -92,19 +93,20 @@ ah(struct delegpt* dp, const char* sv, const char* ip)
 {
        struct sockaddr_storage addr;
        socklen_t addrlen;
-       ldns_rdf* rdf = ldns_dname_new_frm_str(sv);
-       if(!rdf) {
+       size_t dname_len;
+       uint8_t* dname = ldns_str2wire_dname(sv, &dname_len);
+       if(!dname) {
                log_err("could not parse %s", sv);
                return 0;
        }
-       if(!delegpt_add_ns_mlc(dp, ldns_rdf_data(rdf), 0) ||
+       if(!delegpt_add_ns_mlc(dp, dname, 0) ||
           !extstrtoaddr(ip, &addr, &addrlen) ||
-          !delegpt_add_target_mlc(dp, ldns_rdf_data(rdf), ldns_rdf_size(rdf),
+          !delegpt_add_target_mlc(dp, dname, dname_len,
                &addr, addrlen, 0, 0)) {
-               ldns_rdf_deep_free(rdf);
+               free(dname);
                return 0;
        }
-       ldns_rdf_deep_free(rdf);
+       free(dname);
        return 1;
 }
 
@@ -186,22 +188,23 @@ static struct delegpt*
 read_stubs_name(struct config_stub* s)
 {
        struct delegpt* dp;
-       ldns_rdf* rdf;
+       size_t dname_len;
+       uint8_t* dname;
        if(!s->name) {
                log_err("stub zone without a name");
                return NULL;
        }
-       rdf = ldns_dname_new_frm_str(s->name);
-       if(!rdf) {
+       dname = ldns_str2wire_dname(s->name, &dname_len);
+       if(!dname) {
                log_err("cannot parse stub zone name %s", s->name);
                return NULL;
        }
-       if(!(dp=delegpt_create_mlc(ldns_rdf_data(rdf)))) {
-               ldns_rdf_deep_free(rdf);
+       if(!(dp=delegpt_create_mlc(dname))) {
+               free(dname);
                log_err("out of memory");
                return NULL;
        }
-       ldns_rdf_deep_free(rdf);
+       free(dname);
        return dp;
 }
 
@@ -210,21 +213,22 @@ static int
 read_stubs_host(struct config_stub* s, struct delegpt* dp)
 {
        struct config_strlist* p;
-       ldns_rdf* rdf;
+       size_t dname_len;
+       uint8_t* dname;
        for(p = s->hosts; p; p = p->next) {
                log_assert(p->str);
-               rdf = ldns_dname_new_frm_str(p->str);
-               if(!rdf) {
+               dname = ldns_str2wire_dname(p->str, &dname_len);
+               if(!dname) {
                        log_err("cannot parse stub %s nameserver name: '%s'", 
                                s->name, p->str);
                        return 0;
                }
-               if(!delegpt_add_ns_mlc(dp, ldns_rdf_data(rdf), 0)) {
-                       ldns_rdf_deep_free(rdf);
+               if(!delegpt_add_ns_mlc(dp, dname, 0)) {
+                       free(dname);
                        log_err("out of memory");
                        return 0;
                }
-               ldns_rdf_deep_free(rdf);
+               free(dname);
        }
        return 1;
 }
@@ -279,13 +283,11 @@ read_stubs(struct iter_hints* hints, struct config_file* cfg)
 static int 
 read_root_hints(struct iter_hints* hints, char* fname)
 {
-       int lineno = 0;
-       uint32_t default_ttl = 0;
-       ldns_rdf* origin = NULL;
-       ldns_rdf* prev_rr = NULL;
+       struct ldns_file_parse_state pstate;
        struct delegpt* dp;
-       ldns_rr* rr = NULL;
-       ldns_status status;
+       uint8_t rr[LDNS_RR_BUF_SIZE];
+       size_t rr_len, dname_len;
+       int status;
        uint16_t c = LDNS_RR_CLASS_IN;
        FILE* f = fopen(fname, "r");
        if(!f) {
@@ -300,77 +302,78 @@ read_root_hints(struct iter_hints* hints, char* fname)
                return 0;
        }
        verbose(VERB_QUERY, "Reading root hints from %s", fname);
+       memset(&pstate, 0, sizeof(pstate));
+       pstate.lineno = 1;
        dp->has_parent_side_NS = 1;
        while(!feof(f)) {
-               status = ldns_rr_new_frm_fp_l(&rr, f, 
-                       &default_ttl, &origin, &prev_rr, &lineno);
-               if(status == LDNS_STATUS_SYNTAX_EMPTY ||
-                       status == LDNS_STATUS_SYNTAX_TTL ||
-                       status == LDNS_STATUS_SYNTAX_ORIGIN)
-                       continue;
-               if(status != LDNS_STATUS_OK) {
-                       log_err("reading root hints %s %d: %s", fname,
-                               lineno, ldns_get_errorstr_by_id(status));
+               rr_len = sizeof(rr);
+               dname_len = 0;
+               status = ldns_fp2wire_rr_buf(f, rr, &rr_len, &dname_len,
+                       &pstate);
+               if(status != 0) {
+                       log_err("reading root hints %s %d:%d: %s", fname,
+                               pstate.lineno, LDNS_WIREPARSE_OFFSET(status),
+                               ldns_get_errorstr_parse(status));
                        goto stop_read;
                }
-               if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_NS) {
-                       if(!delegpt_add_ns_mlc(dp,
-                               ldns_rdf_data(ldns_rr_rdf(rr, 0)), 0)) {
+               if(rr_len == 0)
+                       continue; /* EMPTY line, TTL or ORIGIN */
+               if(ldns_wirerr_get_type(rr, rr_len, dname_len)
+                       == LDNS_RR_TYPE_NS) {
+                       if(!delegpt_add_ns_mlc(dp, ldns_wirerr_get_rdata(rr,
+                               rr_len, dname_len), 0)) {
                                log_err("out of memory reading root hints");
                                goto stop_read;
                        }
-                       c = ldns_rr_get_class(rr);
+                       c = ldns_wirerr_get_class(rr, rr_len, dname_len);
                        if(!dp->name) {
-                               if(!delegpt_set_name_mlc(dp,
-                                       ldns_rdf_data(ldns_rr_owner(rr)))){
+                               if(!delegpt_set_name_mlc(dp, rr)) {
                                        log_err("out of memory.");
                                        goto stop_read;
                                }
                        }
-               } else if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_A) {
+               } else if(ldns_wirerr_get_type(rr, rr_len, dname_len)
+                       == LDNS_RR_TYPE_A && ldns_wirerr_get_rdatalen(rr,
+                       rr_len, dname_len) == INET_SIZE) {
                        struct sockaddr_in sa;
                        socklen_t len = (socklen_t)sizeof(sa);
                        memset(&sa, 0, len);
                        sa.sin_family = AF_INET;
                        sa.sin_port = (in_port_t)htons(UNBOUND_DNS_PORT);
                        memmove(&sa.sin_addr, 
-                               ldns_rdf_data(ldns_rr_rdf(rr, 0)), INET_SIZE);
-                       if(!delegpt_add_target_mlc(dp,
-                                       ldns_rdf_data(ldns_rr_owner(rr)),
-                                       ldns_rdf_size(ldns_rr_owner(rr)),
+                               ldns_wirerr_get_rdata(rr, rr_len, dname_len),
+                               INET_SIZE);
+                       if(!delegpt_add_target_mlc(dp, rr, dname_len,
                                        (struct sockaddr_storage*)&sa, len, 
                                        0, 0)) {
                                log_err("out of memory reading root hints");
                                goto stop_read;
                        }
-               } else if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_AAAA) {
+               } else if(ldns_wirerr_get_type(rr, rr_len, dname_len)
+                       == LDNS_RR_TYPE_AAAA && ldns_wirerr_get_rdatalen(rr,
+                       rr_len, dname_len) == INET6_SIZE) {
                        struct sockaddr_in6 sa;
                        socklen_t len = (socklen_t)sizeof(sa);
                        memset(&sa, 0, len);
                        sa.sin6_family = AF_INET6;
                        sa.sin6_port = (in_port_t)htons(UNBOUND_DNS_PORT);
                        memmove(&sa.sin6_addr, 
-                               ldns_rdf_data(ldns_rr_rdf(rr, 0)), INET6_SIZE);
-                       if(!delegpt_add_target_mlc(dp,
-                                       ldns_rdf_data(ldns_rr_owner(rr)),
-                                       ldns_rdf_size(ldns_rr_owner(rr)),
+                               ldns_wirerr_get_rdata(rr, rr_len, dname_len),
+                               INET6_SIZE);
+                       if(!delegpt_add_target_mlc(dp, rr, dname_len,
                                        (struct sockaddr_storage*)&sa, len,
                                        0, 0)) {
                                log_err("out of memory reading root hints");
                                goto stop_read;
                        }
                } else {
-                       log_warn("root hints %s:%d skipping type %d",
-                               fname, lineno, ldns_rr_get_type(rr));
+                       char buf[17];
+                       ldns_wire2str_type_buf(ldns_wirerr_get_type(rr,
+                               rr_len, dname_len), buf, sizeof(buf));
+                       log_warn("root hints %s:%d skipping type %s",
+                               fname, pstate.lineno, buf);
                }
-
-               ldns_rr_free(rr);
        }
-
-       if (origin)
-               ldns_rdf_deep_free(origin);
-       if (prev_rr)
-               ldns_rdf_deep_free(prev_rr);
        fclose(f);
        if(!dp->name) {
                log_warn("root hints %s: no NS content", fname);
@@ -384,10 +387,6 @@ read_root_hints(struct iter_hints* hints, char* fname)
        return 1;
 
 stop_read:
-       if (origin)
-               ldns_rdf_deep_free(origin);
-       if (prev_rr)
-               ldns_rdf_deep_free(prev_rr);
        delegpt_free_mlc(dp);
        fclose(f);
        return 0;
index 572f701f350da001187ec23bcc07e747887bc86c..37cd35d89790ab6fa73b13b8827bd23569905c4d 100644 (file)
@@ -41,7 +41,6 @@
  */
 
 #include "config.h"
-#include <ldns/dname.h>
 #include "iterator/iter_priv.h"
 #include "util/regional.h"
 #include "util/log.h"
@@ -50,6 +49,8 @@
 #include "util/data/msgparse.h"
 #include "util/net_help.h"
 #include "util/storage/dnstree.h"
+#include "ldns/str2wire.h"
+#include "ldns/sbuffer.h"
 
 struct iter_priv* priv_create(void)
 {
@@ -110,23 +111,21 @@ static int read_names(struct iter_priv* priv, struct config_file* cfg)
        /* parse names, report errors, insert into tree */
        struct config_strlist* p;
        struct name_tree_node* n;
-       uint8_t* nm;
+       uint8_t* nm, *nmr;
        size_t nm_len;
        int nm_labs;
-       ldns_rdf* rdf;
 
        for(p = cfg->private_domain; p; p = p->next) {
                log_assert(p->str);
-               rdf = ldns_dname_new_frm_str(p->str);
-               if(!rdf) {
+               nm = ldns_str2wire_dname(p->str, &nm_len);
+               if(!nm) {
                        log_err("cannot parse private-domain: %s", p->str);
                        return 0;
                }
-               nm = ldns_rdf_data(rdf);
                nm_labs = dname_count_size_labels(nm, &nm_len);
-               nm = (uint8_t*)regional_alloc_init(priv->region, nm, nm_len);
-               ldns_rdf_deep_free(rdf);
-               if(!nm) {
+               nmr = (uint8_t*)regional_alloc_init(priv->region, nm, nm_len);
+               free(nm);
+               if(!nmr) {
                        log_err("out of memory");
                        return 0;
                }
@@ -136,7 +135,7 @@ static int read_names(struct iter_priv* priv, struct config_file* cfg)
                        log_err("out of memory");
                        return 0;
                }
-               if(!name_tree_insert(&priv->n, n, nm, nm_len, nm_labs,
+               if(!name_tree_insert(&priv->n, n, nmr, nm_len, nm_labs,
                        LDNS_RR_CLASS_IN)) {
                        verbose(VERB_QUERY, "ignoring duplicate "
                                "private-domain: %s", p->str);
index e6e51c159b09b9419c15c65fe4845c46f4b34e25..19b3cbc3f00bba608aba33a297fd5612863193f7 100644 (file)
@@ -43,7 +43,7 @@
 #ifndef ITERATOR_ITER_PRIV_H
 #define ITERATOR_ITER_PRIV_H
 #include "util/rbtree.h"
-#include <ldns/buffer.h>
+struct ldns_buffer;
 struct iter_env;
 struct config_file;
 struct regional;
@@ -99,7 +99,7 @@ int priv_apply_cfg(struct iter_priv* priv, struct config_file* cfg);
  * @param rrset: the rrset to examine, A or AAAA.
  * @return true if the rrset is bad and should be removed.
  */
-int priv_rrset_bad(struct iter_priv* priv, ldns_buffer* pkt, 
+int priv_rrset_bad(struct iter_priv* priv, struct ldns_buffer* pkt, 
        struct rrset_parse* rrset);
 
 /**
index 2cdc5fcfc3d355361efec89478f6a67e35072004..377cdf454f2ed43d32bec00bd202d135222ffd57 100644 (file)
  * one of the response types.
  */
 #include "config.h"
-#include <ldns/packet.h>
 #include "iterator/iter_resptype.h"
 #include "iterator/iter_delegpt.h"
 #include "services/cache/dns.h"
 #include "util/net_help.h"
 #include "util/data/dname.h"
+#include "ldns/rrdef.h"
+#include "ldns/pkthdr.h"
 
 enum response_type 
 response_type_from_cache(struct dns_msg* msg, 
index a2407c27c84020dc05261b64689ce4e39f267c27..0b1a02ae0acbc888615d1baacec92fecdf04fa66 100644 (file)
@@ -53,6 +53,7 @@
 #include "util/data/dname.h"
 #include "util/data/msgreply.h"
 #include "util/alloc.h"
+#include "ldns/sbuffer.h"
 
 /** RRset flag used during scrubbing. The RRset is OK. */
 #define RRSET_SCRUB_OK 0x80
index 6b7274e4ac364f513811e9535ce8327d9d5148b1..7ef14ded347e5bab3a54fc78cfb0b35b9dd57a2e 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef ITERATOR_ITER_SCRUB_H
 #define ITERATOR_ITER_SCRUB_H
-#include <ldns/buffer.h>
+struct ldns_buffer;
 struct msg_parse;
 struct query_info;
 struct regional;
@@ -62,7 +62,7 @@ struct iter_env;
  * @param ie: iterator module environment data.
  * @return: false if the message is total waste. true if scrubbed with success.
  */
-int scrub_message(ldns_buffer* pkt, struct msg_parse* msg, 
+int scrub_message(struct ldns_buffer* pkt, struct msg_parse* msg, 
        struct query_info* qinfo, uint8_t* zonename, struct regional* regional,
        struct module_env* env, struct iter_env* ie);
 
index 28f7dc2415c1343baec9e8bb91b5df7d3f9d80f4..6bea745ae6c070c5ac9590409abf559b31fed24e 100644 (file)
@@ -63,6 +63,8 @@
 #include "validator/val_kcache.h"
 #include "validator/val_kentry.h"
 #include "validator/val_utils.h"
+#include "validator/val_sigcrypt.h"
+#include "ldns/sbuffer.h"
 
 /** time when nameserver glue is said to be 'recent' */
 #define SUSPICION_RECENT_EXPIRY 86400
@@ -682,7 +684,7 @@ rrset_equal(struct ub_packed_rrset_key* k1, struct ub_packed_rrset_key* k2)
 }
 
 int 
-reply_equal(struct reply_info* p, struct reply_info* q, ldns_buffer* scratch)
+reply_equal(struct reply_info* p, struct reply_info* q, struct regional* region)
 {
        size_t i;
        if(p->flags != q->flags ||
@@ -697,27 +699,12 @@ reply_equal(struct reply_info* p, struct reply_info* q, ldns_buffer* scratch)
                return 0;
        for(i=0; i<p->rrset_count; i++) {
                if(!rrset_equal(p->rrsets[i], q->rrsets[i])) {
-                       /* fallback procedure: try to sort and canonicalize */
-                       ldns_rr_list* pl, *ql;
-                       pl = packed_rrset_to_rr_list(p->rrsets[i], scratch);
-                       ql = packed_rrset_to_rr_list(q->rrsets[i], scratch);
-                       if(!pl || !ql) {
-                               ldns_rr_list_deep_free(pl);
-                               ldns_rr_list_deep_free(ql);
+                       if(!rrset_canonical_equal(region, p->rrsets[i],
+                               q->rrsets[i])) {
+                               regional_free_all(region);
                                return 0;
                        }
-                       ldns_rr_list2canonical(pl);
-                       ldns_rr_list2canonical(ql);
-                       ldns_rr_list_sort(pl);
-                       ldns_rr_list_sort(ql);
-                       if(ldns_rr_list_compare(pl, ql) != 0) {
-                               ldns_rr_list_deep_free(pl);
-                               ldns_rr_list_deep_free(ql);
-                               return 0;
-                       }
-                       ldns_rr_list_deep_free(pl);
-                       ldns_rr_list_deep_free(ql);
-                       continue;
+                       regional_free_all(region);
                }
        }
        return 1;
index 2070622d47581ab0bca9512ac4d5ae2a92af9f98..d660772db9e53e703bfa235fb63ec39c41fd4116 100644 (file)
@@ -43,7 +43,7 @@
 #ifndef ITERATOR_ITER_UTILS_H
 #define ITERATOR_ITER_UTILS_H
 #include "iterator/iter_resptype.h"
-#include <ldns/buffer.h>
+struct ldns_buffer;
 struct iter_env;
 struct iter_hints;
 struct iter_forwards;
@@ -102,7 +102,7 @@ struct delegpt_addr* iter_server_selection(struct iter_env* iter_env,
  * @param regional: regional to use for allocation.
  * @return newly allocated dns_msg, or NULL on memory error.
  */
-struct dns_msg* dns_alloc_msg(ldns_buffer* pkt, struct msg_parse* msg, 
+struct dns_msg* dns_alloc_msg(struct ldns_buffer* pkt, struct msg_parse* msg, 
        struct regional* regional);
 
 /**
@@ -216,10 +216,10 @@ int iter_msg_from_zone(struct dns_msg* msg, struct delegpt* dp,
  * @param p: reply one. The reply has rrset data pointers in region.
  *     Does not check rrset-IDs
  * @param q: reply two
- * @param buf: scratch buffer.
+ * @param region: scratch buffer.
  * @return if one and two are equal.
  */
-int reply_equal(struct reply_info* p, struct reply_info* q, ldns_buffer* buf);
+int reply_equal(struct reply_info* p, struct reply_info* q, struct regional* region);
 
 /**
  * Store parent-side rrset in seperate rrset cache entries for later 
index 3c9804926d13dd05da1ef1b98776efe8649e3817..c4254c17ab04f8a6f03c17e6aaf74d583491cca6 100644 (file)
@@ -41,7 +41,6 @@
  */
 
 #include "config.h"
-#include <ldns/ldns.h>
 #include "iterator/iterator.h"
 #include "iterator/iter_utils.h"
 #include "iterator/iter_hints.h"
 #include "util/data/msgencode.h"
 #include "util/fptr_wlist.h"
 #include "util/config_file.h"
+#include "ldns/rrdef.h"
+#include "ldns/wire2str.h"
+#include "ldns/parseutil.h"
+#include "ldns/sbuffer.h"
 
 int 
 iter_init(struct module_env* env, int id)
@@ -2815,7 +2818,7 @@ process_response(struct module_qstate* qstate, struct iter_qstate* iq,
                } else {
                        /* check if reply is the same, otherwise, fail */
                        if(!reply_equal(iq->response->rep, iq->caps_reply,
-                               qstate->env->scratch_buffer)) {
+                               qstate->env->scratch)) {
                                verbose(VERB_DETAIL, "Capsforid fallback: "
                                        "getting different replies, failed");
                                outbound_list_remove(&iq->outlist, outbound);
diff --git a/ldns/keyraw.c b/ldns/keyraw.c
new file mode 100644 (file)
index 0000000..a207835
--- /dev/null
@@ -0,0 +1,368 @@
+/*
+ * keyraw.c - raw key operations and conversions
+ *
+ * (c) NLnet Labs, 2004-2008
+ *
+ * See the file LICENSE for the license
+ */
+/**
+ * \file
+ * Implementation of raw DNSKEY functions (work on wire rdata).
+ */
+
+#include "config.h"
+#include "ldns/keyraw.h"
+#include "ldns/rrdef.h"
+
+#ifdef HAVE_SSL
+#include <openssl/ssl.h>
+#include <openssl/evp.h>
+#include <openssl/rand.h>
+#include <openssl/err.h>
+#include <openssl/md5.h>
+#ifdef HAVE_OPENSSL_ENGINE_H
+#  include <openssl/engine.h>
+#endif
+#endif /* HAVE_SSL */
+
+size_t
+ldns_rr_dnskey_key_size_raw(const unsigned char* keydata,
+       const size_t len, int alg)
+{
+       /* for DSA keys */
+       uint8_t t;
+       
+       /* for RSA keys */
+       uint16_t exp;
+       uint16_t int16;
+       
+       switch ((ldns_algorithm)alg) {
+       case LDNS_DSA:
+       case LDNS_DSA_NSEC3:
+               if (len > 0) {
+                       t = keydata[0];
+                       return (64 + t*8)*8;
+               } else {
+                       return 0;
+               }
+               break;
+       case LDNS_RSAMD5:
+       case LDNS_RSASHA1:
+       case LDNS_RSASHA1_NSEC3:
+#ifdef USE_SHA2
+       case LDNS_RSASHA256:
+       case LDNS_RSASHA512:
+#endif
+               if (len > 0) {
+                       if (keydata[0] == 0) {
+                               /* big exponent */
+                               if (len > 3) {
+                                       memmove(&int16, keydata + 1, 2);
+                                       exp = ntohs(int16);
+                                       return (len - exp - 3)*8;
+                               } else {
+                                       return 0;
+                               }
+                       } else {
+                               exp = keydata[0];
+                               return (len-exp-1)*8;
+                       }
+               } else {
+                       return 0;
+               }
+               break;
+#ifdef USE_GOST
+       case LDNS_ECC_GOST:
+               return 512;
+#endif
+#ifdef USE_ECDSA
+        case LDNS_ECDSAP256SHA256:
+                return 256;
+        case LDNS_ECDSAP384SHA384:
+                return 384;
+#endif
+       default:
+               return 0;
+       }
+}
+
+uint16_t ldns_calc_keytag_raw(uint8_t* key, size_t keysize)
+{
+       if(keysize < 4) {
+               return 0;
+       }
+       /* look at the algorithm field, copied from 2535bis */
+       if (key[3] == LDNS_RSAMD5) {
+               uint16_t ac16 = 0;
+               if (keysize > 4) {
+                       memmove(&ac16, key + keysize - 3, 2);
+               }
+               ac16 = ntohs(ac16);
+               return (uint16_t) ac16;
+       } else {
+               size_t i;
+               uint32_t ac32 = 0;
+               for (i = 0; i < keysize; ++i) {
+                       ac32 += (i & 1) ? key[i] : key[i] << 8;
+               }
+               ac32 += (ac32 >> 16) & 0xFFFF;
+               return (uint16_t) (ac32 & 0xFFFF);
+       }
+}
+
+#ifdef HAVE_SSL
+#ifdef USE_GOST
+/** store GOST engine reference loaded into OpenSSL library */
+ENGINE* ldns_gost_engine = NULL;
+
+int
+ldns_key_EVP_load_gost_id(void)
+{
+       static int gost_id = 0;
+       const EVP_PKEY_ASN1_METHOD* meth;
+       ENGINE* e;
+
+       if(gost_id) return gost_id;
+
+       /* see if configuration loaded gost implementation from other engine*/
+       meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
+       if(meth) {
+               EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
+               return gost_id;
+       }
+
+       /* see if engine can be loaded already */
+       e = ENGINE_by_id("gost");
+       if(!e) {
+               /* load it ourself, in case statically linked */
+               ENGINE_load_builtin_engines();
+               ENGINE_load_dynamic();
+               e = ENGINE_by_id("gost");
+       }
+       if(!e) {
+               /* no gost engine in openssl */
+               return 0;
+       }
+       if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
+               ENGINE_finish(e);
+               ENGINE_free(e);
+               return 0;
+       }
+
+       meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
+       if(!meth) {
+               /* algo not found */
+               ENGINE_finish(e);
+               ENGINE_free(e);
+               return 0;
+       }
+        /* Note: do not ENGINE_finish and ENGINE_free the acquired engine
+         * on some platforms this frees up the meth and unloads gost stuff */
+        ldns_gost_engine = e;
+       
+       EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
+       return gost_id;
+} 
+
+void ldns_key_EVP_unload_gost(void)
+{
+        if(ldns_gost_engine) {
+                ENGINE_finish(ldns_gost_engine);
+                ENGINE_free(ldns_gost_engine);
+                ldns_gost_engine = NULL;
+        }
+}
+#endif /* USE_GOST */
+
+DSA *
+ldns_key_buf2dsa_raw(unsigned char* key, size_t len)
+{
+       uint8_t T;
+       uint16_t length;
+       uint16_t offset;
+       DSA *dsa;
+       BIGNUM *Q; BIGNUM *P;
+       BIGNUM *G; BIGNUM *Y;
+
+       if(len == 0)
+               return NULL;
+       T = (uint8_t)key[0];
+       length = (64 + T * 8);
+       offset = 1;
+
+       if (T > 8) {
+               return NULL;
+       }
+       if(len < (size_t)1 + SHA_DIGEST_LENGTH + 3*length)
+               return NULL;
+
+       Q = BN_bin2bn(key+offset, SHA_DIGEST_LENGTH, NULL);
+       offset += SHA_DIGEST_LENGTH;
+
+       P = BN_bin2bn(key+offset, (int)length, NULL);
+       offset += length;
+
+       G = BN_bin2bn(key+offset, (int)length, NULL);
+       offset += length;
+
+       Y = BN_bin2bn(key+offset, (int)length, NULL);
+       offset += length;
+
+       /* create the key and set its properties */
+       if(!Q || !P || !G || !Y || !(dsa = DSA_new())) {
+               BN_free(Q);
+               BN_free(P);
+               BN_free(G);
+               BN_free(Y);
+               return NULL;
+       }
+#ifndef S_SPLINT_S
+       dsa->p = P;
+       dsa->q = Q;
+       dsa->g = G;
+       dsa->pub_key = Y;
+#endif /* splint */
+
+       return dsa;
+}
+
+RSA *
+ldns_key_buf2rsa_raw(unsigned char* key, size_t len)
+{
+       uint16_t offset;
+       uint16_t exp;
+       uint16_t int16;
+       RSA *rsa;
+       BIGNUM *modulus;
+       BIGNUM *exponent;
+
+       if (len == 0)
+               return NULL;
+       if (key[0] == 0) {
+               if(len < 3)
+                       return NULL;
+               memmove(&int16, key+1, 2);
+               exp = ntohs(int16);
+               offset = 3;
+       } else {
+               exp = key[0];
+               offset = 1;
+       }
+
+       /* key length at least one */
+       if(len < (size_t)offset + exp + 1)
+               return NULL;
+
+       /* Exponent */
+       exponent = BN_new();
+       if(!exponent) return NULL;
+       (void) BN_bin2bn(key+offset, (int)exp, exponent);
+       offset += exp;
+
+       /* Modulus */
+       modulus = BN_new();
+       if(!modulus) {
+               BN_free(exponent);
+               return NULL;
+       }
+       /* length of the buffer must match the key length! */
+       (void) BN_bin2bn(key+offset, (int)(len - offset), modulus);
+
+       rsa = RSA_new();
+       if(!rsa) {
+               BN_free(exponent);
+               BN_free(modulus);
+               return NULL;
+       }
+#ifndef S_SPLINT_S
+       rsa->n = modulus;
+       rsa->e = exponent;
+#endif /* splint */
+
+       return rsa;
+}
+
+#ifdef USE_GOST
+EVP_PKEY*
+ldns_gost2pkey_raw(unsigned char* key, size_t keylen)
+{
+       /* prefix header for X509 encoding */
+       uint8_t asn[37] = { 0x30, 0x63, 0x30, 0x1c, 0x06, 0x06, 0x2a, 0x85, 
+               0x03, 0x02, 0x02, 0x13, 0x30, 0x12, 0x06, 0x07, 0x2a, 0x85, 
+               0x03, 0x02, 0x02, 0x23, 0x01, 0x06, 0x07, 0x2a, 0x85, 0x03, 
+               0x02, 0x02, 0x1e, 0x01, 0x03, 0x43, 0x00, 0x04, 0x40};
+       unsigned char encoded[37+64];
+       const unsigned char* pp;
+       if(keylen != 64) {
+               /* key wrong size */
+               return NULL;
+       }
+
+       /* create evp_key */
+       memmove(encoded, asn, 37);
+       memmove(encoded+37, key, 64);
+       pp = (unsigned char*)&encoded[0];
+
+       return d2i_PUBKEY(NULL, &pp, (int)sizeof(encoded));
+}
+#endif /* USE_GOST */
+
+#ifdef USE_ECDSA
+EVP_PKEY*
+ldns_ecdsa2pkey_raw(unsigned char* key, size_t keylen, uint8_t algo)
+{
+       unsigned char buf[256+2]; /* sufficient for 2*384/8+1 */
+        const unsigned char* pp = buf;
+        EVP_PKEY *evp_key;
+        EC_KEY *ec;
+       /* check length, which uncompressed must be 2 bignums */
+        if(algo == LDNS_ECDSAP256SHA256) {
+               if(keylen != 2*256/8) return NULL;
+                ec = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
+        } else if(algo == LDNS_ECDSAP384SHA384) {
+               if(keylen != 2*384/8) return NULL;
+                ec = EC_KEY_new_by_curve_name(NID_secp384r1);
+        } else    ec = NULL;
+        if(!ec) return NULL;
+       if(keylen+1 > sizeof(buf))
+               return NULL; /* sanity check */
+       /* prepend the 0x02 (from docs) (or actually 0x04 from implementation
+        * of openssl) for uncompressed data */
+       buf[0] = POINT_CONVERSION_UNCOMPRESSED;
+       memmove(buf+1, key, keylen);
+        if(!o2i_ECPublicKey(&ec, &pp, (int)keylen+1)) {
+                EC_KEY_free(ec);
+                return NULL;
+        }
+        evp_key = EVP_PKEY_new();
+        if(!evp_key) {
+                EC_KEY_free(ec);
+                return NULL;
+        }
+        if (!EVP_PKEY_assign_EC_KEY(evp_key, ec)) {
+               EVP_PKEY_free(evp_key);
+               EC_KEY_free(ec);
+               return NULL;
+       }
+        return evp_key;
+}
+#endif /* USE_ECDSA */
+
+int
+ldns_digest_evp(unsigned char* data, unsigned int len, unsigned char* dest,
+       const EVP_MD* md)
+{
+       EVP_MD_CTX* ctx;
+       ctx = EVP_MD_CTX_create();
+       if(!ctx)
+               return 0;
+       if(!EVP_DigestInit_ex(ctx, md, NULL) ||
+               !EVP_DigestUpdate(ctx, data, len) ||
+               !EVP_DigestFinal_ex(ctx, dest, NULL)) {
+               EVP_MD_CTX_destroy(ctx);
+               return 0;
+       }
+       EVP_MD_CTX_destroy(ctx);
+       return 1;
+}
+#endif /* HAVE_SSL */
diff --git a/ldns/keyraw.h b/ldns/keyraw.h
new file mode 100644 (file)
index 0000000..9314891
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * keyraw.h -- raw key and signature access and conversion
+ *
+ * Copyright (c) 2005-2008, NLnet Labs. All rights reserved.
+ *
+ * See LICENSE for the license.
+ *
+ */
+
+/**
+ * \file
+ *
+ * raw key and signature access and conversion
+ *
+ * Since those functions heavily rely op cryptographic operations,
+ * this module is dependent on openssl.
+ * 
+ */
+#ifndef LDNS_KEYRAW_H
+#define LDNS_KEYRAW_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#if LDNS_BUILD_CONFIG_HAVE_SSL
+#  include <openssl/ssl.h>
+#  include <openssl/evp.h>
+#endif /* LDNS_BUILD_CONFIG_HAVE_SSL */
+
+/**
+ * get the length of the keydata in bits
+ * \param[in] keydata the raw key data
+ * \param[in] len the length of the keydata
+ * \param[in] alg the cryptographic algorithm this is a key for
+ * \return the keysize in bits, or 0 on error
+ */
+size_t ldns_rr_dnskey_key_size_raw(const unsigned char *keydata,
+       const size_t len, int alg);
+
+/**
+ * Calculates keytag of DNSSEC key, operates on wireformat rdata.
+ * \param[in] key the key as uncompressed wireformat rdata.
+ * \param[in] keysize length of key data.
+ * \return the keytag
+ */
+uint16_t ldns_calc_keytag_raw(uint8_t* key, size_t keysize);
+
+#if LDNS_BUILD_CONFIG_HAVE_SSL
+/** 
+ * Get the PKEY id for GOST, loads GOST into openssl as a side effect.
+ * Only available if GOST is compiled into the library and openssl.
+ * \return the gost id for EVP_CTX creation.
+ */
+int ldns_key_EVP_load_gost_id(void);
+
+/** Release the engine reference held for the GOST engine. */
+void ldns_key_EVP_unload_gost(void);
+
+/**
+ * Like ldns_key_buf2dsa, but uses raw buffer.
+ * \param[in] key the uncompressed wireformat of the key.
+ * \param[in] len length of key data
+ * \return a DSA * structure with the key material
+ */
+DSA *ldns_key_buf2dsa_raw(unsigned char* key, size_t len);
+
+/**
+ * Converts a holding buffer with key material to EVP PKEY in openssl.
+ * Only available if ldns was compiled with GOST.
+ * \param[in] key data to convert
+ * \param[in] keylen length of the key data
+ * \return the key or NULL on error.
+ */
+EVP_PKEY* ldns_gost2pkey_raw(unsigned char* key, size_t keylen);
+
+/**
+ * Converts a holding buffer with key material to EVP PKEY in openssl.
+ * Only available if ldns was compiled with ECDSA.
+ * \param[in] key data to convert
+ * \param[in] keylen length of the key data
+ * \param[in] algo precise algorithm to initialize ECC group values.
+ * \return the key or NULL on error.
+ */
+EVP_PKEY* ldns_ecdsa2pkey_raw(unsigned char* key, size_t keylen, uint8_t algo);
+
+/**
+ * Like ldns_key_buf2rsa, but uses raw buffer.
+ * \param[in] key the uncompressed wireformat of the key.
+ * \param[in] len length of key data
+ * \return a RSA * structure with the key material
+ */
+RSA *ldns_key_buf2rsa_raw(unsigned char* key, size_t len);
+
+/**
+ * Utility function to calculate hash using generic EVP_MD pointer.
+ * \param[in] data the data to hash.
+ * \param[in] len  length of data.
+ * \param[out] dest the destination of the hash, must be large enough.
+ * \param[in] md the message digest to use.
+ * \return true if worked, false on failure.
+ */
+int ldns_digest_evp(unsigned char* data, unsigned int len, 
+       unsigned char* dest, const EVP_MD* md);
+
+#endif /* LDNS_BUILD_CONFIG_HAVE_SSL */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LDNS_KEYRAW_H */
diff --git a/ldns/parse.c b/ldns/parse.c
new file mode 100644 (file)
index 0000000..e5edc1b
--- /dev/null
@@ -0,0 +1,451 @@
+/*
+ * a generic (simple) parser. Use to parse rr's, private key
+ * information and /etc/resolv.conf files
+ *
+ * a Net::DNS like library for C
+ * LibDNS Team @ NLnet Labs
+ * (c) NLnet Labs, 2005-2006
+ * See the file LICENSE for the license
+ */
+#include "config.h"
+#include "ldns/parse.h"
+#include "ldns/parseutil.h"
+#include "ldns/sbuffer.h"
+
+#include <limits.h>
+#include <strings.h>
+
+ldns_lookup_table ldns_directive_types[] = {
+        { LDNS_DIR_TTL, "$TTL" },
+        { LDNS_DIR_ORIGIN, "$ORIGIN" },
+        { LDNS_DIR_INCLUDE, "$INCLUDE" },
+        { 0, NULL }
+};
+
+/* add max_limit here? */
+ssize_t
+ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit)
+{
+       return ldns_fget_token_l(f, token, delim, limit, NULL);
+}
+
+ssize_t
+ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr)
+{
+       int c, prev_c;
+       int p; /* 0 -> no parenthese seen, >0 nr of ( seen */
+       int com, quoted;
+       char *t;
+       size_t i;
+       const char *d;
+       const char *del;
+
+       /* standard delimeters */
+       if (!delim) {
+               /* from isspace(3) */
+               del = LDNS_PARSE_NORMAL;
+       } else {
+               del = delim;
+       }
+
+       p = 0;
+       i = 0;
+       com = 0;
+       quoted = 0;
+       prev_c = 0;
+       t = token;
+       if (del[0] == '"') {
+               quoted = 1;
+       }
+       while ((c = getc(f)) != EOF) {
+               if (c == '\r') /* carriage return */
+                       c = ' ';
+               if (c == '(' && prev_c != '\\' && !quoted) {
+                       /* this only counts for non-comments */
+                       if (com == 0) {
+                               p++;
+                       }
+                       prev_c = c;
+                       continue;
+               }
+
+               if (c == ')' && prev_c != '\\' && !quoted) {
+                       /* this only counts for non-comments */
+                       if (com == 0) {
+                               p--;
+                       }
+                       prev_c = c;
+                       continue;
+               }
+
+               if (p < 0) {
+                       /* more ) then ( - close off the string */
+                       *t = '\0';
+                       return 0;
+               }
+
+               /* do something with comments ; */
+               if (c == ';' && quoted == 0) {
+                       if (prev_c != '\\') {
+                               com = 1;
+                       }
+               }
+               if (c == '\"' && com == 0 && prev_c != '\\') {
+                       quoted = 1 - quoted;
+               }
+
+               if (c == '\n' && com != 0) {
+                       /* comments */
+                       com = 0;
+                       *t = ' ';
+                       if (line_nr) {
+                               *line_nr = *line_nr + 1;
+                       }
+                       if (p == 0 && i > 0) {
+                               goto tokenread;
+                       } else {
+                               prev_c = c;
+                               continue;
+                       }
+               }
+
+               if (com == 1) {
+                       *t = ' ';
+                       prev_c = c;
+                       continue;
+               }
+
+               if (c == '\n' && p != 0 && t > token) {
+                       /* in parentheses */
+                       if (line_nr) {
+                               *line_nr = *line_nr + 1;
+                       }
+                       *t++ = ' ';
+                       prev_c = c;
+                       continue;
+               }
+
+               /* check if we hit the delim */
+               for (d = del; *d; d++) {
+                       if (c == *d && i > 0 && prev_c != '\\' && p == 0) {
+                               if (c == '\n' && line_nr) {
+                                       *line_nr = *line_nr + 1;
+                               }
+                               goto tokenread;
+                       }
+               }
+               if (c != '\0' && c != '\n') {
+                       i++;
+               }
+               if (limit > 0 && (i >= limit || (size_t)(t-token) >= limit)) {
+                       *t = '\0';
+                       return -1;
+               }
+               if (c != '\0' && c != '\n') {
+                       *t++ = c;
+               }
+               if (c == '\\' && prev_c == '\\')
+                       prev_c = 0;
+               else    prev_c = c;
+       }
+       *t = '\0';
+       if (c == EOF) {
+               return (ssize_t)i;
+       }
+
+       if (i == 0) {
+               /* nothing read */
+               return -1;
+       }
+       if (p != 0) {
+               return -1;
+       }
+       return (ssize_t)i;
+
+tokenread:
+       ldns_fskipcs_l(f, del, line_nr);
+       *t = '\0';
+       if (p != 0) {
+               return -1;
+       }
+
+       return (ssize_t)i;
+}
+
+ssize_t
+ldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data,
+               const char *d_del, size_t data_limit)
+{
+       return ldns_fget_keyword_data_l(f, keyword, k_del, data, d_del,
+                      data_limit, NULL);
+}
+
+ssize_t
+ldns_fget_keyword_data_l(FILE *f, const char *keyword, const char *k_del, char *data,
+               const char *d_del, size_t data_limit, int *line_nr)
+{
+       /* we assume: keyword|sep|data */
+       char *fkeyword;
+       ssize_t i;
+
+       if(strlen(keyword) >= LDNS_MAX_KEYWORDLEN)
+               return -1;
+       fkeyword = (char*)malloc(LDNS_MAX_KEYWORDLEN);
+       if(!fkeyword)
+               return -1;
+
+       i = ldns_fget_token(f, fkeyword, k_del, LDNS_MAX_KEYWORDLEN);
+       if(i==0 || i==-1) {
+               free(fkeyword);
+               return -1;
+       }
+
+       /* case??? i instead of strlen? */
+       if (strncmp(fkeyword, keyword, LDNS_MAX_KEYWORDLEN - 1) == 0) {
+               /* whee! */
+               /* printf("%s\n%s\n", "Matching keyword", fkeyword); */
+               i = ldns_fget_token_l(f, data, d_del, data_limit, line_nr);
+               free(fkeyword);
+               return i;
+       } else {
+               /*printf("no match for %s (read: %s)\n", keyword, fkeyword);*/
+               free(fkeyword);
+               return -1;
+       }
+}
+
+ssize_t
+ldns_bget_token(ldns_buffer *b, char *token, const char *delim, size_t limit)
+{
+       return ldns_bget_token_par(b, token, delim, limit, NULL, NULL);
+}
+
+ssize_t
+ldns_bget_token_par(ldns_buffer *b, char *token, const char *delim,
+       size_t limit, int* par, const char* skipw)
+{
+       int c, lc;
+       int p; /* 0 -> no parenthese seen, >0 nr of ( seen */
+       int com, quoted;
+       char *t;
+       size_t i;
+       const char *d;
+       const char *del;
+
+       /* standard delimiters */
+       if (!delim) {
+               /* from isspace(3) */
+               del = LDNS_PARSE_NORMAL;
+       } else {
+               del = delim;
+       }
+
+       p = (par?*par:0);
+       i = 0;
+       com = 0;
+       quoted = 0;
+       t = token;
+       lc = 0;
+       if (del[0] == '"') {
+               quoted = 1;
+       }
+
+       while ((c = ldns_bgetc(b)) != EOF) {
+               if (c == '\r') /* carriage return */
+                       c = ' ';
+               if (c == '(' && lc != '\\' && !quoted) {
+                       /* this only counts for non-comments */
+                       if (com == 0) {
+                               if(par) (*par)++;
+                               p++;
+                       }
+                       lc = c;
+                       continue;
+               }
+
+               if (c == ')' && lc != '\\' && !quoted) {
+                       /* this only counts for non-comments */
+                       if (com == 0) {
+                               if(par) (*par)--;
+                               p--;
+                       }
+                       lc = c;
+                       continue;
+               }
+
+               if (p < 0) {
+                       /* more ) then ( */
+                       *t = '\0';
+                       return 0;
+               }
+
+               /* do something with comments ; */
+               if (c == ';' && quoted == 0) {
+                       if (lc != '\\') {
+                               com = 1;
+                       }
+               }
+               if (c == '"' && com == 0 && lc != '\\') {
+                       quoted = 1 - quoted;
+               }
+
+               if (c == '\n' && com != 0) {
+                       /* comments */
+                       com = 0;
+                       *t = ' ';
+                       lc = c;
+                       continue;
+               }
+
+               if (com == 1) {
+                       *t = ' ';
+                       lc = c;
+                       continue;
+               }
+
+               if (c == '\n' && p != 0) {
+                       /* in parentheses */
+                       /* do not write ' ' if we want to skip spaces */
+                       if(!(skipw && (strchr(skipw, c)||strchr(skipw, ' '))))
+                               *t++ = ' ';
+                       lc = c;
+                       continue;
+               }
+
+               /* check to skip whitespace at start, but also after ( */
+               if(skipw && i==0 && !com && !quoted && lc != '\\') {
+                       if(strchr(skipw, c)) {
+                               lc = c;
+                               continue;
+                       }
+               }
+
+               /* check if we hit the delim */
+               for (d = del; *d; d++) {
+                       /* we can only exit if no parens or user tracks them */
+                        if (c == *d && lc != '\\' && (p == 0 || par)) {
+                               goto tokenread;
+                        }
+               }
+
+               i++;
+               if (limit > 0 && (i >= limit || (size_t)(t-token) >= limit)) {
+                       *t = '\0';
+                       return -1;
+               }
+               *t++ = c;
+
+               if (c == '\\' && lc == '\\') {
+                       lc = 0;
+               } else {
+                       lc = c;
+               }
+       }
+       *t = '\0';
+       if (i == 0) {
+               /* nothing read */
+               return -1;
+       }
+       if (!par && p != 0) {
+               return -1;
+       }
+       return (ssize_t)i;
+
+tokenread:
+       ldns_bskipcs(b, del);
+       *t = '\0';
+
+       if (!par && p != 0) {
+               return -1;
+       }
+       return (ssize_t)i;
+}
+
+
+void
+ldns_bskipcs(ldns_buffer *buffer, const char *s)
+{
+        int found;
+        char c;
+        const char *d;
+
+        while(ldns_buffer_available_at(buffer, buffer->_position, sizeof(char))) {
+                c = (char) ldns_buffer_read_u8_at(buffer, buffer->_position);
+                found = 0;
+                for (d = s; *d; d++) {
+                        if (*d == c) {
+                                found = 1;
+                        }
+                }
+                if (found && buffer->_limit > buffer->_position) {
+                        buffer->_position += sizeof(char);
+                } else {
+                        return;
+                }
+        }
+}
+
+void
+ldns_fskipcs(FILE *fp, const char *s)
+{
+       ldns_fskipcs_l(fp, s, NULL);
+}
+
+void
+ldns_fskipcs_l(FILE *fp, const char *s, int *line_nr)
+{
+        int found;
+        int c;
+        const char *d;
+
+       while ((c = fgetc(fp)) != EOF) {
+               if (line_nr && c == '\n') {
+                       *line_nr = *line_nr + 1;
+               }
+                found = 0;
+                for (d = s; *d; d++) {
+                        if (*d == c) {
+                                found = 1;
+                        }
+                }
+               if (!found) {
+                       /* with getc, we've read too far */
+                       ungetc(c, fp);
+                       return;
+               }
+       }
+}
+
+ssize_t
+ldns_bget_keyword_data(ldns_buffer *b, const char *keyword, const char *k_del, char
+*data, const char *d_del, size_t data_limit)
+{
+       /* we assume: keyword|sep|data */
+       char *fkeyword;
+       ssize_t i;
+
+       if(strlen(keyword) >= LDNS_MAX_KEYWORDLEN)
+               return -1;
+       fkeyword = (char*)malloc(LDNS_MAX_KEYWORDLEN);
+       if(!fkeyword)
+               return -1; /* out of memory */
+
+       i = ldns_bget_token(b, fkeyword, k_del, data_limit);
+       if(i==0 || i==-1) {
+               free(fkeyword);
+               return -1; /* nothing read */
+       }
+
+       /* case??? */
+       if (strncmp(fkeyword, keyword, strlen(keyword)) == 0) {
+               free(fkeyword);
+               /* whee, the match! */
+               /* retrieve it's data */
+               i = ldns_bget_token(b, data, d_del, 0);
+               return i;
+       } else {
+               free(fkeyword);
+               return -1;
+       }
+}
+
diff --git a/ldns/parse.h b/ldns/parse.h
new file mode 100644 (file)
index 0000000..1ddd013
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * parse.h 
+ *
+ * a Net::DNS like library for C
+ * LibDNS Team @ NLnet Labs
+ * (c) NLnet Labs, 2005-2006
+ * See the file LICENSE for the license
+ */
+
+#ifndef LDNS_PARSE_H
+#define LDNS_PARSE_H
+
+struct ldns_buffer;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LDNS_PARSE_SKIP_SPACE          "\f\n\r\v"
+#define LDNS_PARSE_NORMAL              " \f\n\r\t\v"
+#define LDNS_PARSE_NO_NL               " \t"
+#define LDNS_MAX_LINELEN               10230
+#define LDNS_MAX_KEYWORDLEN            32
+
+
+/**
+ * \file
+ *
+ * Contains some low-level parsing functions, mostly used in the _frm_str
+ * family of functions.
+ */
+/**
+ * different type of directives in zone files
+ * We now deal with $TTL, $ORIGIN and $INCLUDE.
+ * The latter is not implemented in ldns (yet)
+ */
+enum ldns_enum_directive
+{
+       LDNS_DIR_TTL,
+       LDNS_DIR_ORIGIN,
+       LDNS_DIR_INCLUDE
+};
+typedef enum ldns_enum_directive ldns_directive;
+
+/** 
+ * returns a token/char from the stream F.
+ * This function deals with ( and ) in the stream,
+ * and ignores them when encountered
+ * \param[in] *f the file to read from
+ * \param[out] *token the read token is put here
+ * \param[in] *delim chars at which the parsing should stop
+ * \param[in] *limit how much to read. If 0 the builtin maximum is used
+ * \return 0 on error of EOF of the stream F.  Otherwise return the length of what is read
+ */
+ssize_t ldns_fget_token(FILE *f, char *token, const char *delim, size_t limit);
+
+/** 
+ * returns a token/char from the stream F.
+ * This function deals with ( and ) in the stream,
+ * and ignores when it finds them.
+ * \param[in] *f the file to read from
+ * \param[out] *token the token is put here
+ * \param[in] *delim chars at which the parsing should stop
+ * \param[in] *limit how much to read. If 0 use builtin maximum
+ * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
+ * \return 0 on error of EOF of F otherwise return the length of what is read
+ */
+ssize_t ldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *line_nr);
+
+/**
+ * returns a token/char from the buffer b.
+ * This function deals with ( and ) in the buffer,
+ * and ignores when it finds them.
+ * \param[in] *b the buffer to read from
+ * \param[out] *token the token is put here
+ * \param[in] *delim chars at which the parsing should stop
+ * \param[in] *limit how much to read. If 0 the builtin maximum is used
+ * \param[in] *par if you pass nonNULL, set to 0 on first call, the parenthesis
+ * state is stored in it, for use on next call.  User must check it is back
+ * to zero after last bget in string (for parse error).  If you pass NULL,
+ * the entire parenthesized string is read in.
+ * \param[in] skipw string with whitespace to skip before the start of the
+ * token, like " ", or " \t", or NULL for none.  
+ * \returns 0 on error of EOF of b. Otherwise return the length of what is read
+ */
+ssize_t ldns_bget_token_par(struct ldns_buffer *b, char *token, const char *delim, size_t limit, int* par, const char* skipw);
+
+/**
+ * returns a token/char from the buffer b.
+ * This function deals with ( and ) in the buffer,
+ * and ignores when it finds them.
+ * \param[in] *b the buffer to read from
+ * \param[out] *token the token is put here
+ * \param[in] *delim chars at which the parsing should stop
+ * \param[in] *limit how much to read. If 0 the builtin maximum is used
+ * \returns 0 on error of EOF of b. Otherwise return the length of what is read
+ */
+ssize_t ldns_bget_token(struct ldns_buffer *b, char *token, const char *delim, size_t limit);
+
+/*
+ * searches for keyword and delim in a file. Gives everything back
+ * after the keyword + k_del until we hit d_del
+ * \param[in] f file pointer to read from
+ * \param[in] keyword keyword to look for
+ * \param[in] k_del keyword delimeter 
+ * \param[out] data the data found 
+ * \param[in] d_del the data delimeter
+ * \param[in] data_limit maximum size the the data buffer
+ * \return the number of character read
+ */
+ssize_t ldns_fget_keyword_data(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit);
+
+/*
+ * searches for keyword and delim. Gives everything back
+ * after the keyword + k_del until we hit d_del
+ * \param[in] f file pointer to read from
+ * \param[in] keyword keyword to look for
+ * \param[in] k_del keyword delimeter 
+ * \param[out] data the data found 
+ * \param[in] d_del the data delimeter
+ * \param[in] data_limit maximum size the the data buffer
+ * \param[in] line_nr pointer to an integer containing the current line number (for
+debugging purposes)
+ * \return the number of character read
+ */
+ssize_t ldns_fget_keyword_data_l(FILE *f, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit, int *line_nr);
+
+/*
+ * searches for keyword and delim in a buffer. Gives everything back
+ * after the keyword + k_del until we hit d_del
+ * \param[in] b buffer pointer to read from
+ * \param[in] keyword keyword to look for
+ * \param[in] k_del keyword delimeter 
+ * \param[out] data the data found 
+ * \param[in] d_del the data delimeter
+ * \param[in] data_limit maximum size the the data buffer
+ * \return the number of character read
+ */
+ssize_t ldns_bget_keyword_data(struct ldns_buffer *b, const char *keyword, const char *k_del, char *data, const char *d_del, size_t data_limit);
+
+/**
+ * returns the next character from a buffer. Advances the position pointer with 1.
+ * When end of buffer is reached returns EOF. This is the buffer's equivalent
+ * for getc().
+ * \param[in] *buffer buffer to read from
+ * \return EOF on failure otherwise return the character
+ */
+int ldns_bgetc(struct ldns_buffer *buffer);
+
+/**
+ * skips all of the characters in the given string in the buffer, moving
+ * the position to the first character that is not in *s.
+ * \param[in] *buffer buffer to use
+ * \param[in] *s characters to skip
+ * \return void
+ */
+void ldns_bskipcs(struct ldns_buffer *buffer, const char *s);
+
+/**
+ * skips all of the characters in the given string in the fp, moving
+ * the position to the first character that is not in *s.
+ * \param[in] *fp file to use
+ * \param[in] *s characters to skip
+ * \return void
+ */
+void ldns_fskipcs(FILE *fp, const char *s);
+
+
+/**
+ * skips all of the characters in the given string in the fp, moving
+ * the position to the first character that is not in *s.
+ * \param[in] *fp file to use
+ * \param[in] *s characters to skip
+ * \param[in] line_nr pointer to an integer containing the current line number (for debugging purposes)
+ * \return void
+ */
+void ldns_fskipcs_l(FILE *fp, const char *s, int *line_nr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LDNS_PARSE_H */
diff --git a/ldns/parseutil.c b/ldns/parseutil.c
new file mode 100644 (file)
index 0000000..61fa638
--- /dev/null
@@ -0,0 +1,726 @@
+/*
+ * parseutil.c - parse utilities for string and wire conversion
+ *
+ * (c) NLnet Labs, 2004-2006
+ *
+ * See the file LICENSE for the license
+ */
+/**
+ * \file
+ *
+ * Utility functions for parsing, base32(DNS variant) and base64 encoding
+ * and decoding, Hex, Time units, Escape codes.
+ */
+
+#include "config.h"
+#include "ldns/parseutil.h"
+#include <sys/time.h>
+#include <time.h>
+#include <ctype.h>
+
+ldns_lookup_table *
+ldns_lookup_by_name(ldns_lookup_table *table, const char *name)
+{
+        while (table->name != NULL) {
+                if (strcasecmp(name, table->name) == 0)
+                        return table;
+                table++;
+        }
+        return NULL;
+}
+
+ldns_lookup_table *
+ldns_lookup_by_id(ldns_lookup_table *table, int id)
+{
+        while (table->name != NULL) {
+                if (table->id == id)
+                        return table;
+                table++;
+        }
+        return NULL;
+}
+
+/* Number of days per month (except for February in leap years). */
+static const int mdays[] = {
+       31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
+};
+
+#define LDNS_MOD(x,y) (((x) % (y) < 0) ? ((x) % (y) + (y)) : ((x) % (y)))
+#define LDNS_DIV(x,y) (((x) % (y) < 0) ? ((x) / (y) -  1 ) : ((x) / (y)))
+
+static int
+is_leap_year(int year)
+{
+       return LDNS_MOD(year,   4) == 0 && (LDNS_MOD(year, 100) != 0 
+           || LDNS_MOD(year, 400) == 0);
+}
+
+static int
+leap_days(int y1, int y2)
+{
+       --y1;
+       --y2;
+       return (LDNS_DIV(y2,   4) - LDNS_DIV(y1,   4)) - 
+              (LDNS_DIV(y2, 100) - LDNS_DIV(y1, 100)) +
+              (LDNS_DIV(y2, 400) - LDNS_DIV(y1, 400));
+}
+
+/*
+ * Code adapted from Python 2.4.1 sources (Lib/calendar.py).
+ */
+time_t
+ldns_mktime_from_utc(const struct tm *tm)
+{
+       int year = 1900 + tm->tm_year;
+       time_t days = 365 * ((time_t) year - 1970) + leap_days(1970, year);
+       time_t hours;
+       time_t minutes;
+       time_t seconds;
+       int i;
+
+       for (i = 0; i < tm->tm_mon; ++i) {
+               days += mdays[i];
+       }
+       if (tm->tm_mon > 1 && is_leap_year(year)) {
+               ++days;
+       }
+       days += tm->tm_mday - 1;
+
+       hours = days * 24 + tm->tm_hour;
+       minutes = hours * 60 + tm->tm_min;
+       seconds = minutes * 60 + tm->tm_sec;
+
+       return seconds;
+}
+
+#if SIZEOF_TIME_T <= 4
+
+static void
+ldns_year_and_yday_from_days_since_epoch(int64_t days, struct tm *result)
+{
+       int year = 1970;
+       int new_year;
+
+       while (days < 0 || days >= (int64_t) (is_leap_year(year) ? 366 : 365)) {
+               new_year = year + (int) LDNS_DIV(days, 365);
+               days -= (new_year - year) * 365;
+               days -= leap_days(year, new_year);
+               year  = new_year;
+       }
+       result->tm_year = year;
+       result->tm_yday = (int) days;
+}
+
+/* Number of days per month in a leap year. */
+static const int leap_year_mdays[] = {
+       31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
+};
+
+static void
+ldns_mon_and_mday_from_year_and_yday(struct tm *result)
+{
+       int idays = result->tm_yday;
+       const int *mon_lengths = is_leap_year(result->tm_year) ? 
+                                       leap_year_mdays : mdays;
+
+       result->tm_mon = 0;
+       while  (idays >= mon_lengths[result->tm_mon]) {
+               idays -= mon_lengths[result->tm_mon++];
+       }
+       result->tm_mday = idays + 1;
+}
+
+static void
+ldns_wday_from_year_and_yday(struct tm *result)
+{
+       result->tm_wday = 4 /* 1-1-1970 was a thursday */
+                       + LDNS_MOD((result->tm_year - 1970), 7) * LDNS_MOD(365, 7)
+                       + leap_days(1970, result->tm_year)
+                       + result->tm_yday;
+       result->tm_wday = LDNS_MOD(result->tm_wday, 7);
+       if (result->tm_wday < 0) {
+               result->tm_wday += 7;
+       }
+}
+
+static struct tm *
+ldns_gmtime64_r(int64_t clock, struct tm *result)
+{
+       result->tm_isdst = 0;
+       result->tm_sec   = (int) LDNS_MOD(clock, 60);
+       clock            =       LDNS_DIV(clock, 60);
+       result->tm_min   = (int) LDNS_MOD(clock, 60);
+       clock            =       LDNS_DIV(clock, 60);
+       result->tm_hour  = (int) LDNS_MOD(clock, 24);
+       clock            =       LDNS_DIV(clock, 24);
+
+       ldns_year_and_yday_from_days_since_epoch(clock, result);
+       ldns_mon_and_mday_from_year_and_yday(result);
+       ldns_wday_from_year_and_yday(result);
+       result->tm_year -= 1900;
+
+       return result;
+}
+
+#endif /* SIZEOF_TIME_T <= 4 */
+
+static int64_t
+ldns_serial_arithmitics_time(int32_t time, time_t now)
+{
+       int32_t offset = time - (int32_t) now;
+       return (int64_t) now + offset;
+}
+
+struct tm *
+ldns_serial_arithmitics_gmtime_r(int32_t time, time_t now, struct tm *result)
+{
+#if SIZEOF_TIME_T <= 4
+       int64_t secs_since_epoch = ldns_serial_arithmitics_time(time, now);
+       return  ldns_gmtime64_r(secs_since_epoch, result);
+#else
+       time_t  secs_since_epoch = ldns_serial_arithmitics_time(time, now);
+       return  gmtime_r(&secs_since_epoch, result);
+#endif
+}
+
+int
+ldns_hexdigit_to_int(char ch)
+{
+       switch (ch) {
+       case '0': return 0;
+       case '1': return 1;
+       case '2': return 2;
+       case '3': return 3;
+       case '4': return 4;
+       case '5': return 5;
+       case '6': return 6;
+       case '7': return 7;
+       case '8': return 8;
+       case '9': return 9;
+       case 'a': case 'A': return 10;
+       case 'b': case 'B': return 11;
+       case 'c': case 'C': return 12;
+       case 'd': case 'D': return 13;
+       case 'e': case 'E': return 14;
+       case 'f': case 'F': return 15;
+       default:
+               return -1;
+       }
+}
+
+uint32_t
+ldns_str2period(const char *nptr, const char **endptr)
+{
+       int sign = 0;
+       uint32_t i = 0;
+       uint32_t seconds = 0;
+
+       for(*endptr = nptr; **endptr; (*endptr)++) {
+               switch (**endptr) {
+                       case ' ':
+                       case '\t':
+                               break;
+                       case '-':
+                               if(sign == 0) {
+                                       sign = -1;
+                               } else {
+                                       return seconds;
+                               }
+                               break;
+                       case '+':
+                               if(sign == 0) {
+                                       sign = 1;
+                               } else {
+                                       return seconds;
+                               }
+                               break;
+                       case 's':
+                       case 'S':
+                               seconds += i;
+                               i = 0;
+                               break;
+                       case 'm':
+                       case 'M':
+                               seconds += i * 60;
+                               i = 0;
+                               break;
+                       case 'h':
+                       case 'H':
+                               seconds += i * 60 * 60;
+                               i = 0;
+                               break;
+                       case 'd':
+                       case 'D':
+                               seconds += i * 60 * 60 * 24;
+                               i = 0;
+                               break;
+                       case 'w':
+                       case 'W':
+                               seconds += i * 60 * 60 * 24 * 7;
+                               i = 0;
+                               break;
+                       case '0':
+                       case '1':
+                       case '2':
+                       case '3':
+                       case '4':
+                       case '5':
+                       case '6':
+                       case '7':
+                       case '8':
+                       case '9':
+                               i *= 10;
+                               i += (**endptr - '0');
+                               break;
+                       default:
+                               seconds += i;
+                               /* disregard signedness */
+                               return seconds;
+               }
+       }
+       seconds += i;
+       /* disregard signedness */
+       return seconds;
+}
+
+int
+ldns_parse_escape(uint8_t *ch_p, const char** str_p)
+{
+       uint16_t val;
+
+       if ((*str_p)[0] && isdigit((*str_p)[0])  &&
+           (*str_p)[1] && isdigit((*str_p)[1])  &&
+           (*str_p)[2] && isdigit((*str_p)[2]))  {
+
+               val = (uint16_t)(((*str_p)[0] - '0') * 100 +
+                                ((*str_p)[1] - '0') *  10 +
+                                ((*str_p)[2] - '0'));
+
+               if (val > 255) {
+                       goto error;
+               }
+               *ch_p = (uint8_t)val;
+               *str_p += 3;
+               return 1;
+
+       } else if ((*str_p)[0] && !isdigit((*str_p)[0])) {
+
+               *ch_p = (uint8_t)*(*str_p)++;
+               return 1;
+       }
+error:
+       *str_p = NULL;
+       return 0; /* LDNS_WIREPARSE_ERR_SYNTAX_BAD_ESCAPE */
+}
+
+/** parse one character, with escape codes */
+int
+ldns_parse_char(uint8_t *ch_p, const char** str_p)
+{
+       switch (**str_p) {
+
+       case '\0':      return 0;
+
+       case '\\':      *str_p += 1;
+                       return ldns_parse_escape(ch_p, str_p);
+
+       default:        *ch_p = (uint8_t)*(*str_p)++;
+                       return 1;
+       }
+}
+
+size_t ldns_b32_ntop_calculate_size(size_t src_data_length)
+{
+       return src_data_length == 0 ? 0 : ((src_data_length - 1) / 5 + 1) * 8;
+}
+
+size_t ldns_b32_ntop_calculate_size_no_padding(size_t src_data_length)
+{
+       return ((src_data_length + 3) * 8 / 5) - 4;
+}
+
+static int
+ldns_b32_ntop_base(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz,
+       int extended_hex, int add_padding)
+{
+       size_t ret_sz;
+       const char* b32 = extended_hex ?  "0123456789abcdefghijklmnopqrstuv"
+                                       : "abcdefghijklmnopqrstuvwxyz234567";
+
+       size_t c = 0; /* c is used to carry partial base32 character over 
+                      * byte boundaries for sizes with a remainder.
+                      * (i.e. src_sz % 5 != 0)
+                      */
+
+       ret_sz = add_padding ? ldns_b32_ntop_calculate_size(src_sz)
+                            : ldns_b32_ntop_calculate_size_no_padding(src_sz);
+       
+       /* Do we have enough space? */
+       if (dst_sz < ret_sz + 1)
+               return -1;
+
+       /* We know the size; terminate the string */
+       dst[ret_sz] = '\0';
+
+       /* First process all chunks of five */
+       while (src_sz >= 5) {
+               /* 00000... ........ ........ ........ ........ */
+               dst[0] = b32[(src[0]       ) >> 3];
+
+               /* .....111 11...... ........ ........ ........ */
+               dst[1] = b32[(src[0] & 0x07) << 2 | src[1] >> 6];
+
+               /* ........ ..22222. ........ ........ ........ */
+               dst[2] = b32[(src[1] & 0x3e) >> 1];
+
+               /* ........ .......3 3333.... ........ ........ */
+               dst[3] = b32[(src[1] & 0x01) << 4 | src[2] >> 4];
+
+               /* ........ ........ ....4444 4....... ........ */
+               dst[4] = b32[(src[2] & 0x0f) << 1 | src[3] >> 7];
+
+               /* ........ ........ ........ .55555.. ........ */
+               dst[5] = b32[(src[3] & 0x7c) >> 2];
+
+               /* ........ ........ ........ ......66 666..... */
+               dst[6] = b32[(src[3] & 0x03) << 3 | src[4] >> 5];
+
+               /* ........ ........ ........ ........ ...77777 */
+               dst[7] = b32[(src[4] & 0x1f)     ];
+
+               src_sz -= 5;
+               src    += 5;
+               dst    += 8;
+       }
+       /* Process what remains */
+       switch (src_sz) {
+       case 4: /* ........ ........ ........ ......66 666..... */
+               dst[6] = b32[(src[3] & 0x03) << 3];
+
+               /* ........ ........ ........ .55555.. ........ */
+               dst[5] = b32[(src[3] & 0x7c) >> 2];
+
+               /* ........ ........ ....4444 4....... ........ */
+                        c =  src[3]         >> 7 ;
+       case 3: dst[4] = b32[(src[2] & 0x0f) << 1 | c];
+
+               /* ........ .......3 3333.... ........ ........ */
+                        c =  src[2]         >> 4 ;
+       case 2: dst[3] = b32[(src[1] & 0x01) << 4 | c];
+
+               /* ........ ..22222. ........ ........ ........ */
+               dst[2] = b32[(src[1] & 0x3e) >> 1];
+
+               /* .....111 11...... ........ ........ ........ */
+                        c =  src[1]         >> 6 ;
+       case 1: dst[1] = b32[(src[0] & 0x07) << 2 | c];
+
+               /* 00000... ........ ........ ........ ........ */
+               dst[0] = b32[ src[0]         >> 3];
+       }
+       /* Add padding */
+       if (add_padding) {
+               switch (src_sz) {
+                       case 1: dst[2] = '=';
+                               dst[3] = '=';
+                       case 2: dst[4] = '=';
+                       case 3: dst[5] = '=';
+                               dst[6] = '=';
+                       case 4: dst[7] = '=';
+               }
+       }
+       return (int)ret_sz;
+}
+
+int 
+ldns_b32_ntop(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz)
+{
+       return ldns_b32_ntop_base(src, src_sz, dst, dst_sz, 0, 1);
+}
+
+int 
+ldns_b32_ntop_extended_hex(const uint8_t* src, size_t src_sz,
+               char* dst, size_t dst_sz)
+{
+       return ldns_b32_ntop_base(src, src_sz, dst, dst_sz, 1, 1);
+}
+
+size_t ldns_b32_pton_calculate_size(size_t src_text_length)
+{
+       return src_text_length * 5 / 8;
+}
+
+static int
+ldns_b32_pton_base(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz,
+       int extended_hex, int check_padding)
+{
+       size_t i = 0;
+       char ch = '\0';
+       uint8_t buf[8];
+       uint8_t* start = dst;
+
+       while (src_sz) {
+               /* Collect 8 characters in buf (if possible) */
+               for (i = 0; i < 8; i++) {
+
+                       do {
+                               ch = *src++;
+                               --src_sz;
+
+                       } while (isspace(ch) && src_sz > 0);
+
+                       if (ch == '=' || ch == '\0')
+                               break;
+
+                       else if (extended_hex)
+
+                               if (ch >= '0' && ch <= '9')
+                                       buf[i] = (uint8_t)ch - '0';
+                               else if (ch >= 'a' && ch <= 'v')
+                                       buf[i] = (uint8_t)ch - 'a' + 10;
+                               else if (ch >= 'A' && ch <= 'V')
+                                       buf[i] = (uint8_t)ch - 'A' + 10;
+                               else
+                                       return -1;
+
+                       else if (ch >= 'a' && ch <= 'z')
+                               buf[i] = (uint8_t)ch - 'a';
+                       else if (ch >= 'A' && ch <= 'Z')
+                               buf[i] = (uint8_t)ch - 'A';
+                       else if (ch >= '2' && ch <= '7')
+                               buf[i] = (uint8_t)ch - '2' + 26;
+                       else
+                               return -1;
+               }
+               /* Less that 8 characters. We're done. */
+               if (i < 8)
+                       break;
+
+               /* Enough space available at the destination? */
+               if (dst_sz < 5)
+                       return -1;
+
+               /* 00000... ........ ........ ........ ........ */
+               /* .....111 11...... ........ ........ ........ */
+               dst[0] = buf[0] << 3 | buf[1] >> 2;
+
+               /* .....111 11...... ........ ........ ........ */
+               /* ........ ..22222. ........ ........ ........ */
+               /* ........ .......3 3333.... ........ ........ */
+               dst[1] = buf[1] << 6 | buf[2] << 1 | buf[3] >> 4;
+
+               /* ........ .......3 3333.... ........ ........ */
+               /* ........ ........ ....4444 4....... ........ */
+               dst[2] = buf[3] << 4 | buf[4] >> 1;
+
+               /* ........ ........ ....4444 4....... ........ */
+               /* ........ ........ ........ .55555.. ........ */
+               /* ........ ........ ........ ......66 666..... */
+               dst[3] = buf[4] << 7 | buf[5] << 2 | buf[6] >> 3;
+
+               /* ........ ........ ........ ......66 666..... */
+               /* ........ ........ ........ ........ ...77777 */
+               dst[4] = buf[6] << 5 | buf[7];
+
+               dst += 5;
+               dst_sz -= 5;
+       }
+       /* Not ending on a eight byte boundary? */
+       if (i > 0 && i < 8) {
+
+               /* Enough space available at the destination? */
+               if (dst_sz < (i + 1) / 2)
+                       return -1;
+
+               switch (i) {
+               case 7: /* ........ ........ ........ ......66 666..... */
+                       /* ........ ........ ........ .55555.. ........ */
+                       /* ........ ........ ....4444 4....... ........ */
+                       dst[3] = buf[4] << 7 | buf[5] << 2 | buf[6] >> 3;
+
+               case 5: /* ........ ........ ....4444 4....... ........ */
+                       /* ........ .......3 3333.... ........ ........ */
+                       dst[2] = buf[3] << 4 | buf[4] >> 1;
+
+               case 4: /* ........ .......3 3333.... ........ ........ */
+                       /* ........ ..22222. ........ ........ ........ */
+                       /* .....111 11...... ........ ........ ........ */
+                       dst[1] = buf[1] << 6 | buf[2] << 1 | buf[3] >> 4;
+
+               case 2: /* .....111 11...... ........ ........ ........ */
+                       /* 00000... ........ ........ ........ ........ */
+                       dst[0] = buf[0] << 3 | buf[1] >> 2;
+
+                       break;
+
+               default:
+                       return -1;
+               }
+               dst += (i + 1) / 2;
+
+               if (check_padding) {
+                       /* Check remaining padding characters */
+                       if (ch != '=')
+                               return -1;
+
+                       /* One down, 8 - i - 1 more to come... */
+                       for (i = 8 - i - 1; i > 0; i--) {
+
+                               do {
+                                       if (src_sz == 0)
+                                               return -1;
+                                       ch = *src++;
+                                       src_sz--;
+
+                               } while (isspace(ch));
+
+                               if (ch != '=')
+                                       return -1;
+                       }
+               }
+       }
+       return dst - start;
+}
+
+int
+ldns_b32_pton(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz)
+{
+       return ldns_b32_pton_base(src, src_sz, dst, dst_sz, 0, 1);
+}
+
+int
+ldns_b32_pton_extended_hex(const char* src, size_t src_sz, 
+               uint8_t* dst, size_t dst_sz)
+{
+       return ldns_b32_pton_base(src, src_sz, dst, dst_sz, 1, 1);
+}
+
+size_t ldns_b64_ntop_calculate_size(size_t srcsize)
+{
+       return ((((srcsize + 2) / 3) * 4) + 1);
+}
+
+/* RFC 1521, section 5.2.
+ *
+ * The encoding process represents 24-bit groups of input bits as output
+ * strings of 4 encoded characters. Proceeding from left to right, a
+ * 24-bit input group is formed by concatenating 3 8-bit input groups.
+ * These 24 bits are then treated as 4 concatenated 6-bit groups, each
+ * of which is translated into a single digit in the base64 alphabet.
+ *
+ * This routine does not insert spaces or linebreaks after 76 characters.
+ */
+int ldns_b64_ntop(uint8_t const *src, size_t srclength,
+       char *target, size_t targsize)
+{
+       const char* b64 =
+       "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+       const char pad64 = '=';
+       size_t i = 0, o = 0;
+       if(targsize < ldns_b64_ntop_calculate_size(srclength))
+               return -1;
+       /* whole chunks: xxxxxxyy yyyyzzzz zzwwwwww */
+       while(i+3 <= srclength) {
+               if(o+4 > targsize) return -1;
+               target[o] = b64[src[i] >> 2];
+               target[o+1] = b64[ ((src[i]&0x03)<<4) | (src[i+1]>>4) ];
+               target[o+2] = b64[ ((src[i+1]&0x0f)<<2) | (src[i+2]>>6) ];
+               target[o+3] = b64[ (src[i+2]&0x3f) ];
+               i += 3;
+               o += 4;
+       }
+       /* remainder */
+       switch(srclength - i) {
+       case 2:
+               /* two at end, converted into A B C = */
+               target[o] = b64[src[i] >> 2];
+               target[o+1] = b64[ ((src[i]&0x03)<<4) | (src[i+1]>>4) ];
+               target[o+2] = b64[ ((src[i+1]&0x0f)<<2) ];
+               target[o+3] = pad64;
+               i += 2;
+               o += 4;
+               break;
+       case 1:
+               /* one at end, converted into A B = = */
+               target[o] = b64[src[i] >> 2];
+               target[o+1] = b64[ ((src[i]&0x03)<<4) ];
+               target[o+2] = pad64;
+               target[o+3] = pad64;
+               i += 1;
+               o += 4;
+               break;
+       case 0:
+       default:
+               /* nothing */
+               break;
+       }
+       /* assert: i == srclength */
+       if(o+1 > targsize) return -1;
+       target[o] = 0;
+       return (int)o;
+}
+
+size_t ldns_b64_pton_calculate_size(size_t srcsize)
+{
+       return (((((srcsize + 3) / 4) * 3)) + 1);
+}
+
+int ldns_b64_pton(char const *src, uint8_t *target, size_t targsize)
+{
+       const uint8_t pad64 = 64; /* is 64th in the b64 array */
+       const char* s = src;
+       uint8_t in[4];
+       size_t o = 0, incount = 0;
+
+       while(*s) {
+               /* skip any character that is not base64 */
+               /* conceptually we do:
+               const char* b64 =      pad'=' is appended to array
+               "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+               const char* d = strchr(b64, *s++);
+               and use d-b64;
+               */
+               char d = *s++;
+               if(d <= 'Z' && d >= 'A')
+                       d -= 'A';
+               else if(d <= 'z' && d >= 'a')
+                       d = d - 'a' + 26;
+               else if(d <= '9' && d >= '0')
+                       d = d - '0' + 52;
+               else if(d == '+')
+                       d = 62;
+               else if(d == '/')
+                       d = 63;
+               else if(d == '=')
+                       d = 64;
+               else    continue;
+               in[incount++] = (uint8_t)d;
+               if(incount != 4)
+                       continue;
+               /* process whole block of 4 characters into 3 output bytes */
+               if(in[3] == pad64 && in[2] == pad64) { /* A B = = */
+                       if(o+1 > targsize)
+                               return -1;
+                       target[o] = (in[0]<<2) | ((in[1]&0x30)>>4);
+                       o += 1;
+                       break; /* we are done */
+               } else if(in[3] == pad64) { /* A B C = */
+                       if(o+2 > targsize)
+                               return -1;
+                       target[o] = (in[0]<<2) | ((in[1]&0x30)>>4);
+                       target[o+1]= ((in[1]&0x0f)<<4) | ((in[2]&0x3c)>>2);
+                       o += 2;
+                       break; /* we are done */
+               } else {
+                       if(o+3 > targsize)
+                               return -1;
+                       /* write xxxxxxyy yyyyzzzz zzwwwwww */
+                       target[o] = (in[0]<<2) | ((in[1]&0x30)>>4);
+                       target[o+1]= ((in[1]&0x0f)<<4) | ((in[2]&0x3c)>>2);
+                       target[o+2]= ((in[2]&0x03)<<6) | in[3];
+                       o += 3;
+               }
+               incount = 0;
+       }
+       return (int)o;
+}
diff --git a/ldns/parseutil.h b/ldns/parseutil.h
new file mode 100644 (file)
index 0000000..9808ef3
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * parseutil.h - parse utilities for string and wire conversion
+ *
+ * (c) NLnet Labs, 2004
+ *
+ * See the file LICENSE for the license
+ */
+/**
+ * \file
+ *
+ * Utility functions for parsing, base32(DNS variant) and base64 encoding
+ * and decoding, Hex, Time units, Escape codes.
+ */
+
+#ifndef LDNS_PARSEUTIL_H
+#define LDNS_PARSEUTIL_H
+struct tm;
+
+/** 
+ *  A general purpose lookup table
+ *  
+ *  Lookup tables are arrays of (id, name) pairs,
+ *  So you can for instance lookup the RCODE 3, which is "NXDOMAIN",
+ *  and vice versa. The lookup tables themselves are defined wherever needed,
+ *  for instance in host2str.c
+ */
+struct ldns_struct_lookup_table {
+        int id;
+        const char *name;
+};
+typedef struct ldns_struct_lookup_table ldns_lookup_table;
+
+/**
+ * Looks up the table entry by name, returns NULL if not found.
+ * \param[in] table the lookup table to search in
+ * \param[in] name what to search for
+ * \return the item found
+ */
+ldns_lookup_table *ldns_lookup_by_name(ldns_lookup_table table[],
+                                       const char *name);
+/**
+ * Looks up the table entry by id, returns NULL if not found.
+ * \param[in] table the lookup table to search in
+ * \param[in] id what to search for
+ * \return the item found
+ */
+ldns_lookup_table *ldns_lookup_by_id(ldns_lookup_table table[], int id);
+
+/**
+ * Convert TM to seconds since epoch (midnight, January 1st, 1970).
+ * Like timegm(3), which is not always available.
+ * \param[in] tm a struct tm* with the date
+ * \return the seconds since epoch
+ */
+time_t ldns_mktime_from_utc(const struct tm *tm);
+
+/**
+ * The function interprets time as the number of seconds since epoch
+ * with respect to now using serial arithmitics (rfc1982).
+ * That number of seconds is then converted to broken-out time information.
+ * This is especially usefull when converting the inception and expiration
+ * fields of RRSIG records.
+ *
+ * \param[in] time number of seconds since epoch (midnight, January 1st, 1970)
+ *            to be intepreted as a serial arithmitics number relative to now.
+ * \param[in] now number of seconds since epoch (midnight, January 1st, 1970)
+ *            to which the time value is compared to determine the final value.
+ * \param[out] result the struct with the broken-out time information
+ * \return result on success or NULL on error
+ */
+struct tm * ldns_serial_arithmitics_gmtime_r(int32_t time, time_t now, struct tm *result);
+
+/**
+ * converts a ttl value (like 5d2h) to a long.
+ * \param[in] nptr the start of the string
+ * \param[out] endptr points to the last char in case of error
+ * \return the convert duration value
+ */
+uint32_t ldns_str2period(const char *nptr, const char **endptr);
+
+/**
+ * Returns the int value of the given (hex) digit
+ * \param[in] ch the hex char to convert
+ * \return the converted decimal value
+ */
+int ldns_hexdigit_to_int(char ch);
+
+/**
+ * calculates the size needed to store the result of b64_ntop
+ */
+size_t ldns_b64_ntop_calculate_size(size_t srcsize);
+
+int ldns_b64_ntop(uint8_t const *src, size_t srclength,
+       char *target, size_t targsize);
+
+/**
+ * calculates the size needed to store the result of ldns_b64_pton
+ */
+size_t ldns_b64_pton_calculate_size(size_t srcsize);
+
+int ldns_b64_pton(char const *src, uint8_t *target, size_t targsize);
+
+/**
+ * calculates the size needed to store the result of b32_ntop
+ */
+size_t ldns_b32_ntop_calculate_size(size_t src_data_length);
+
+size_t ldns_b32_ntop_calculate_size_no_padding(size_t src_data_length);
+
+int ldns_b32_ntop(const uint8_t* src_data, size_t src_data_length,
+       char* target_text_buffer, size_t target_text_buffer_size);
+
+int ldns_b32_ntop_extended_hex(const uint8_t* src_data, size_t src_data_length,
+       char* target_text_buffer, size_t target_text_buffer_size);
+
+/**
+ * calculates the size needed to store the result of b32_pton
+ */
+size_t ldns_b32_pton_calculate_size(size_t src_text_length);
+
+int ldns_b32_pton(const char* src_text, size_t src_text_length,
+       uint8_t* target_data_buffer, size_t target_data_buffer_size);
+
+int ldns_b32_pton_extended_hex(const char* src_text, size_t src_text_length,
+       uint8_t* target_data_buffer, size_t target_data_buffer_size);
+
+/*
+ * Checks whether the escaped value at **s is an octal value or
+ * a 'normally' escaped character (and not eos)
+ *
+ * @param ch_p: the parsed character
+ * @param str_p: the string. moved along for characters read.
+ * The string pointer at *s is increased by either 0 (on error), 1 (on
+ * normal escapes), or 3 (on octals)
+ *
+ * @return 0 on error
+ */
+int ldns_parse_escape(uint8_t *ch_p, const char** str_p);
+
+/** 
+ * Parse one character, with escape codes,
+ * @param ch_p: the parsed character
+ * @param str_p: the string. moved along for characters read.
+ * @return 0 on error
+ */
+int ldns_parse_char(uint8_t *ch_p, const char** str_p);
+
+#endif /* LDNS_PARSEUTIL_H */
diff --git a/ldns/pkthdr.h b/ldns/pkthdr.h
new file mode 100644 (file)
index 0000000..30177cd
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * pkthdr.h - packet header from wire conversion routines
+ *
+ * a Net::DNS like library for C
+ *
+ * (c) NLnet Labs, 2005-2006
+ *
+ * See the file LICENSE for the license
+ */
+
+/**
+ * \file
+ *
+ * Contains functions that translate dns data from the wire format (as sent
+ * by servers and clients) to the internal structures for the packet header.
+ */
+#ifndef LDNS_PKTHDR_H
+#define LDNS_PKTHDR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* The length of the header */
+#define        LDNS_HEADER_SIZE        12
+
+/* First octet of flags */
+#define        LDNS_RD_MASK            0x01U
+#define        LDNS_RD_SHIFT   0
+#define        LDNS_RD_WIRE(wirebuf)   (*(wirebuf+2) & LDNS_RD_MASK)
+#define        LDNS_RD_SET(wirebuf)    (*(wirebuf+2) |= LDNS_RD_MASK)
+#define        LDNS_RD_CLR(wirebuf)    (*(wirebuf+2) &= ~LDNS_RD_MASK)
+
+#define LDNS_TC_MASK           0x02U
+#define LDNS_TC_SHIFT  1
+#define        LDNS_TC_WIRE(wirebuf)   (*(wirebuf+2) & LDNS_TC_MASK)
+#define        LDNS_TC_SET(wirebuf)    (*(wirebuf+2) |= LDNS_TC_MASK)
+#define        LDNS_TC_CLR(wirebuf)    (*(wirebuf+2) &= ~LDNS_TC_MASK)
+
+#define        LDNS_AA_MASK            0x04U
+#define        LDNS_AA_SHIFT   2
+#define        LDNS_AA_WIRE(wirebuf)   (*(wirebuf+2) & LDNS_AA_MASK)
+#define        LDNS_AA_SET(wirebuf)    (*(wirebuf+2) |= LDNS_AA_MASK)
+#define        LDNS_AA_CLR(wirebuf)    (*(wirebuf+2) &= ~LDNS_AA_MASK)
+
+#define        LDNS_OPCODE_MASK        0x78U
+#define        LDNS_OPCODE_SHIFT       3
+#define        LDNS_OPCODE_WIRE(wirebuf)       ((*(wirebuf+2) & LDNS_OPCODE_MASK) >> LDNS_OPCODE_SHIFT)
+#define        LDNS_OPCODE_SET(wirebuf, opcode) \
+       (*(wirebuf+2) = ((*(wirebuf+2)) & ~LDNS_OPCODE_MASK) | ((opcode) << LDNS_OPCODE_SHIFT))
+
+#define        LDNS_QR_MASK            0x80U
+#define        LDNS_QR_SHIFT   7
+#define        LDNS_QR_WIRE(wirebuf)   (*(wirebuf+2) & LDNS_QR_MASK)
+#define        LDNS_QR_SET(wirebuf)    (*(wirebuf+2) |= LDNS_QR_MASK)
+#define        LDNS_QR_CLR(wirebuf)    (*(wirebuf+2) &= ~LDNS_QR_MASK)
+
+/* Second octet of flags */
+#define        LDNS_RCODE_MASK 0x0fU
+#define        LDNS_RCODE_SHIFT        0
+#define        LDNS_RCODE_WIRE(wirebuf)        (*(wirebuf+3) & LDNS_RCODE_MASK)
+#define        LDNS_RCODE_SET(wirebuf, rcode) \
+       (*(wirebuf+3) = ((*(wirebuf+3)) & ~LDNS_RCODE_MASK) | (rcode))
+
+#define        LDNS_CD_MASK            0x10U
+#define        LDNS_CD_SHIFT   4
+#define        LDNS_CD_WIRE(wirebuf)   (*(wirebuf+3) & LDNS_CD_MASK)
+#define        LDNS_CD_SET(wirebuf)    (*(wirebuf+3) |= LDNS_CD_MASK)
+#define        LDNS_CD_CLR(wirebuf)    (*(wirebuf+3) &= ~LDNS_CD_MASK)
+
+#define        LDNS_AD_MASK            0x20U
+#define        LDNS_AD_SHIFT   5
+#define        LDNS_AD_WIRE(wirebuf)   (*(wirebuf+3) & LDNS_AD_MASK)
+#define        LDNS_AD_SET(wirebuf)    (*(wirebuf+3) |= LDNS_AD_MASK)
+#define        LDNS_AD_CLR(wirebuf)    (*(wirebuf+3) &= ~LDNS_AD_MASK)
+
+#define        LDNS_Z_MASK             0x40U
+#define        LDNS_Z_SHIFT            6
+#define        LDNS_Z_WIRE(wirebuf)    (*(wirebuf+3) & LDNS_Z_MASK)
+#define        LDNS_Z_SET(wirebuf)     (*(wirebuf+3) |= LDNS_Z_MASK)
+#define        LDNS_Z_CLR(wirebuf)     (*(wirebuf+3) &= ~LDNS_Z_MASK)
+
+#define        LDNS_RA_MASK            0x80U
+#define        LDNS_RA_SHIFT   7
+#define        LDNS_RA_WIRE(wirebuf)   (*(wirebuf+3) & LDNS_RA_MASK)
+#define        LDNS_RA_SET(wirebuf)    (*(wirebuf+3) |= LDNS_RA_MASK)
+#define        LDNS_RA_CLR(wirebuf)    (*(wirebuf+3) &= ~LDNS_RA_MASK)
+
+/* Query ID */
+#define        LDNS_ID_WIRE(wirebuf)           (ldns_read_uint16(wirebuf))
+#define        LDNS_ID_SET(wirebuf, id)        (ldns_write_uint16(wirebuf, id))
+
+/* Counter of the question section */
+#define LDNS_QDCOUNT_OFF               4
+/*
+#define        QDCOUNT(wirebuf)                (ntohs(*(uint16_t *)(wirebuf+QDCOUNT_OFF)))
+*/
+#define        LDNS_QDCOUNT(wirebuf)           (ldns_read_uint16(wirebuf+LDNS_QDCOUNT_OFF))
+
+/* Counter of the answer section */
+#define LDNS_ANCOUNT_OFF               6
+#define        LDNS_ANCOUNT(wirebuf)           (ldns_read_uint16(wirebuf+LDNS_ANCOUNT_OFF))
+
+/* Counter of the authority section */
+#define LDNS_NSCOUNT_OFF               8
+#define        LDNS_NSCOUNT(wirebuf)           (ldns_read_uint16(wirebuf+LDNS_NSCOUNT_OFF))
+
+/* Counter of the additional section */
+#define LDNS_ARCOUNT_OFF               10
+#define        LDNS_ARCOUNT(wirebuf)           (ldns_read_uint16(wirebuf+LDNS_ARCOUNT_OFF))
+
+/**
+ * The sections of a packet
+ */
+enum ldns_enum_pkt_section {
+        LDNS_SECTION_QUESTION = 0,
+        LDNS_SECTION_ANSWER = 1,
+        LDNS_SECTION_AUTHORITY = 2,
+        LDNS_SECTION_ADDITIONAL = 3,
+        /** bogus section, if not interested */
+        LDNS_SECTION_ANY = 4,
+        /** used to get all non-question rrs from a packet */
+        LDNS_SECTION_ANY_NOQUESTION = 5
+};
+typedef enum ldns_enum_pkt_section ldns_pkt_section;
+
+/* opcodes for pkt's */
+enum ldns_enum_pkt_opcode {
+        LDNS_PACKET_QUERY = 0,
+        LDNS_PACKET_IQUERY = 1,
+        LDNS_PACKET_STATUS = 2, /* there is no 3?? DNS is weird */
+        LDNS_PACKET_NOTIFY = 4,
+        LDNS_PACKET_UPDATE = 5
+};
+typedef enum ldns_enum_pkt_opcode ldns_pkt_opcode;
+
+/* rcodes for pkts */
+enum ldns_enum_pkt_rcode {
+        LDNS_RCODE_NOERROR = 0,
+        LDNS_RCODE_FORMERR = 1,
+        LDNS_RCODE_SERVFAIL = 2,
+        LDNS_RCODE_NXDOMAIN = 3,
+        LDNS_RCODE_NOTIMPL = 4,
+        LDNS_RCODE_REFUSED = 5,
+        LDNS_RCODE_YXDOMAIN = 6,
+        LDNS_RCODE_YXRRSET = 7,
+        LDNS_RCODE_NXRRSET = 8,
+        LDNS_RCODE_NOTAUTH = 9,
+        LDNS_RCODE_NOTZONE = 10
+};
+typedef enum ldns_enum_pkt_rcode ldns_pkt_rcode;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LDNS_PKTHDR_H */
diff --git a/ldns/rrdef.c b/ldns/rrdef.c
new file mode 100644 (file)
index 0000000..0d4d140
--- /dev/null
@@ -0,0 +1,778 @@
+/* rrdef.c
+ *
+ * access functions to rr definitions list.
+ * a Net::DNS like library for C
+ * LibDNS Team @ NLnet Labs
+ *
+ * (c) NLnet Labs, 2004-2006
+ * See the file LICENSE for the license
+ */
+/**
+ * \file
+ *
+ * Defines resource record types and constants.
+ */
+#include "config.h"
+#include "ldns/rrdef.h"
+#include "ldns/parseutil.h"
+
+/* classes  */
+static ldns_lookup_table ldns_rr_classes_data[] = {
+        { LDNS_RR_CLASS_IN, "IN" },
+        { LDNS_RR_CLASS_CH, "CH" },
+        { LDNS_RR_CLASS_HS, "HS" },
+        { LDNS_RR_CLASS_NONE, "NONE" },
+        { LDNS_RR_CLASS_ANY, "ANY" },
+        { 0, NULL }
+};
+ldns_lookup_table* ldns_rr_classes = ldns_rr_classes_data;
+
+/* types */
+static const ldns_rdf_type type_0_wireformat[] = { LDNS_RDF_TYPE_UNKNOWN };
+static const ldns_rdf_type type_a_wireformat[] = { LDNS_RDF_TYPE_A };
+static const ldns_rdf_type type_ns_wireformat[] = { LDNS_RDF_TYPE_DNAME };
+static const ldns_rdf_type type_md_wireformat[] = { LDNS_RDF_TYPE_DNAME };
+static const ldns_rdf_type type_mf_wireformat[] = { LDNS_RDF_TYPE_DNAME };
+static const ldns_rdf_type type_cname_wireformat[] = { LDNS_RDF_TYPE_DNAME };
+static const ldns_rdf_type type_soa_wireformat[] = {
+       LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_INT32, 
+       LDNS_RDF_TYPE_PERIOD, LDNS_RDF_TYPE_PERIOD, LDNS_RDF_TYPE_PERIOD,
+       LDNS_RDF_TYPE_PERIOD
+};
+static const ldns_rdf_type type_mb_wireformat[] = { LDNS_RDF_TYPE_DNAME };
+static const ldns_rdf_type type_mg_wireformat[] = { LDNS_RDF_TYPE_DNAME };
+static const ldns_rdf_type type_mr_wireformat[] = { LDNS_RDF_TYPE_DNAME };
+static const ldns_rdf_type type_wks_wireformat[] = {
+       LDNS_RDF_TYPE_A, LDNS_RDF_TYPE_WKS
+};
+static const ldns_rdf_type type_ptr_wireformat[] = { LDNS_RDF_TYPE_DNAME };
+static const ldns_rdf_type type_hinfo_wireformat[] = {
+       LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR
+};
+static const ldns_rdf_type type_minfo_wireformat[] = {
+       LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
+};
+static const ldns_rdf_type type_mx_wireformat[] = {
+       LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
+};
+static const ldns_rdf_type type_rp_wireformat[] = {
+       LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
+};
+static const ldns_rdf_type type_afsdb_wireformat[] = {
+       LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
+};
+static const ldns_rdf_type type_x25_wireformat[] = { LDNS_RDF_TYPE_STR };
+static const ldns_rdf_type type_isdn_wireformat[] = {
+       LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR
+};
+static const ldns_rdf_type type_rt_wireformat[] = {
+       LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
+};
+static const ldns_rdf_type type_nsap_wireformat[] = {
+       LDNS_RDF_TYPE_NSAP
+};
+static const ldns_rdf_type type_nsap_ptr_wireformat[] = {
+       LDNS_RDF_TYPE_STR
+};
+static const ldns_rdf_type type_sig_wireformat[] = {
+       LDNS_RDF_TYPE_TYPE, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT32,
+       LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_B64
+};
+static const ldns_rdf_type type_key_wireformat[] = {
+       LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_B64
+};
+static const ldns_rdf_type type_px_wireformat[] = {
+       LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
+};
+static const ldns_rdf_type type_gpos_wireformat[] = {
+       LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR
+};
+static const ldns_rdf_type type_aaaa_wireformat[] = { LDNS_RDF_TYPE_AAAA };
+static const ldns_rdf_type type_loc_wireformat[] = { LDNS_RDF_TYPE_LOC };
+static const ldns_rdf_type type_nxt_wireformat[] = {
+       LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_UNKNOWN
+};
+static const ldns_rdf_type type_eid_wireformat[] = {
+       LDNS_RDF_TYPE_HEX
+};
+static const ldns_rdf_type type_nimloc_wireformat[] = {
+       LDNS_RDF_TYPE_HEX
+};
+static const ldns_rdf_type type_srv_wireformat[] = {
+       LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
+};
+static const ldns_rdf_type type_atma_wireformat[] = {
+       LDNS_RDF_TYPE_ATMA
+};
+static const ldns_rdf_type type_naptr_wireformat[] = {
+       LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_DNAME
+};
+static const ldns_rdf_type type_kx_wireformat[] = {
+       LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
+};
+static const ldns_rdf_type type_cert_wireformat[] = {
+        LDNS_RDF_TYPE_CERT_ALG, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_B64
+};
+static const ldns_rdf_type type_a6_wireformat[] = { LDNS_RDF_TYPE_UNKNOWN };
+static const ldns_rdf_type type_dname_wireformat[] = { LDNS_RDF_TYPE_DNAME };
+static const ldns_rdf_type type_sink_wireformat[] = { LDNS_RDF_TYPE_INT8,
+       LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_B64
+};
+static const ldns_rdf_type type_apl_wireformat[] = {
+       LDNS_RDF_TYPE_APL
+};
+static const ldns_rdf_type type_ds_wireformat[] = {
+       LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_HEX
+};
+static const ldns_rdf_type type_sshfp_wireformat[] = {
+       LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_HEX
+};
+static const ldns_rdf_type type_ipseckey_wireformat[] = {
+       LDNS_RDF_TYPE_IPSECKEY
+};
+static const ldns_rdf_type type_rrsig_wireformat[] = {
+       LDNS_RDF_TYPE_TYPE, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT32,
+       LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_B64
+};
+static const ldns_rdf_type type_nsec_wireformat[] = {
+       LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_NSEC
+};
+static const ldns_rdf_type type_dhcid_wireformat[] = {
+       LDNS_RDF_TYPE_B64
+};
+static const ldns_rdf_type type_talink_wireformat[] = {
+       LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
+};
+/* nsec3 is some vars, followed by same type of data of nsec */
+static const ldns_rdf_type type_nsec3_wireformat[] = {
+/*     LDNS_RDF_TYPE_NSEC3_VARS, LDNS_RDF_TYPE_NSEC3_NEXT_OWNER, LDNS_RDF_TYPE_NSEC*/
+       LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_NSEC3_SALT, LDNS_RDF_TYPE_NSEC3_NEXT_OWNER, LDNS_RDF_TYPE_NSEC
+};
+
+static const ldns_rdf_type type_nsec3param_wireformat[] = {
+/*     LDNS_RDF_TYPE_NSEC3_PARAMS_VARS*/
+       LDNS_RDF_TYPE_INT8,
+       LDNS_RDF_TYPE_INT8,
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_NSEC3_SALT
+};
+
+static const ldns_rdf_type type_dnskey_wireformat[] = {
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_INT8,
+       LDNS_RDF_TYPE_ALG,
+       LDNS_RDF_TYPE_B64
+};
+static const ldns_rdf_type type_tkey_wireformat[] = {
+       LDNS_RDF_TYPE_DNAME,
+       LDNS_RDF_TYPE_TIME,
+       LDNS_RDF_TYPE_TIME,
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_INT16_DATA,
+       LDNS_RDF_TYPE_INT16_DATA,
+};
+static const ldns_rdf_type type_tsig_wireformat[] = {
+       LDNS_RDF_TYPE_DNAME,
+       LDNS_RDF_TYPE_TSIGTIME,
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_INT16_DATA,
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_INT16_DATA
+};
+static const ldns_rdf_type type_tlsa_wireformat[] = {
+       LDNS_RDF_TYPE_INT8,
+       LDNS_RDF_TYPE_INT8,
+       LDNS_RDF_TYPE_INT8,
+       LDNS_RDF_TYPE_HEX
+};
+
+/** 
+ * With HIP, wire and presentation format are out of step.
+ * In presentation format, we have:
+ * - a PK algorithm presented as integer in range [0..255]
+ * - a variable length HIT field presented as hexstring
+ * - a variable length Public Key field presented as Base64
+ *
+ * Unfortunately in the wireformat the lengths of the variable
+ * length HIT and Public Key fields do not directly preceed them.
+ * In stead we have:
+ * - 1 byte  HIT length: h
+ * - 1 byte  PK algorithm
+ * - 2 bytes Public Key length: p
+ * - h bytes HIT
+ * - p bytes Public Key
+ *
+ * In ldns those deviations from the conventions for rdata fields are best 
+ * tackeled by letting the array refered to by the descriptor for HIP represent
+ * host format only.
+ *
+ * BEWARE! Unlike other RR types, actual HIP wire format does not directly
+ * follow the RDF types enumerated in the array pointed to by _wireformat in
+ * its descriptor record.
+ */
+static const ldns_rdf_type type_hip_hostformat[] = {
+       LDNS_RDF_TYPE_INT8,
+       LDNS_RDF_TYPE_HEX,
+       LDNS_RDF_TYPE_B64
+};
+
+static const ldns_rdf_type type_nid_wireformat[] = {
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_ILNP64
+};
+static const ldns_rdf_type type_l32_wireformat[] = {
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_A
+};
+static const ldns_rdf_type type_l64_wireformat[] = {
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_ILNP64
+};
+static const ldns_rdf_type type_lp_wireformat[] = {
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_DNAME
+};
+#ifdef DRAFT_RRTYPES
+static const ldns_rdf_type type_eui48_wireformat[] = {
+       LDNS_RDF_TYPE_EUI48
+};
+static const ldns_rdf_type type_eui64_wireformat[] = {
+       LDNS_RDF_TYPE_EUI64
+};
+static const ldns_rdf_type type_uri_wireformat[] = {
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_INT16,
+       LDNS_RDF_TYPE_LONG_STR
+};
+#endif
+static const ldns_rdf_type type_caa_wireformat[] = {
+       LDNS_RDF_TYPE_INT8,
+       LDNS_RDF_TYPE_TAG,
+       LDNS_RDF_TYPE_LONG_STR
+};
+
+/* All RR's defined in 1035 are well known and can thus
+ * be compressed. See RFC3597. These RR's are:
+ * CNAME HINFO MB MD MF MG MINFO MR MX NULL NS PTR SOA TXT
+ */
+static ldns_rr_descriptor rdata_field_descriptors[] = {
+       /* 0 */
+       { 0, NULL, 0, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 1 */
+       {LDNS_RR_TYPE_A, "A", 1, 1, type_a_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 2 */
+       {LDNS_RR_TYPE_NS, "NS", 1, 1, type_ns_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
+       /* 3 */
+       {LDNS_RR_TYPE_MD, "MD", 1, 1, type_md_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
+       /* 4 */
+       {LDNS_RR_TYPE_MF, "MF", 1, 1, type_mf_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
+       /* 5 */
+       {LDNS_RR_TYPE_CNAME, "CNAME", 1, 1, type_cname_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
+       /* 6 */
+       {LDNS_RR_TYPE_SOA, "SOA", 7, 7, type_soa_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 2 },
+       /* 7 */
+       {LDNS_RR_TYPE_MB, "MB", 1, 1, type_mb_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
+       /* 8 */
+       {LDNS_RR_TYPE_MG, "MG", 1, 1, type_mg_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
+       /* 9 */
+       {LDNS_RR_TYPE_MR, "MR", 1, 1, type_mr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
+       /* 10 */
+       {LDNS_RR_TYPE_NULL, "NULL", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 11 */
+       {LDNS_RR_TYPE_WKS, "WKS", 2, 2, type_wks_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 12 */
+       {LDNS_RR_TYPE_PTR, "PTR", 1, 1, type_ptr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
+       /* 13 */
+       {LDNS_RR_TYPE_HINFO, "HINFO", 2, 2, type_hinfo_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 14 */
+       {LDNS_RR_TYPE_MINFO, "MINFO", 2, 2, type_minfo_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 2 },
+       /* 15 */
+       {LDNS_RR_TYPE_MX, "MX", 2, 2, type_mx_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
+       /* 16 */
+       {LDNS_RR_TYPE_TXT, "TXT", 1, 0, NULL, LDNS_RDF_TYPE_STR, LDNS_RR_NO_COMPRESS, 0 },
+       /* 17 */
+       {LDNS_RR_TYPE_RP, "RP", 2, 2, type_rp_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 2 },
+       /* 18 */
+       {LDNS_RR_TYPE_AFSDB, "AFSDB", 2, 2, type_afsdb_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+       /* 19 */
+       {LDNS_RR_TYPE_X25, "X25", 1, 1, type_x25_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 20 */
+       {LDNS_RR_TYPE_ISDN, "ISDN", 1, 2, type_isdn_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 21 */
+       {LDNS_RR_TYPE_RT, "RT", 2, 2, type_rt_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+       /* 22 */
+       {LDNS_RR_TYPE_NSAP, "NSAP", 1, 1, type_nsap_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 23 */
+       {LDNS_RR_TYPE_NSAP_PTR, "NSAP-PTR", 1, 1, type_nsap_ptr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 24 */
+       {LDNS_RR_TYPE_SIG, "SIG", 9, 9, type_sig_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+       /* 25 */
+       {LDNS_RR_TYPE_KEY, "KEY", 4, 4, type_key_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 26 */
+       {LDNS_RR_TYPE_PX, "PX", 3, 3, type_px_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 2 },
+       /* 27 */
+       {LDNS_RR_TYPE_GPOS, "GPOS", 3, 3, type_gpos_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 28 */
+       {LDNS_RR_TYPE_AAAA, "AAAA", 1, 1, type_aaaa_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 29 */
+       {LDNS_RR_TYPE_LOC, "LOC", 1, 1, type_loc_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 30 */
+       {LDNS_RR_TYPE_NXT, "NXT", 2, 2, type_nxt_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+       /* 31 */
+       {LDNS_RR_TYPE_EID, "EID", 1, 1, type_eid_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 32 */
+       {LDNS_RR_TYPE_NIMLOC, "NIMLOC", 1, 1, type_nimloc_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 33 */
+       {LDNS_RR_TYPE_SRV, "SRV", 4, 4, type_srv_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+       /* 34 */
+       {LDNS_RR_TYPE_ATMA, "ATMA", 1, 1, type_atma_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 35 */
+       {LDNS_RR_TYPE_NAPTR, "NAPTR", 6, 6, type_naptr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+       /* 36 */
+       {LDNS_RR_TYPE_KX, "KX", 2, 2, type_kx_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+       /* 37 */
+       {LDNS_RR_TYPE_CERT, "CERT", 4, 4, type_cert_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 38 */
+       {LDNS_RR_TYPE_A6, "A6", 1, 1, type_a6_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 39 */
+       {LDNS_RR_TYPE_DNAME, "DNAME", 1, 1, type_dname_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+       /* 40 */
+       {LDNS_RR_TYPE_SINK, "SINK", 1, 1, type_sink_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 41 */
+       {LDNS_RR_TYPE_OPT, "OPT", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 42 */
+       {LDNS_RR_TYPE_APL, "APL", 0, 0, type_apl_wireformat, LDNS_RDF_TYPE_APL, LDNS_RR_NO_COMPRESS, 0 },
+       /* 43 */
+       {LDNS_RR_TYPE_DS, "DS", 4, 4, type_ds_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 44 */
+       {LDNS_RR_TYPE_SSHFP, "SSHFP", 3, 3, type_sshfp_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 45 */
+       {LDNS_RR_TYPE_IPSECKEY, "IPSECKEY", 1, 1, type_ipseckey_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 46 */
+       {LDNS_RR_TYPE_RRSIG, "RRSIG", 9, 9, type_rrsig_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+       /* 47 */
+       {LDNS_RR_TYPE_NSEC, "NSEC", 1, 2, type_nsec_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+       /* 48 */
+       {LDNS_RR_TYPE_DNSKEY, "DNSKEY", 4, 4, type_dnskey_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 49 */
+       {LDNS_RR_TYPE_DHCID, "DHCID", 1, 1, type_dhcid_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 50 */
+       {LDNS_RR_TYPE_NSEC3, "NSEC3", 5, 6, type_nsec3_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 51 */
+       {LDNS_RR_TYPE_NSEC3PARAM, "NSEC3PARAM", 4, 4, type_nsec3param_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 52 */
+       {LDNS_RR_TYPE_TLSA, "TLSA", 4, 4, type_tlsa_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+
+{LDNS_RR_TYPE_NULL, "TYPE53", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE54", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+
+       /* 55
+        * Hip ends with 0 or more Rendezvous Servers represented as dname's.
+        * Hence the LDNS_RDF_TYPE_DNAME _variable field and the _maximum field
+        * set to 0.
+        *
+        * BEWARE! Unlike other RR types, actual HIP wire format does not 
+        * directly follow the RDF types enumerated in the array pointed to
+        * by _wireformat. For more info see type_hip_hostformat declaration.
+        */
+       {LDNS_RR_TYPE_HIP, "HIP", 3, 3, type_hip_hostformat, LDNS_RDF_TYPE_DNAME, LDNS_RR_NO_COMPRESS, 0 },
+
+#ifdef DRAFT_RRTYPES
+       /* 56 */
+       {LDNS_RR_TYPE_NINFO, "NINFO", 1, 0, NULL, LDNS_RDF_TYPE_STR, LDNS_RR_NO_COMPRESS, 0 },
+       /* 57 */
+       {LDNS_RR_TYPE_RKEY, "RKEY", 4, 4, type_key_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+#else
+{LDNS_RR_TYPE_NULL, "TYPE56", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE57", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+#endif
+       /* 58 */
+       {LDNS_RR_TYPE_TALINK, "TALINK", 2, 2, type_talink_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 2 },
+
+#ifdef DRAFT_RRTYPES
+       /* 59 */
+       {LDNS_RR_TYPE_CDS, "CDS", 4, 4, type_ds_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+#else
+{LDNS_RR_TYPE_NULL, "TYPE59", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+#endif
+
+{LDNS_RR_TYPE_NULL, "TYPE60", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE61", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE62", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE63", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE64", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE65", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE66", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE67", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE68", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE69", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE70", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE71", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE72", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE73", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE74", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE75", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE76", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE77", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE78", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE79", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE80", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE81", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE82", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE83", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE84", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE85", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE86", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE87", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE88", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE89", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE90", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE91", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE92", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE93", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE94", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE95", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE96", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE97", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE98", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+
+       /* 99 */
+       {LDNS_RR_TYPE_SPF,  "SPF", 1, 0, NULL, LDNS_RDF_TYPE_STR, LDNS_RR_NO_COMPRESS, 0 },
+
+       /* UINFO  [IANA-Reserved] */
+{LDNS_RR_TYPE_NULL, "TYPE100", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* UID    [IANA-Reserved] */
+{LDNS_RR_TYPE_NULL, "TYPE101", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* GID    [IANA-Reserved] */
+{LDNS_RR_TYPE_NULL, "TYPE102", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* UNSPEC [IANA-Reserved] */
+{LDNS_RR_TYPE_NULL, "TYPE103", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+
+       /* 104 */
+       {LDNS_RR_TYPE_NID, "NID", 2, 2, type_nid_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 105 */
+       {LDNS_RR_TYPE_L32, "L32", 2, 2, type_l32_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 106 */
+       {LDNS_RR_TYPE_L64, "L64", 2, 2, type_l64_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 107 */
+       {LDNS_RR_TYPE_LP, "LP", 2, 2, type_lp_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+
+#ifdef DRAFT_RRTYPES
+       /* 108 */
+       {LDNS_RR_TYPE_EUI48, "EUI48", 1, 1, type_eui48_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* 109 */
+       {LDNS_RR_TYPE_EUI64, "EUI64", 1, 1, type_eui64_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+#else
+{LDNS_RR_TYPE_NULL, "TYPE108", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE109", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+#endif
+
+{LDNS_RR_TYPE_NULL, "TYPE110", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE111", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE112", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE113", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE114", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE115", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE116", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE117", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE118", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE119", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE120", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE121", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE122", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE123", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE124", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE125", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE126", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE127", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE128", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE129", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE130", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE131", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE132", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE133", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE134", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE135", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE136", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE137", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE138", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE139", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE140", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE141", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE142", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE143", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE144", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE145", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE146", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE147", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE148", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE149", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE150", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE151", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE152", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE153", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE154", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE155", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE156", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE157", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE158", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE159", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE160", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE161", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE162", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE163", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE164", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE165", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE166", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE167", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE168", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE169", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE170", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE171", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE172", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE173", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE174", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE175", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE176", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE177", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE178", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE179", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE180", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE181", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE182", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE183", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE184", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE185", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE186", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE187", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE188", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE189", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE190", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE191", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE192", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE193", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE194", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE195", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE196", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE197", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE198", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE199", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE200", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE201", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE202", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE203", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE204", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE205", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE206", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE207", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE208", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE209", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE210", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE211", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE212", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE213", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE214", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE215", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE216", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE217", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE218", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE219", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE220", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE221", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE222", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE223", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE224", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE225", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE226", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE227", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE228", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE229", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE230", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE231", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE232", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE233", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE234", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE235", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE236", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE237", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE238", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE239", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE240", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE241", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE242", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE243", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE244", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE245", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE246", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE247", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+{LDNS_RR_TYPE_NULL, "TYPE248", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+
+       /* LDNS_RDF_TYPE_INT16_DATA takes two fields (length and data) as one.
+        * So, unlike RFC 2930 spec, we have 7 min/max rdf's i.s.o. 8/9.
+        */
+       /* 249 */
+       {LDNS_RR_TYPE_TKEY, "TKEY", 7, 7, type_tkey_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+       /* LDNS_RDF_TYPE_INT16_DATA takes two fields (length and data) as one.
+        * So, unlike RFC 2930 spec, we have 7 min/max rdf's i.s.o. 8/9.
+        */
+       /* 250 */
+       {LDNS_RR_TYPE_TSIG, "TSIG", 7, 7, type_tsig_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
+
+       /* IXFR: A request for a transfer of an incremental zone transfer */
+{LDNS_RR_TYPE_IXFR, "IXFR", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* AXFR: A request for a transfer of an entire zone */
+{LDNS_RR_TYPE_AXFR, "AXFR", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* MAILB: A request for mailbox-related records (MB, MG or MR) */
+{LDNS_RR_TYPE_MAILB, "MAILB", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* MAILA: A request for mail agent RRs (Obsolete - see MX) */
+{LDNS_RR_TYPE_MAILA, "MAILA", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+       /* ANY: A request for all (available) records */
+{LDNS_RR_TYPE_ANY, "ANY", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+
+#ifdef DRAFT_RRTYPES
+       /* 256 */
+       {LDNS_RR_TYPE_URI, "URI", 3, 3, type_uri_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+#else
+{LDNS_RR_TYPE_NULL, "TYPE256", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+#endif
+       /* 257 */
+       {LDNS_RR_TYPE_CAA, "CAA", 3, 3, type_caa_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+
+/* split in array, no longer contiguous */
+
+#ifdef DRAFT_RRTYPES
+       /* 32768 */
+       {LDNS_RR_TYPE_TA, "TA", 4, 4, type_ds_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+#else
+{LDNS_RR_TYPE_NULL, "TYPE32768", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
+#endif
+       /* 32769 */
+       {LDNS_RR_TYPE_DLV, "DLV", 4, 4, type_ds_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }
+};
+
+/**
+ * \def LDNS_RDATA_FIELD_DESCRIPTORS_COUNT
+ * computes the number of rdata fields
+ */
+#define LDNS_RDATA_FIELD_DESCRIPTORS_COUNT \
+       (sizeof(rdata_field_descriptors)/sizeof(rdata_field_descriptors[0]))
+
+const ldns_rr_descriptor *
+ldns_rr_descript(uint16_t type)
+{
+       size_t i;
+       if (type < LDNS_RDATA_FIELD_DESCRIPTORS_COMMON) {
+               return &rdata_field_descriptors[type];
+       } else {
+               /* because not all array index equals type code */
+               for (i = LDNS_RDATA_FIELD_DESCRIPTORS_COMMON;
+                    i < LDNS_RDATA_FIELD_DESCRIPTORS_COUNT;
+                    i++) {
+                       if (rdata_field_descriptors[i]._type == type) {
+                               return &rdata_field_descriptors[i];
+                       }
+               }
+                return &rdata_field_descriptors[0];
+       }
+}
+
+size_t
+ldns_rr_descriptor_minimum(const ldns_rr_descriptor *descriptor)
+{
+       if (descriptor) {
+               return descriptor->_minimum;
+       } else {
+               return 0;
+       }
+}
+
+size_t
+ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor)
+{
+       if (descriptor) {
+               if (descriptor->_variable != LDNS_RDF_TYPE_NONE) {
+                       /* Should really be SIZE_MAX... bad FreeBSD.  */
+                       return UINT_MAX;
+               } else {
+                       return descriptor->_maximum;
+               }
+       } else {
+               return 0;
+       }
+}
+
+ldns_rdf_type
+ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor,
+                              size_t index)
+{
+       assert(descriptor != NULL);
+       assert(index < descriptor->_maximum
+              || descriptor->_variable != LDNS_RDF_TYPE_NONE);
+       if (index < descriptor->_maximum) {
+               return descriptor->_wireformat[index];
+       } else {
+               return descriptor->_variable;
+       }
+}
+
+ldns_rr_type
+ldns_get_rr_type_by_name(const char *name)
+{
+       unsigned int i;
+       const char *desc_name;
+       const ldns_rr_descriptor *desc;
+
+       /* TYPEXX representation */
+       if (strlen(name) > 4 && strncasecmp(name, "TYPE", 4) == 0) {
+               return atoi(name + 4);
+       }
+
+       /* Normal types */
+       for (i = 0; i < (unsigned int) LDNS_RDATA_FIELD_DESCRIPTORS_COUNT; i++) {
+               desc = &rdata_field_descriptors[i];
+               desc_name = desc->_name;
+               if(desc_name &&
+                  strlen(name) == strlen(desc_name) &&
+                  strncasecmp(name, desc_name, strlen(desc_name)) == 0) {
+                       /* because not all array index equals type code */
+                       return desc->_type;
+               }
+       }
+
+       /* special cases for query types */
+       if (strlen(name) == 4 && strncasecmp(name, "IXFR", 4) == 0) {
+               return 251;
+       } else if (strlen(name) == 4 && strncasecmp(name, "AXFR", 4) == 0) {
+               return 252;
+       } else if (strlen(name) == 5 && strncasecmp(name, "MAILB", 5) == 0) {
+               return 253;
+       } else if (strlen(name) == 5 && strncasecmp(name, "MAILA", 5) == 0) {
+               return 254;
+       } else if (strlen(name) == 3 && strncasecmp(name, "ANY", 3) == 0) {
+               return 255;
+       }
+
+       return 0;
+}
+
+ldns_rr_class
+ldns_get_rr_class_by_name(const char *name)
+{
+       ldns_lookup_table *lt;
+
+       /* CLASSXX representation */
+       if (strlen(name) > 5 && strncasecmp(name, "CLASS", 5) == 0) {
+               return atoi(name + 5);
+       }
+
+       /* Normal types */
+       lt = ldns_lookup_by_name(ldns_rr_classes, name);
+
+       if (lt) {
+               return lt->id;
+       }
+       return 0;
+}
diff --git a/ldns/rrdef.h b/ldns/rrdef.h
new file mode 100644 (file)
index 0000000..45ffa32
--- /dev/null
@@ -0,0 +1,500 @@
+/*
+ * rrdef.h
+ *
+ * RR definitions
+ *
+ * a Net::DNS like library for C
+ *
+ * (c) NLnet Labs, 2005-2006
+ *
+ * See the file LICENSE for the license
+ */
+
+/**
+ * \file
+ *
+ * Defines resource record types and constants.
+ */
+
+#ifndef LDNS_RRDEF_H
+#define LDNS_RRDEF_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Maximum length of a dname label */
+#define LDNS_MAX_LABELLEN     63
+/** Maximum length of a complete dname */
+#define LDNS_MAX_DOMAINLEN    255
+/** Maximum number of pointers in 1 dname */
+#define LDNS_MAX_POINTERS      65535
+/** The bytes TTL, CLASS and length use up in an rr */
+#define LDNS_RR_OVERHEAD       10
+
+#define LDNS_DNSSEC_KEYPROTO    3
+#define LDNS_KEY_ZONE_KEY   0x0100 /* set for ZSK&KSK, rfc 4034 */
+#define LDNS_KEY_SEP_KEY    0x0001 /* set for KSK, rfc 4034 */
+#define LDNS_KEY_REVOKE_KEY 0x0080 /* used to revoke KSK, rfc 5011 */
+
+/* The first fields are contiguous and can be referenced instantly */
+#define LDNS_RDATA_FIELD_DESCRIPTORS_COMMON 258
+
+/** lookuptable for rr types  */
+extern struct ldns_struct_lookup_table* ldns_rr_classes;
+
+/**
+ *  The different RR classes.
+ */
+enum ldns_enum_rr_class
+{
+       /** the Internet */
+       LDNS_RR_CLASS_IN        = 1,
+       /** Chaos class */
+       LDNS_RR_CLASS_CH        = 3,
+       /** Hesiod (Dyer 87) */
+       LDNS_RR_CLASS_HS        = 4,
+       /** None class, dynamic update */
+       LDNS_RR_CLASS_NONE      = 254,
+       /** Any class */
+       LDNS_RR_CLASS_ANY       = 255,
+
+       LDNS_RR_CLASS_FIRST     = 0,
+       LDNS_RR_CLASS_LAST      = 65535,
+       LDNS_RR_CLASS_COUNT     = LDNS_RR_CLASS_LAST - LDNS_RR_CLASS_FIRST + 1
+};
+typedef enum ldns_enum_rr_class ldns_rr_class;
+
+/**
+ *  Used to specify whether compression is allowed.
+ */
+enum ldns_enum_rr_compress
+{
+       /** compression is allowed */
+       LDNS_RR_COMPRESS,
+       LDNS_RR_NO_COMPRESS
+};
+typedef enum ldns_enum_rr_compress ldns_rr_compress;
+
+/**
+ * The different RR types.
+ */
+enum ldns_enum_rr_type
+{
+       /**  a host address */
+       LDNS_RR_TYPE_A = 1,
+       /**  an authoritative name server */
+       LDNS_RR_TYPE_NS = 2,
+       /**  a mail destination (Obsolete - use MX) */
+       LDNS_RR_TYPE_MD = 3,
+       /**  a mail forwarder (Obsolete - use MX) */
+       LDNS_RR_TYPE_MF = 4,
+       /**  the canonical name for an alias */
+       LDNS_RR_TYPE_CNAME = 5,
+       /**  marks the start of a zone of authority */
+       LDNS_RR_TYPE_SOA = 6,
+       /**  a mailbox domain name (EXPERIMENTAL) */
+       LDNS_RR_TYPE_MB = 7,
+       /**  a mail group member (EXPERIMENTAL) */
+       LDNS_RR_TYPE_MG = 8,
+       /**  a mail rename domain name (EXPERIMENTAL) */
+       LDNS_RR_TYPE_MR = 9,
+       /**  a null RR (EXPERIMENTAL) */
+       LDNS_RR_TYPE_NULL = 10,
+       /**  a well known service description */
+       LDNS_RR_TYPE_WKS = 11,
+       /**  a domain name pointer */
+       LDNS_RR_TYPE_PTR = 12,
+       /**  host information */
+       LDNS_RR_TYPE_HINFO = 13,
+       /**  mailbox or mail list information */
+       LDNS_RR_TYPE_MINFO = 14,
+       /**  mail exchange */
+       LDNS_RR_TYPE_MX = 15,
+       /**  text strings */
+       LDNS_RR_TYPE_TXT = 16,
+       /**  RFC1183 */
+       LDNS_RR_TYPE_RP = 17,
+       /**  RFC1183 */
+       LDNS_RR_TYPE_AFSDB = 18,
+       /**  RFC1183 */
+       LDNS_RR_TYPE_X25 = 19,
+       /**  RFC1183 */
+       LDNS_RR_TYPE_ISDN = 20,
+       /**  RFC1183 */
+       LDNS_RR_TYPE_RT = 21,
+       /**  RFC1706 */
+       LDNS_RR_TYPE_NSAP = 22,
+       /**  RFC1348 */
+       LDNS_RR_TYPE_NSAP_PTR = 23,
+       /**  2535typecode */
+       LDNS_RR_TYPE_SIG = 24,
+       /**  2535typecode */
+       LDNS_RR_TYPE_KEY = 25,
+       /**  RFC2163 */
+       LDNS_RR_TYPE_PX = 26,
+       /**  RFC1712 */
+       LDNS_RR_TYPE_GPOS = 27,
+       /**  ipv6 address */
+       LDNS_RR_TYPE_AAAA = 28,
+       /**  LOC record  RFC1876 */
+       LDNS_RR_TYPE_LOC = 29,
+       /**  2535typecode */
+       LDNS_RR_TYPE_NXT = 30,
+       /**  draft-ietf-nimrod-dns-01.txt */
+       LDNS_RR_TYPE_EID = 31,
+       /**  draft-ietf-nimrod-dns-01.txt */
+       LDNS_RR_TYPE_NIMLOC = 32,
+       /**  SRV record RFC2782 */
+       LDNS_RR_TYPE_SRV = 33,
+       /**  http://www.jhsoft.com/rfc/af-saa-0069.000.rtf */
+       LDNS_RR_TYPE_ATMA = 34,
+       /**  RFC2915 */
+       LDNS_RR_TYPE_NAPTR = 35,
+       /**  RFC2230 */
+       LDNS_RR_TYPE_KX = 36,
+       /**  RFC2538 */
+       LDNS_RR_TYPE_CERT = 37,
+       /**  RFC2874 */
+       LDNS_RR_TYPE_A6 = 38,
+       /**  RFC2672 */
+       LDNS_RR_TYPE_DNAME = 39,
+       /**  dnsind-kitchen-sink-02.txt */
+       LDNS_RR_TYPE_SINK = 40,
+       /**  Pseudo OPT record... */
+       LDNS_RR_TYPE_OPT = 41,
+       /**  RFC3123 */
+       LDNS_RR_TYPE_APL = 42,
+       /**  RFC4034, RFC3658 */
+       LDNS_RR_TYPE_DS = 43,
+       /**  SSH Key Fingerprint */
+       LDNS_RR_TYPE_SSHFP = 44, /* RFC 4255 */
+       /**  IPsec Key */
+       LDNS_RR_TYPE_IPSECKEY = 45, /* RFC 4025 */
+       /**  DNSSEC */
+       LDNS_RR_TYPE_RRSIG = 46, /* RFC 4034 */
+       LDNS_RR_TYPE_NSEC = 47, /* RFC 4034 */
+       LDNS_RR_TYPE_DNSKEY = 48, /* RFC 4034 */
+
+       LDNS_RR_TYPE_DHCID = 49, /* RFC 4701 */
+       /* NSEC3 */
+       LDNS_RR_TYPE_NSEC3 = 50, /* RFC 5155 */
+       LDNS_RR_TYPE_NSEC3PARAM = 51, /* RFC 5155 */
+       LDNS_RR_TYPE_NSEC3PARAMS = 51,
+       LDNS_RR_TYPE_TLSA = 52, /* RFC 6698 */
+
+       LDNS_RR_TYPE_HIP = 55, /* RFC 5205 */
+
+       /** draft-reid-dnsext-zs */
+       LDNS_RR_TYPE_NINFO = 56,
+       /** draft-reid-dnsext-rkey */
+       LDNS_RR_TYPE_RKEY = 57,
+        /** draft-ietf-dnsop-trust-history */
+        LDNS_RR_TYPE_TALINK = 58,
+       /** draft-barwood-dnsop-ds-publis */
+       LDNS_RR_TYPE_CDS = 59,
+
+       LDNS_RR_TYPE_SPF = 99, /* RFC 4408 */
+
+       LDNS_RR_TYPE_UINFO = 100,
+       LDNS_RR_TYPE_UID = 101,
+       LDNS_RR_TYPE_GID = 102,
+       LDNS_RR_TYPE_UNSPEC = 103,
+
+       LDNS_RR_TYPE_NID = 104, /* RFC 6742 */
+       LDNS_RR_TYPE_L32 = 105, /* RFC 6742 */
+       LDNS_RR_TYPE_L64 = 106, /* RFC 6742 */
+       LDNS_RR_TYPE_LP = 107, /* RFC 6742 */
+
+       /** draft-jabley-dnsext-eui48-eui64-rrtypes */
+       LDNS_RR_TYPE_EUI48 = 108,
+       LDNS_RR_TYPE_EUI64 = 109,
+
+       LDNS_RR_TYPE_TKEY = 249, /* RFC 2930 */
+       LDNS_RR_TYPE_TSIG = 250,
+       LDNS_RR_TYPE_IXFR = 251,
+       LDNS_RR_TYPE_AXFR = 252,
+       /**  A request for mailbox-related records (MB, MG or MR) */
+       LDNS_RR_TYPE_MAILB = 253,
+       /**  A request for mail agent RRs (Obsolete - see MX) */
+       LDNS_RR_TYPE_MAILA = 254,
+       /**  any type (wildcard) */
+       LDNS_RR_TYPE_ANY = 255,
+       /** draft-faltstrom-uri-06 */
+       LDNS_RR_TYPE_URI = 256,
+       LDNS_RR_TYPE_CAA = 257, /* RFC 6844 */
+
+       /** DNSSEC Trust Authorities */
+       LDNS_RR_TYPE_TA = 32768,
+       /* RFC 4431, 5074, DNSSEC Lookaside Validation */
+       LDNS_RR_TYPE_DLV = 32769,
+
+       /* type codes from nsec3 experimental phase
+       LDNS_RR_TYPE_NSEC3 = 65324,
+       LDNS_RR_TYPE_NSEC3PARAMS = 65325, */
+       LDNS_RR_TYPE_FIRST = 0,
+       LDNS_RR_TYPE_LAST  = 65535,
+       LDNS_RR_TYPE_COUNT = LDNS_RR_TYPE_LAST - LDNS_RR_TYPE_FIRST + 1
+};
+typedef enum ldns_enum_rr_type ldns_rr_type;
+
+/* RDATA */
+#define LDNS_MAX_RDFLEN        65535
+
+#define LDNS_RDF_SIZE_BYTE              1
+#define LDNS_RDF_SIZE_WORD              2
+#define LDNS_RDF_SIZE_DOUBLEWORD        4
+#define LDNS_RDF_SIZE_6BYTES            6
+#define LDNS_RDF_SIZE_8BYTES            8
+#define LDNS_RDF_SIZE_16BYTES           16
+
+#define LDNS_NSEC3_VARS_OPTOUT_MASK 0x01
+
+#define LDNS_APL_IP4            1
+#define LDNS_APL_IP6            2
+#define LDNS_APL_MASK           0x7f
+#define LDNS_APL_NEGATION       0x80
+
+/**
+ * The different types of RDATA fields.
+ */
+enum ldns_enum_rdf_type
+{
+       /** none */
+       LDNS_RDF_TYPE_NONE,
+       /** domain name */
+       LDNS_RDF_TYPE_DNAME,
+       /** 8 bits */
+       LDNS_RDF_TYPE_INT8,
+       /** 16 bits */
+       LDNS_RDF_TYPE_INT16,
+       /** 32 bits */
+       LDNS_RDF_TYPE_INT32,
+       /** A record */
+       LDNS_RDF_TYPE_A,
+       /** AAAA record */
+       LDNS_RDF_TYPE_AAAA,
+       /** txt string */
+       LDNS_RDF_TYPE_STR,
+       /** apl data */
+       LDNS_RDF_TYPE_APL,
+       /** b32 string */
+       LDNS_RDF_TYPE_B32_EXT,
+       /** b64 string */
+       LDNS_RDF_TYPE_B64,
+       /** hex string */
+       LDNS_RDF_TYPE_HEX,
+       /** nsec type codes */
+       LDNS_RDF_TYPE_NSEC,
+       /** a RR type */
+       LDNS_RDF_TYPE_TYPE,
+       /** a class */
+       LDNS_RDF_TYPE_CLASS,
+       /** certificate algorithm */
+       LDNS_RDF_TYPE_CERT_ALG,
+       /** a key algorithm */
+        LDNS_RDF_TYPE_ALG,
+        /** unknown types */
+        LDNS_RDF_TYPE_UNKNOWN,
+        /** time (32 bits) */
+        LDNS_RDF_TYPE_TIME,
+        /** period */
+        LDNS_RDF_TYPE_PERIOD,
+        /** tsig time 48 bits */
+        LDNS_RDF_TYPE_TSIGTIME,
+       /** skip 21 unused */
+        /** variable length any type rdata where the length
+            is specified by the first 2 bytes */
+        LDNS_RDF_TYPE_INT16_DATA = 22,
+        /** protocol and port bitmaps */
+        LDNS_RDF_TYPE_SERVICE,
+        /** location data */
+        LDNS_RDF_TYPE_LOC,
+        /** well known services */
+        LDNS_RDF_TYPE_WKS,
+        /** NSAP */
+        LDNS_RDF_TYPE_NSAP,
+        /** ATMA */
+        LDNS_RDF_TYPE_ATMA,
+        /** IPSECKEY */
+        LDNS_RDF_TYPE_IPSECKEY,
+        /** nsec3 hash salt */
+        LDNS_RDF_TYPE_NSEC3_SALT,
+        /** nsec3 base32 string (with length byte on wire */
+        LDNS_RDF_TYPE_NSEC3_NEXT_OWNER,
+
+        /** 4 shorts represented as 4 * 16 bit hex numbers
+         *  seperated by colons. For NID and L64.
+         */
+        LDNS_RDF_TYPE_ILNP64,
+
+        /** 6 * 8 bit hex numbers seperated by dashes. For EUI48. */
+        LDNS_RDF_TYPE_EUI48,
+        /** 8 * 8 bit hex numbers seperated by dashes. For EUI64. */
+        LDNS_RDF_TYPE_EUI64,
+
+        /** A non-zero sequence of US-ASCII letters and numbers in lower case.
+         *  For CAA.
+         */
+        LDNS_RDF_TYPE_TAG,
+
+        /** A <character-string> encoding of the value field as specified 
+         * [RFC1035], Section 5.1., encoded as remaining rdata.
+         * For CAA.
+         */
+        LDNS_RDF_TYPE_LONG_STR,
+
+        /* Aliases */
+        LDNS_RDF_TYPE_BITMAP = LDNS_RDF_TYPE_NSEC
+};
+typedef enum ldns_enum_rdf_type ldns_rdf_type;
+
+/**
+ * Algorithms used in dns
+ */
+enum ldns_enum_algorithm
+{
+        LDNS_RSAMD5             = 1,   /* RFC 4034,4035 */
+        LDNS_DH                 = 2,
+        LDNS_DSA                = 3,
+        LDNS_ECC                = 4,
+        LDNS_RSASHA1            = 5,
+        LDNS_DSA_NSEC3          = 6,
+        LDNS_RSASHA1_NSEC3      = 7,
+        LDNS_RSASHA256          = 8,   /* RFC 5702 */
+        LDNS_RSASHA512          = 10,  /* RFC 5702 */
+        LDNS_ECC_GOST           = 12,  /* RFC 5933 */
+        LDNS_ECDSAP256SHA256    = 13,  /* RFC 6605 */
+        LDNS_ECDSAP384SHA384    = 14,  /* RFC 6605 */
+        LDNS_INDIRECT           = 252,
+        LDNS_PRIVATEDNS         = 253,
+        LDNS_PRIVATEOID         = 254
+};
+typedef enum ldns_enum_algorithm ldns_algorithm;
+
+/**
+ * Hashing algorithms used in the DS record
+ */
+enum ldns_enum_hash
+{
+        LDNS_SHA1               = 1,  /* RFC 4034 */
+        LDNS_SHA256             = 2,  /* RFC 4509 */
+        LDNS_HASH_GOST          = 3,  /* RFC 5933 */
+        LDNS_SHA384             = 4   /* RFC 6605 */
+};
+typedef enum ldns_enum_hash ldns_hash;
+
+/**
+ * algorithms used in CERT rrs
+ */
+enum ldns_enum_cert_algorithm
+{
+        LDNS_CERT_PKIX          = 1,
+        LDNS_CERT_SPKI          = 2,
+        LDNS_CERT_PGP           = 3,
+        LDNS_CERT_IPKIX         = 4,
+        LDNS_CERT_ISPKI         = 5,
+        LDNS_CERT_IPGP          = 6,
+        LDNS_CERT_ACPKIX        = 7,
+        LDNS_CERT_IACPKIX       = 8,
+        LDNS_CERT_URI           = 253,
+        LDNS_CERT_OID           = 254
+};
+typedef enum ldns_enum_cert_algorithm ldns_cert_algorithm;
+
+/**
+ * EDNS option codes
+ */
+enum ldns_enum_edns_option
+{
+       LDNS_EDNS_LLQ = 1, /* http://files.dns-sd.org/draft-sekar-dns-llq.txt */
+       LDNS_EDNS_UL = 2, /* http://files.dns-sd.org/draft-sekar-dns-ul.txt */
+       LDNS_EDNS_NSID = 3, /* RFC5001 */
+       /* 4 draft-cheshire-edns0-owner-option */
+       LDNS_EDNS_DAU = 5, /* RFC6975 */
+       LDNS_EDNS_DHU = 6, /* RFC6975 */
+       LDNS_EDNS_N3U = 7, /* RFC6975 */
+       LDNS_EDNS_CLIENT_SUBNET = 8 /* draft-vandergaast-edns-client-subnet */
+};
+typedef enum ldns_edns_option ldns_edns_option;
+
+#define LDNS_EDNS_MASK_DO_BIT 0x8000
+
+/**
+ * Contains all information about resource record types.
+ *
+ * This structure contains, for all rr types, the rdata fields that are defined.
+ */
+struct ldns_struct_rr_descriptor
+{
+       /** Type of the RR that is described here */
+       ldns_rr_type    _type;
+       /** Textual name of the RR type.  */
+       const char *_name;
+       /** Minimum number of rdata fields in the RRs of this type.  */
+       uint8_t     _minimum;
+       /** Maximum number of rdata fields in the RRs of this type.  */
+       uint8_t     _maximum;
+       /** Wireformat specification for the rr, i.e. the types of rdata fields in their respective order. */
+       const ldns_rdf_type *_wireformat;
+       /** Special rdf types */
+       ldns_rdf_type _variable;
+       /** Specifies whether compression can be used for dnames in this RR type. */
+       ldns_rr_compress _compress;
+       /** The number of DNAMEs in the _wireformat string, for parsing. */
+       uint8_t _dname_count;
+};
+typedef struct ldns_struct_rr_descriptor ldns_rr_descriptor;
+
+/**
+ * returns the resource record descriptor for the given rr type.
+ *
+ * \param[in] type the type value of the rr type
+ *\return the ldns_rr_descriptor for this type
+ */
+const ldns_rr_descriptor *ldns_rr_descript(uint16_t type);
+
+/**
+ * returns the minimum number of rdata fields of the rr type this descriptor describes.
+ *
+ * \param[in]  descriptor for an rr type
+ * \return the minimum number of rdata fields
+ */
+size_t ldns_rr_descriptor_minimum(const ldns_rr_descriptor *descriptor);
+
+/**
+ * returns the maximum number of rdata fields of the rr type this descriptor describes.
+ *
+ * \param[in]  descriptor for an rr type
+ * \return the maximum number of rdata fields
+ */
+size_t ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor);
+
+/**
+ * returns the rdf type for the given rdata field number of the rr type for the given descriptor.
+ *
+ * \param[in] descriptor for an rr type
+ * \param[in] field the field number
+ * \return the rdf type for the field
+ */
+ldns_rdf_type ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor, size_t field);
+
+/**
+ * retrieves a rrtype by looking up its name.
+ * \param[in] name a string with the name
+ * \return the type which corresponds with the name
+ */
+ldns_rr_type ldns_get_rr_type_by_name(const char *name);
+
+/**
+ * retrieves a class by looking up its name.
+ * \param[in] name string with the name
+ * \return the cass which corresponds with the name
+ */
+ldns_rr_class ldns_get_rr_class_by_name(const char *name);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LDNS_RRDEF_H */
diff --git a/ldns/sbuffer.c b/ldns/sbuffer.c
new file mode 100644 (file)
index 0000000..0561752
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+ * buffer.c -- generic memory buffer .
+ *
+ * Copyright (c) 2001-2008, NLnet Labs. All rights reserved.
+ *
+ * See LICENSE for the license.
+ *
+ */
+/**
+ * \file
+ *
+ * This file contains the definition of ldns_buffer, and functions to manipulate those.
+ */
+#include "config.h"
+#include "ldns/sbuffer.h"
+#include <stdarg.h>
+
+ldns_buffer *
+ldns_buffer_new(size_t capacity)
+{
+       ldns_buffer *buffer = (ldns_buffer*)malloc(sizeof(ldns_buffer));
+
+       if (!buffer) {
+               return NULL;
+       }
+       
+       buffer->_data = (uint8_t *) malloc(capacity);
+       if (!buffer->_data) {
+               free(buffer);
+               return NULL;
+       }
+       
+       buffer->_position = 0;
+       buffer->_limit = buffer->_capacity = capacity;
+       buffer->_fixed = 0;
+       buffer->_status_err = 0;
+       
+       ldns_buffer_invariant(buffer);
+       
+       return buffer;
+}
+
+void
+ldns_buffer_new_frm_data(ldns_buffer *buffer, void *data, size_t size)
+{
+       assert(data != NULL);
+
+       buffer->_position = 0; 
+       buffer->_limit = buffer->_capacity = size;
+       buffer->_fixed = 0;
+       buffer->_data = malloc(size);
+       if(!buffer->_data) {
+               buffer->_status_err = 1;
+               return;
+       }
+       memcpy(buffer->_data, data, size);
+       buffer->_status_err = 0;
+       
+       ldns_buffer_invariant(buffer);
+}
+
+void
+ldns_buffer_init_frm_data(ldns_buffer *buffer, void *data, size_t size)
+{
+       memset(buffer, 0, sizeof(*buffer));
+       buffer->_data = data;
+       buffer->_capacity = buffer->_limit = size;
+       buffer->_fixed = 1;
+}
+
+int
+ldns_buffer_set_capacity(ldns_buffer *buffer, size_t capacity)
+{
+       void *data;
+       
+       ldns_buffer_invariant(buffer);
+       assert(buffer->_position <= capacity);
+
+       data = (uint8_t *) realloc(buffer->_data, capacity);
+       if (!data) {
+               buffer->_status_err = 1;
+               return 0;
+       } else {
+               buffer->_data = data;
+               buffer->_limit = buffer->_capacity = capacity;
+               return 1;
+       }
+}
+
+int
+ldns_buffer_reserve(ldns_buffer *buffer, size_t amount)
+{
+       ldns_buffer_invariant(buffer);
+       assert(!buffer->_fixed);
+       if (buffer->_capacity < buffer->_position + amount) {
+               size_t new_capacity = buffer->_capacity * 3 / 2;
+
+               if (new_capacity < buffer->_position + amount) {
+                       new_capacity = buffer->_position + amount;
+               }
+               if (!ldns_buffer_set_capacity(buffer, new_capacity)) {
+                       buffer->_status_err = 1;
+                       return 0;
+               }
+       }
+       buffer->_limit = buffer->_capacity;
+       return 1;
+}
+
+int
+ldns_buffer_printf(ldns_buffer *buffer, const char *format, ...)
+{
+       va_list args;
+       int written = 0;
+       size_t remaining;
+       
+       if (ldns_buffer_status_ok(buffer)) {
+               ldns_buffer_invariant(buffer);
+               assert(buffer->_limit == buffer->_capacity);
+
+               remaining = ldns_buffer_remaining(buffer);
+               va_start(args, format);
+               written = vsnprintf((char *) ldns_buffer_current(buffer), remaining,
+                                   format, args);
+               va_end(args);
+               if (written == -1) {
+                       buffer->_status_err = 1;
+                       return -1;
+               } else if ((size_t) written >= remaining) {
+                       if (!ldns_buffer_reserve(buffer, (size_t) written + 1)) {
+                               buffer->_status_err = 1;
+                               return -1;
+                       }
+                       va_start(args, format);
+                       written = vsnprintf((char *) ldns_buffer_current(buffer),
+                           ldns_buffer_remaining(buffer), format, args);
+                       va_end(args);
+                       if (written == -1) {
+                               buffer->_status_err = 1;
+                               return -1;
+                       }
+               }
+               buffer->_position += written;
+       }
+       return written;
+}
+
+void
+ldns_buffer_free(ldns_buffer *buffer)
+{
+       if (!buffer) {
+               return;
+       }
+
+       if (!buffer->_fixed)
+               free(buffer->_data);
+
+       free(buffer);
+}
+
+void *
+ldns_buffer_export(ldns_buffer *buffer)
+{
+       buffer->_fixed = 1;
+       return buffer->_data;
+}
+
+int
+ldns_bgetc(ldns_buffer *buffer)
+{
+       if (!ldns_buffer_available_at(buffer, buffer->_position, sizeof(uint8_t))) {
+               ldns_buffer_set_position(buffer, ldns_buffer_limit(buffer));
+               /* ldns_buffer_rewind(buffer);*/
+               return EOF;
+       }
+       return (int)ldns_buffer_read_u8(buffer);
+}
+
+void 
+ldns_buffer_copy(ldns_buffer* result, ldns_buffer* from)
+{
+       size_t tocopy = ldns_buffer_limit(from);
+
+       if(tocopy > ldns_buffer_capacity(result))
+               tocopy = ldns_buffer_capacity(result);
+       ldns_buffer_clear(result);
+       ldns_buffer_write(result, ldns_buffer_begin(from), tocopy);
+       ldns_buffer_flip(result);
+}
diff --git a/ldns/sbuffer.h b/ldns/sbuffer.h
new file mode 100644 (file)
index 0000000..dd66dfe
--- /dev/null
@@ -0,0 +1,706 @@
+/*
+ * buffer.h -- generic memory buffer.
+ *
+ * Copyright (c) 2005-2008, NLnet Labs. All rights reserved.
+ *
+ * See LICENSE for the license.
+ *
+ *
+ * The buffer module implements a generic buffer.  The API is based on
+ * the java.nio.Buffer interface.
+ */
+
+#ifndef LDNS_SBUFFER_H
+#define LDNS_SBUFFER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef S_SPLINT_S
+#  define INLINE 
+#else
+#  ifdef SWIG
+#    define INLINE static
+#  else
+#    define INLINE static inline
+#  endif
+#endif
+
+/*
+ * Copy data allowing for unaligned accesses in network byte order
+ * (big endian).
+ */
+INLINE uint16_t
+ldns_read_uint16(const void *src)
+{
+#ifdef ALLOW_UNALIGNED_ACCESSES
+        return ntohs(*(uint16_t *) src);
+#else
+        uint8_t *p = (uint8_t *) src;
+        return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
+#endif
+}
+
+INLINE uint32_t
+ldns_read_uint32(const void *src)
+{
+#ifdef ALLOW_UNALIGNED_ACCESSES
+        return ntohl(*(uint32_t *) src);
+#else
+        uint8_t *p = (uint8_t *) src;
+        return (  ((uint32_t) p[0] << 24)
+                | ((uint32_t) p[1] << 16)
+                | ((uint32_t) p[2] << 8)
+                |  (uint32_t) p[3]);
+#endif
+}
+
+/*
+ * Copy data allowing for unaligned accesses in network byte order
+ * (big endian).
+ */
+INLINE void
+ldns_write_uint16(void *dst, uint16_t data)
+{
+#ifdef ALLOW_UNALIGNED_ACCESSES
+        * (uint16_t *) dst = htons(data);
+#else
+        uint8_t *p = (uint8_t *) dst;
+        p[0] = (uint8_t) ((data >> 8) & 0xff);
+        p[1] = (uint8_t) (data & 0xff);
+#endif
+}
+
+INLINE void
+ldns_write_uint32(void *dst, uint32_t data)
+{
+#ifdef ALLOW_UNALIGNED_ACCESSES
+        * (uint32_t *) dst = htonl(data);
+#else
+        uint8_t *p = (uint8_t *) dst;
+        p[0] = (uint8_t) ((data >> 24) & 0xff);
+        p[1] = (uint8_t) ((data >> 16) & 0xff);
+        p[2] = (uint8_t) ((data >> 8) & 0xff);
+        p[3] = (uint8_t) (data & 0xff);
+#endif
+}
+
+
+/**
+ * \file sbuffer.h
+ *
+ * This file contains the definition of ldns_buffer, and functions to manipulate those.
+ */
+
+/** 
+ * implementation of buffers to ease operations
+ *
+ * ldns_buffers can contain arbitrary information, per octet. You can write
+ * to the current end of a buffer, read from the current position, and
+ * access any data within it.
+ */
+struct ldns_buffer
+{
+       /** The current position used for reading/writing */ 
+       size_t   _position;
+
+       /** The read/write limit */
+       size_t   _limit;
+
+       /** The amount of data the buffer can contain */
+       size_t   _capacity;
+
+       /** The data contained in the buffer */
+       uint8_t *_data;
+
+       /** If the buffer is fixed it cannot be resized */
+       unsigned _fixed : 1;
+
+       /** The current state of the buffer. If writing to the buffer fails
+        * for any reason, this value is changed. This way, you can perform
+        * multiple writes in sequence and check for success afterwards. */
+       unsigned _status_err : 1;
+};
+typedef struct ldns_buffer ldns_buffer;
+
+#ifdef NDEBUG
+INLINE void
+ldns_buffer_invariant(ldns_buffer *ATTR_UNUSED(buffer))
+{
+}
+#else
+INLINE void
+ldns_buffer_invariant(ldns_buffer *buffer)
+{
+       assert(buffer != NULL);
+       assert(buffer->_position <= buffer->_limit);
+       assert(buffer->_limit <= buffer->_capacity);
+       assert(buffer->_data != NULL);
+}
+#endif
+
+/**
+ * creates a new buffer with the specified capacity.
+ *
+ * \param[in] capacity the size (in bytes) to allocate for the buffer
+ * \return the created buffer
+ */
+ldns_buffer *ldns_buffer_new(size_t capacity);
+
+/**
+ * creates a buffer with the specified data.  The data IS copied
+ * and MEMORY allocations are done.  The buffer is not fixed and can
+ * be resized using buffer_reserve().
+ *
+ * \param[in] buffer pointer to the buffer to put the data in
+ * \param[in] data the data to encapsulate in the buffer
+ * \param[in] size the size of the data
+ */
+void ldns_buffer_new_frm_data(ldns_buffer *buffer, void *data, size_t size);
+
+/**
+ * Setup a buffer with the data pointed to. No data copied, no memory allocs.
+ * The buffer is fixed.
+ * \param[in] buffer pointer to the buffer to put the data in
+ * \param[in] data the data to encapsulate in the buffer
+ * \param[in] size the size of the data
+ */
+void ldns_buffer_init_frm_data(ldns_buffer *buffer, void *data, size_t size);
+
+/**
+ * clears the buffer and make it ready for writing.  The buffer's limit
+ * is set to the capacity and the position is set to 0.
+ * \param[in] buffer the buffer to clear
+ */
+INLINE void ldns_buffer_clear(ldns_buffer *buffer)
+{
+       ldns_buffer_invariant(buffer);
+
+       /* reset status here? */
+
+       buffer->_position = 0;
+       buffer->_limit = buffer->_capacity;
+}
+
+/**
+ * makes the buffer ready for reading the data that has been written to
+ * the buffer.  The buffer's limit is set to the current position and
+ * the position is set to 0.
+ *
+ * \param[in] buffer the buffer to flip
+ * \return void
+ */
+INLINE void ldns_buffer_flip(ldns_buffer *buffer)
+{
+       ldns_buffer_invariant(buffer);
+
+       buffer->_limit = buffer->_position;
+       buffer->_position = 0;
+}
+
+/**
+ * make the buffer ready for re-reading the data.  The buffer's
+ * position is reset to 0.
+ * \param[in] buffer the buffer to rewind
+ */
+INLINE void ldns_buffer_rewind(ldns_buffer *buffer)
+{
+       ldns_buffer_invariant(buffer);
+
+       buffer->_position = 0;
+}
+
+/**
+ * returns the current position in the buffer (as a number of bytes)
+ * \param[in] buffer the buffer
+ * \return the current position
+ */
+INLINE size_t
+ldns_buffer_position(ldns_buffer *buffer)
+{
+       return buffer->_position;
+}
+
+/**
+ * sets the buffer's position to MARK.  The position must be less than
+ * or equal to the buffer's limit.
+ * \param[in] buffer the buffer
+ * \param[in] mark the mark to use
+ */
+INLINE void
+ldns_buffer_set_position(ldns_buffer *buffer, size_t mark)
+{
+       assert(mark <= buffer->_limit);
+       buffer->_position = mark;
+}
+
+/**
+ * changes the buffer's position by COUNT bytes.  The position must not
+ * be moved behind the buffer's limit or before the beginning of the
+ * buffer.
+ * \param[in] buffer the buffer
+ * \param[in] count the count to use
+ */
+INLINE void
+ldns_buffer_skip(ldns_buffer *buffer, ssize_t count)
+{
+       assert(buffer->_position + count <= buffer->_limit);
+       buffer->_position += count;
+}
+
+/**
+ * returns the maximum size of the buffer
+ * \param[in] buffer
+ * \return the size
+ */
+INLINE size_t
+ldns_buffer_limit(ldns_buffer *buffer)
+{
+       return buffer->_limit;
+}
+
+/**
+ * changes the buffer's limit.  If the buffer's position is greater
+ * than the new limit the position is set to the limit.
+ * \param[in] buffer the buffer
+ * \param[in] limit the new limit
+ */
+INLINE void
+ldns_buffer_set_limit(ldns_buffer *buffer, size_t limit)
+{
+       assert(limit <= buffer->_capacity);
+       buffer->_limit = limit;
+       if (buffer->_position > buffer->_limit)
+               buffer->_position = buffer->_limit;
+}
+
+/**
+ * returns the number of bytes the buffer can hold.
+ * \param[in] buffer the buffer
+ * \return the number of bytes
+ */
+INLINE size_t
+ldns_buffer_capacity(ldns_buffer *buffer)
+{
+       return buffer->_capacity;
+}
+
+/**
+ * changes the buffer's capacity.  The data is reallocated so any
+ * pointers to the data may become invalid.  The buffer's limit is set
+ * to the buffer's new capacity.
+ * \param[in] buffer the buffer
+ * \param[in] capacity the capacity to use
+ * \return whether this failed or succeeded
+ */
+int ldns_buffer_set_capacity(ldns_buffer *buffer, size_t capacity);
+
+/**
+ * ensures BUFFER can contain at least AMOUNT more bytes.  The buffer's
+ * capacity is increased if necessary using buffer_set_capacity().
+ *
+ * The buffer's limit is always set to the (possibly increased)
+ * capacity.
+ * \param[in] buffer the buffer
+ * \param[in] amount amount to use
+ * \return whether this failed or succeeded
+ */
+int ldns_buffer_reserve(ldns_buffer *buffer, size_t amount);
+
+/**
+ * returns a pointer to the data at the indicated position.
+ * \param[in] buffer the buffer
+ * \param[in] at position
+ * \return the pointer to the data
+ */
+INLINE uint8_t *
+ldns_buffer_at(const ldns_buffer *buffer, size_t at)
+{
+       assert(at <= buffer->_limit);
+       return buffer->_data + at;
+}
+
+/**
+ * returns a pointer to the beginning of the buffer (the data at
+ * position 0).
+ * \param[in] buffer the buffer
+ * \return the pointer
+ */
+INLINE uint8_t *
+ldns_buffer_begin(const ldns_buffer *buffer)
+{
+       return ldns_buffer_at(buffer, 0);
+}
+
+/**
+ * returns a pointer to the end of the buffer (the data at the buffer's
+ * limit).
+ * \param[in] buffer the buffer
+ * \return the pointer
+ */
+INLINE uint8_t *
+ldns_buffer_end(ldns_buffer *buffer)
+{
+       return ldns_buffer_at(buffer, buffer->_limit);
+}
+
+/**
+ * returns a pointer to the data at the buffer's current position.
+ * \param[in] buffer the buffer
+ * \return the pointer
+ */
+INLINE uint8_t *
+ldns_buffer_current(ldns_buffer *buffer)
+{
+       return ldns_buffer_at(buffer, buffer->_position);
+}
+
+/**
+ * returns the number of bytes remaining between the indicated position and
+ * the limit.
+ * \param[in] buffer the buffer
+ * \param[in] at indicated position
+ * \return number of bytes
+ */
+INLINE size_t
+ldns_buffer_remaining_at(ldns_buffer *buffer, size_t at)
+{
+       ldns_buffer_invariant(buffer);
+       assert(at <= buffer->_limit);
+       return buffer->_limit - at;
+}
+
+/**
+ * returns the number of bytes remaining between the buffer's position and
+ * limit.
+ * \param[in] buffer the buffer
+ * \return the number of bytes
+ */
+INLINE size_t
+ldns_buffer_remaining(ldns_buffer *buffer)
+{
+       return ldns_buffer_remaining_at(buffer, buffer->_position);
+}
+
+/**
+ * checks if the buffer has at least COUNT more bytes available.
+ * Before reading or writing the caller needs to ensure enough space
+ * is available!
+ * \param[in] buffer the buffer
+ * \param[in] at indicated position
+ * \param[in] count how much is available
+ * \return true or false (as int?)
+ */
+INLINE int
+ldns_buffer_available_at(ldns_buffer *buffer, size_t at, size_t count)
+{
+       return count <= ldns_buffer_remaining_at(buffer, at);
+}
+
+/**
+ * checks if the buffer has count bytes available at the current position
+ * \param[in] buffer the buffer
+ * \param[in] count how much is available
+ * \return true or false (as int?)
+ */
+INLINE int
+ldns_buffer_available(ldns_buffer *buffer, size_t count)
+{
+       return ldns_buffer_available_at(buffer, buffer->_position, count);
+}
+
+/**
+ * writes the given data to the buffer at the specified position
+ * \param[in] buffer the buffer
+ * \param[in] at the position (in number of bytes) to write the data at
+ * \param[in] data pointer to the data to write to the buffer
+ * \param[in] count the number of bytes of data to write
+ */
+INLINE void
+ldns_buffer_write_at(ldns_buffer *buffer, size_t at, const void *data, size_t count)
+{
+       assert(ldns_buffer_available_at(buffer, at, count));
+       memcpy(buffer->_data + at, data, count);
+}
+
+/**
+ * writes count bytes of data to the current position of the buffer
+ * \param[in] buffer the buffer
+ * \param[in] data the data to write
+ * \param[in] count the lenght of the data to write
+ */
+INLINE void
+ldns_buffer_write(ldns_buffer *buffer, const void *data, size_t count)
+{
+       ldns_buffer_write_at(buffer, buffer->_position, data, count);
+       buffer->_position += count;
+}
+
+/**
+ * copies the given (null-delimited) string to the specified position at the buffer
+ * \param[in] buffer the buffer
+ * \param[in] at the position in the buffer
+ * \param[in] str the string to write
+ */
+INLINE void
+ldns_buffer_write_string_at(ldns_buffer *buffer, size_t at, const char *str)
+{
+       ldns_buffer_write_at(buffer, at, str, strlen(str));
+}
+
+/**
+ * copies the given (null-delimited) string to the current position at the buffer
+ * \param[in] buffer the buffer
+ * \param[in] str the string to write
+ */
+INLINE void
+ldns_buffer_write_string(ldns_buffer *buffer, const char *str)
+{
+       ldns_buffer_write(buffer, str, strlen(str));
+}
+
+/**
+ * writes the given byte of data at the given position in the buffer
+ * \param[in] buffer the buffer
+ * \param[in] at the position in the buffer
+ * \param[in] data the 8 bits to write
+ */
+INLINE void
+ldns_buffer_write_u8_at(ldns_buffer *buffer, size_t at, uint8_t data)
+{
+       assert(ldns_buffer_available_at(buffer, at, sizeof(data)));
+       buffer->_data[at] = data;
+}
+
+/**
+ * writes the given byte of data at the current position in the buffer
+ * \param[in] buffer the buffer
+ * \param[in] data the 8 bits to write
+ */
+INLINE void
+ldns_buffer_write_u8(ldns_buffer *buffer, uint8_t data)
+{
+       ldns_buffer_write_u8_at(buffer, buffer->_position, data);
+       buffer->_position += sizeof(data);
+}
+
+/**
+ * writes the given 2 byte integer at the given position in the buffer
+ * \param[in] buffer the buffer
+ * \param[in] at the position in the buffer
+ * \param[in] data the 16 bits to write
+ */
+INLINE void
+ldns_buffer_write_u16_at(ldns_buffer *buffer, size_t at, uint16_t data)
+{
+       assert(ldns_buffer_available_at(buffer, at, sizeof(data)));
+       ldns_write_uint16(buffer->_data + at, data);
+}
+
+/**
+ * writes the given 2 byte integer at the current position in the buffer
+ * \param[in] buffer the buffer
+ * \param[in] data the 16 bits to write
+ */
+INLINE void
+ldns_buffer_write_u16(ldns_buffer *buffer, uint16_t data)
+{
+       ldns_buffer_write_u16_at(buffer, buffer->_position, data);
+       buffer->_position += sizeof(data);
+}
+
+/**
+ * writes the given 4 byte integer at the given position in the buffer
+ * \param[in] buffer the buffer
+ * \param[in] at the position in the buffer
+ * \param[in] data the 32 bits to write
+ */
+INLINE void
+ldns_buffer_write_u32_at(ldns_buffer *buffer, size_t at, uint32_t data)
+{
+       assert(ldns_buffer_available_at(buffer, at, sizeof(data)));
+       ldns_write_uint32(buffer->_data + at, data);
+}
+
+/**
+ * writes the given 4 byte integer at the current position in the buffer
+ * \param[in] buffer the buffer
+ * \param[in] data the 32 bits to write
+ */
+INLINE void
+ldns_buffer_write_u32(ldns_buffer *buffer, uint32_t data)
+{
+       ldns_buffer_write_u32_at(buffer, buffer->_position, data);
+       buffer->_position += sizeof(data);
+}
+
+/**
+ * copies count bytes of data at the given position to the given data-array
+ * \param[in] buffer the buffer
+ * \param[in] at the position in the buffer to start
+ * \param[out] data buffer to copy to
+ * \param[in] count the length of the data to copy
+ */
+INLINE void
+ldns_buffer_read_at(ldns_buffer *buffer, size_t at, void *data, size_t count)
+{
+       assert(ldns_buffer_available_at(buffer, at, count));
+       memcpy(data, buffer->_data + at, count);
+}
+
+/**
+ * copies count bytes of data at the current position to the given data-array
+ * \param[in] buffer the buffer
+ * \param[out] data buffer to copy to
+ * \param[in] count the length of the data to copy
+ */
+INLINE void
+ldns_buffer_read(ldns_buffer *buffer, void *data, size_t count)
+{
+       ldns_buffer_read_at(buffer, buffer->_position, data, count);
+       buffer->_position += count;
+}
+
+/**
+ * returns the byte value at the given position in the buffer
+ * \param[in] buffer the buffer
+ * \param[in] at the position in the buffer
+ * \return 1 byte integer
+ */
+INLINE uint8_t
+ldns_buffer_read_u8_at(ldns_buffer *buffer, size_t at)
+{
+       assert(ldns_buffer_available_at(buffer, at, sizeof(uint8_t)));
+       return buffer->_data[at];
+}
+
+/**
+ * returns the byte value at the current position in the buffer
+ * \param[in] buffer the buffer
+ * \return 1 byte integer
+ */
+INLINE uint8_t
+ldns_buffer_read_u8(ldns_buffer *buffer)
+{
+       uint8_t result = ldns_buffer_read_u8_at(buffer, buffer->_position);
+       buffer->_position += sizeof(uint8_t);
+       return result;
+}
+
+/**
+ * returns the 2-byte integer value at the given position in the buffer
+ * \param[in] buffer the buffer
+ * \param[in] at position in the buffer
+ * \return 2 byte integer
+ */
+INLINE uint16_t
+ldns_buffer_read_u16_at(ldns_buffer *buffer, size_t at)
+{
+       assert(ldns_buffer_available_at(buffer, at, sizeof(uint16_t)));
+       return ldns_read_uint16(buffer->_data + at);
+}
+
+/**
+ * returns the 2-byte integer value at the current position in the buffer
+ * \param[in] buffer the buffer
+ * \return 2 byte integer
+ */
+INLINE uint16_t
+ldns_buffer_read_u16(ldns_buffer *buffer)
+{
+       uint16_t result = ldns_buffer_read_u16_at(buffer, buffer->_position);
+       buffer->_position += sizeof(uint16_t);
+       return result;
+}
+
+/**
+ * returns the 4-byte integer value at the given position in the buffer
+ * \param[in] buffer the buffer
+ * \param[in] at position in the buffer
+ * \return 4 byte integer
+ */
+INLINE uint32_t
+ldns_buffer_read_u32_at(ldns_buffer *buffer, size_t at)
+{
+       assert(ldns_buffer_available_at(buffer, at, sizeof(uint32_t)));
+       return ldns_read_uint32(buffer->_data + at);
+}
+
+/**
+ * returns the 4-byte integer value at the current position in the buffer
+ * \param[in] buffer the buffer
+ * \return 4 byte integer
+ */
+INLINE uint32_t
+ldns_buffer_read_u32(ldns_buffer *buffer)
+{
+       uint32_t result = ldns_buffer_read_u32_at(buffer, buffer->_position);
+       buffer->_position += sizeof(uint32_t);
+       return result;
+}
+
+/**
+ * returns the status of the buffer
+ * \param[in] buffer
+ * \return the status
+ */
+INLINE int
+ldns_buffer_status(ldns_buffer *buffer)
+{
+       return (int)buffer->_status_err;
+}
+
+/**
+ * returns true if the status of the buffer is LDNS_STATUS_OK, false otherwise
+ * \param[in] buffer the buffer
+ * \return true or false
+ */
+INLINE int
+ldns_buffer_status_ok(ldns_buffer *buffer)
+{
+       if (buffer) {
+               return ldns_buffer_status(buffer) == 0;
+       } else {
+               return 0;
+       }
+}
+
+/**
+ * prints to the buffer, increasing the capacity if required using
+ * buffer_reserve(). The buffer's position is set to the terminating '\\0'
+ * Returns the number of characters written (not including the
+ * terminating '\\0') or -1 on failure.
+ */
+int ldns_buffer_printf(ldns_buffer *buffer, const char *format, ...)
+       ATTR_FORMAT(printf, 2, 3);
+
+/**
+ * frees the buffer.
+ * \param[in] *buffer the buffer to be freed
+ * \return void
+ */
+void ldns_buffer_free(ldns_buffer *buffer);
+
+/**
+ * Makes the buffer fixed and returns a pointer to the data.  The
+ * caller is responsible for free'ing the result.
+ * \param[in] *buffer the buffer to be exported
+ * \return void
+ */
+void *ldns_buffer_export(ldns_buffer *buffer);
+
+/**
+ * Copy contents of the from buffer to the result buffer and then flips 
+ * the result buffer. Data will be silently truncated if the result buffer is
+ * too small.
+ * \param[out] *result resulting buffer which is copied to.
+ * \param[in] *from what to copy to result.
+ */
+void ldns_buffer_copy(ldns_buffer* result, ldns_buffer* from);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LDNS_SBUFFER_H */
diff --git a/ldns/str2wire.c b/ldns/str2wire.c
new file mode 100644 (file)
index 0000000..b3f75bd
--- /dev/null
@@ -0,0 +1,1840 @@
+/**
+ * str2wire.c - read txt presentation of RRs
+ *
+ * (c) NLnet Labs, 2005-2006
+ *
+ * See the file LICENSE for the license
+ */
+
+/**
+ * \file
+ *
+ * Parses text to wireformat.
+ */
+#include "config.h"
+#include "ldns/str2wire.h"
+#include "ldns/wire2str.h"
+#include "ldns/sbuffer.h"
+#include "ldns/parse.h"
+#include "ldns/parseutil.h"
+#include <ctype.h>
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+/** return an error */
+#define RET_ERR(e, off) ((int)((e)|((off)<<LDNS_WIREPARSE_SHIFT)))
+/** Move parse error but keep its ID */
+#define RET_ERR_SHIFT(e, move) RET_ERR(LDNS_WIREPARSE_ERROR(e), LDNS_WIREPARSE_OFFSET(e)+(move));
+#define LDNS_IP6ADDRLEN      (128/8)
+
+/*
+ * No special care is taken, all dots are translated into
+ * label seperators.
+ * @param rel: true if the domain is not absolute (not terminated in .).
+ *     The output is then still terminated with a '0' rootlabel.
+ */
+static int ldns_str2wire_dname_buf_rel(const char* str, uint8_t* buf,
+       size_t* olen, int* rel)
+{
+       size_t len;
+
+       const char *s;
+       uint8_t *q, *pq, label_len;
+
+       if(rel) *rel = 0;
+       len = strlen((char*)str);
+       /* octet representation can make strings a lot longer than actual length */
+       if (len > LDNS_MAX_DOMAINLEN * 4) {
+               return RET_ERR(LDNS_WIREPARSE_ERR_DOMAINNAME_OVERFLOW, 0);
+       }
+       if (0 == len) {
+               return RET_ERR(LDNS_WIREPARSE_ERR_DOMAINNAME_UNDERFLOW, 0);
+       }
+
+       /* root label */
+       if (1 == len && *str == '.') {
+               if(*olen < 1)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, 0);
+               buf[0] = 0;
+               *olen = 1;
+               return LDNS_WIREPARSE_ERR_OK;
+       }
+
+       /* get on with the rest */
+
+       /* s is on the current character in the string
+         * pq points to where the labellength is going to go
+         * label_len keeps track of the current label's length
+        * q builds the dname inside the buf array
+        */
+       len = 0;
+       if(*olen < 1)
+               return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, 0);
+       q = buf+1;
+       pq = buf;
+       label_len = 0;
+       for (s = str; *s; s++, q++) {
+               if (q >= buf + *olen)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, q-buf);
+               if (q > buf + LDNS_MAX_DOMAINLEN)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_DOMAINNAME_OVERFLOW, q-buf);
+               switch (*s) {
+               case '.':
+                       if (label_len > LDNS_MAX_LABELLEN) {
+                               return RET_ERR(LDNS_WIREPARSE_ERR_LABEL_OVERFLOW, q-buf);
+                       }
+                       if (label_len == 0) {
+                               return RET_ERR(LDNS_WIREPARSE_ERR_EMPTY_LABEL, q-buf);
+                       }
+                       len += label_len + 1;
+                       *q = 0;
+                       *pq = label_len;
+                       label_len = 0;
+                       pq = q;
+                       break;
+               case '\\':
+                       /* octet value or literal char */
+                       s += 1;
+                       if (!ldns_parse_escape(q, &s)) {
+                               *q = 0;
+                               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_BAD_ESCAPE, q-buf);
+                       }
+                       s -= 1;
+                       label_len++;
+                       break;
+               default:
+                       *q = (uint8_t)*s;
+                       label_len++;
+               }
+       }
+
+       /* add root label if last char was not '.' */
+       if(label_len != 0) {
+               if(rel) *rel = 1;
+               if (q >= buf + *olen)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, q-buf);
+               if (q > buf + LDNS_MAX_DOMAINLEN) {
+                       return RET_ERR(LDNS_WIREPARSE_ERR_DOMAINNAME_OVERFLOW, q-buf);
+               }
+                if (label_len > LDNS_MAX_LABELLEN) {
+                        return RET_ERR(LDNS_WIREPARSE_ERR_LABEL_OVERFLOW, q-buf);
+                }
+                if (label_len == 0) { /* label_len 0 but not . at end? */
+                        return RET_ERR(LDNS_WIREPARSE_ERR_EMPTY_LABEL, q-buf);
+                }
+               len += label_len + 1;
+               *pq = label_len;
+               *q = 0;
+       }
+       len++;
+       *olen = len;
+
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_dname_buf(const char* str, uint8_t* buf, size_t* len)
+{
+       return ldns_str2wire_dname_buf_rel(str, buf, len, NULL);
+}
+
+int ldns_str2wire_dname_buf_origin(const char* str, uint8_t* buf, size_t* len,
+       uint8_t* origin, size_t origin_len)
+{
+       size_t dlen = *len;
+       int rel = 0;
+       int s = ldns_str2wire_dname_buf_rel(str, buf, &dlen, &rel);
+       if(s) return s;
+
+       if(rel && origin && dlen > 0) {
+               if(dlen + origin_len - 1 > LDNS_MAX_DOMAINLEN)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_DOMAINNAME_OVERFLOW,
+                               LDNS_MAX_DOMAINLEN);
+               if(dlen + origin_len - 1 > *len)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                               *len);
+               memmove(buf+dlen-1, origin, origin_len);
+               *len = dlen + origin_len - 1;
+       } else
+               *len = dlen;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+uint8_t* ldns_str2wire_dname(const char* str, size_t* len)
+{
+       uint8_t dname[LDNS_MAX_DOMAINLEN+1];
+       *len = sizeof(dname);
+       if(ldns_str2wire_dname_buf(str, dname, len) == 0) {
+               uint8_t* r = (uint8_t*)malloc(*len);
+               if(r) memcpy(r, dname, *len);
+               return r;
+       }
+       *len = 0;
+       return NULL;
+}
+
+/** read owner name */
+static int
+rrinternal_get_owner(ldns_buffer* strbuf, uint8_t* rr, size_t* len,
+       size_t* dname_len, uint8_t* origin, size_t origin_len, uint8_t* prev,
+       size_t prev_len, char* token, size_t token_len)
+{
+       /* split the rr in its parts -1 signals trouble */
+       if(ldns_bget_token(strbuf, token, "\t\n ", token_len) == -1) {
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX,
+                       ldns_buffer_position(strbuf));
+       }
+
+       if(strcmp(token, "@") == 0) {
+               uint8_t* tocopy;
+               if (origin) {
+                       *dname_len = origin_len;
+                       tocopy = origin;
+               } else if (prev) {
+                       *dname_len = prev_len;
+                       tocopy = prev;
+               } else {
+                       /* default to root */
+                       *dname_len = 1;
+                       tocopy = (uint8_t*)"\0";
+               }
+               if(*len < *dname_len)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                               ldns_buffer_position(strbuf));
+               memmove(rr, tocopy, *dname_len);
+       } else if(strlen(token) == 0) {
+               /* no ownername was given, try prev, if that fails
+                * origin, else default to root */
+               uint8_t* tocopy;
+               if(prev) {
+                       *dname_len = prev_len;
+                       tocopy = prev;
+               } else if(origin) {
+                       *dname_len = origin_len;
+                       tocopy = origin;
+               } else {
+                       *dname_len = 1;
+                       tocopy = (uint8_t*)"\0";
+               }
+               if(*len < *dname_len)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                               ldns_buffer_position(strbuf));
+               memmove(rr, tocopy, *dname_len);
+       } else {
+               size_t dlen = *len;
+               int s = ldns_str2wire_dname_buf_origin(token, rr, &dlen,
+                       origin, origin_len);
+               if(s) return RET_ERR_SHIFT(s,
+                       ldns_buffer_position(strbuf)-strlen(token));
+               *dname_len = dlen;
+       }
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/** read ttl */
+static int
+rrinternal_get_ttl(ldns_buffer* strbuf, char* token, size_t token_len,
+       int* not_there, uint32_t* ttl, uint32_t default_ttl)
+{
+       const char* endptr;
+       if(ldns_bget_token(strbuf, token, "\t\n ", token_len) == -1) {
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_TTL,
+                       ldns_buffer_position(strbuf));
+       }
+       *ttl = (uint32_t) ldns_str2period(token, &endptr);
+
+       if (strlen(token) > 0 && !isdigit((int)token[0])) {
+               *not_there = 1;
+               /* ah, it's not there or something */
+               if (default_ttl == 0) {
+                       *ttl = LDNS_DEFAULT_TTL;
+               } else {
+                       *ttl = default_ttl;
+               }
+       }
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/** read class */
+static int
+rrinternal_get_class(ldns_buffer* strbuf, char* token, size_t token_len,
+       int* not_there, uint16_t* cl)
+{
+       /* if 'not_there' then we got token from previous parse routine */
+       if(!*not_there) {
+               /* parse new token for class */
+               if(ldns_bget_token(strbuf, token, "\t\n ", token_len) == -1) {
+                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_CLASS,
+                               ldns_buffer_position(strbuf));
+               }
+       } else *not_there = 0;
+       *cl = ldns_get_rr_class_by_name(token);
+       /* class can be left out too, assume IN, current token must be type */
+       if(*cl == 0 && strcmp(token, "CLASS0") != 0) {
+               *not_there = 1;
+               *cl = LDNS_RR_CLASS_IN;
+       }
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/** read type */
+static int
+rrinternal_get_type(ldns_buffer* strbuf, char* token, size_t token_len,
+       int* not_there, uint16_t* tp)
+{
+       /* if 'not_there' then we got token from previous parse routine */
+       if(!*not_there) {
+               /* parse new token for type */
+               if(ldns_bget_token(strbuf, token, "\t\n ", token_len) == -1) {
+                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_TYPE,
+                               ldns_buffer_position(strbuf));
+               }
+       }
+       *tp = ldns_get_rr_type_by_name(token);
+       if(*tp == 0 && strcmp(token, "TYPE0") != 0) {
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_TYPE,
+                       ldns_buffer_position(strbuf));
+       }
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/** put type, class, ttl into rr buffer */
+static int
+rrinternal_writetype(ldns_buffer* strbuf, uint8_t* rr, size_t len,
+       size_t dname_len, uint16_t tp, uint16_t cl, uint32_t ttl, int question)
+{
+       if(question) {
+               /* question is : name, type, class */
+               if(dname_len + 4 > len)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                               ldns_buffer_position(strbuf));
+               ldns_write_uint16(rr+dname_len, tp);
+               ldns_write_uint16(rr+dname_len+2, cl);
+               return LDNS_WIREPARSE_ERR_OK;
+       }
+
+       /* type(2), class(2), ttl(4), rdatalen(2 (later)) = 10 */
+       if(dname_len + 10 > len)
+               return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                       ldns_buffer_position(strbuf));
+       ldns_write_uint16(rr+dname_len, tp);
+       ldns_write_uint16(rr+dname_len+2, cl);
+       ldns_write_uint32(rr+dname_len+4, ttl);
+       ldns_write_uint16(rr+dname_len+8, 0); /* rdatalen placeholder */
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/** find delimiters for type */
+static const char*
+rrinternal_get_delims(ldns_rdf_type rdftype, uint16_t r_cnt, uint16_t r_max)
+{
+       switch(rdftype) {
+       case LDNS_RDF_TYPE_B64        :
+       case LDNS_RDF_TYPE_HEX        : /* These rdf types may con- */
+       case LDNS_RDF_TYPE_LOC        : /* tain whitespace, only if */
+       case LDNS_RDF_TYPE_WKS        : /* it is the last rd field. */
+       case LDNS_RDF_TYPE_IPSECKEY   :
+       case LDNS_RDF_TYPE_NSEC       : if (r_cnt == r_max - 1) {
+                                               return "\n\t";
+                                       }
+                                       break;
+       default                       : break;
+       }
+       return "\n\t "; 
+}
+
+/* Syntactic sugar for ldns_rr_new_frm_str_internal */
+static int
+ldns_rdf_type_maybe_quoted(ldns_rdf_type rdf_type)
+{
+       return  rdf_type == LDNS_RDF_TYPE_STR ||
+               rdf_type == LDNS_RDF_TYPE_LONG_STR;
+}
+
+/** see if rdata is quoted */
+static int
+rrinternal_get_quoted(ldns_buffer* strbuf, const char** delimiters,
+       ldns_rdf_type rdftype)
+{
+       if(ldns_rdf_type_maybe_quoted(rdftype) &&
+               ldns_buffer_remaining(strbuf) > 0) {
+
+               /* skip spaces */
+               while(ldns_buffer_remaining(strbuf) > 0 &&
+                       *(ldns_buffer_current(strbuf)) == ' ') {
+                       ldns_buffer_skip(strbuf, 1);
+               }
+
+               if(ldns_buffer_remaining(strbuf) > 0 &&
+                       *(ldns_buffer_current(strbuf)) == '\"') {
+                       *delimiters = "\"\0";
+                       ldns_buffer_skip(strbuf, 1);
+                       return 1;
+               }
+       }
+       return 0;
+}
+
+/** spool hex data into rdata */
+static int
+rrinternal_spool_hex(char* token, uint8_t* rr, size_t rr_len,
+       size_t rr_cur_len, size_t* cur_hex_data_size, size_t hex_data_size)
+{
+       char* p = token;
+       while(*p) {
+               if(isspace(*p)) {
+                       p++;
+                       continue;
+               }
+               if(!isxdigit(*p))
+                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_RDATA,
+                               p-token);
+               if(*cur_hex_data_size >= hex_data_size)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_RDATA,
+                               p-token);
+               /* extra robust check */
+               if(rr_cur_len+(*cur_hex_data_size)/2 >= rr_len)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                               p-token);
+               /* see if 16s or 1s */
+               if( ((*cur_hex_data_size)&1) == 0) {
+                       rr[rr_cur_len+(*cur_hex_data_size)/2] =
+                               (uint8_t)ldns_hexdigit_to_int(*p)*16;
+               } else {
+                       rr[rr_cur_len+(*cur_hex_data_size)/2] =
+                               (uint8_t)ldns_hexdigit_to_int(*p);
+               }
+               (*cur_hex_data_size)++;
+       }
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/** read unknown rr type format */
+static int
+rrinternal_parse_unknown(ldns_buffer* strbuf, char* token, size_t token_len,
+        uint8_t* rr, size_t* rr_len, size_t* rr_cur_len, size_t pre_data_pos)
+{
+       const char* delim = "\n\t ";
+       size_t hex_data_size, cur_hex_data_size;
+       /* go back to before \#
+        * and skip it while setting delimiters better
+        */
+       ldns_buffer_set_position(strbuf, pre_data_pos);
+       if(ldns_bget_token(strbuf, token, delim, token_len) == -1)
+               return LDNS_WIREPARSE_ERR_GENERAL; /* should not fail */
+       /* read rdata octet length */
+       if(ldns_bget_token(strbuf, token, delim, token_len) == -1) {
+               /* something goes very wrong here */
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_RDATA,
+                       ldns_buffer_position(strbuf));
+       }
+       hex_data_size = (size_t)atoi(token);
+       if(hex_data_size > LDNS_MAX_RDFLEN || 
+               *rr_cur_len + hex_data_size > *rr_len) {
+               return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                       ldns_buffer_position(strbuf));
+       }
+       /* copy hex chars into hex str (2 chars per byte) */
+       hex_data_size *= 2;
+       cur_hex_data_size = 0;
+       while(cur_hex_data_size < hex_data_size) {
+               int status;
+               ssize_t c = ldns_bget_token(strbuf, token, delim, token_len);
+               if((status = rrinternal_spool_hex(token, rr, *rr_len,
+                       *rr_cur_len, &cur_hex_data_size, hex_data_size)) != 0)
+                       return RET_ERR_SHIFT(status,
+                               ldns_buffer_position(strbuf)-strlen(token));
+               if(c == -1) {
+                       if(cur_hex_data_size != hex_data_size)
+                               return RET_ERR(
+                                       LDNS_WIREPARSE_ERR_SYNTAX_RDATA,
+                                       ldns_buffer_position(strbuf));
+                       break;
+               }
+       }
+       *rr_cur_len += hex_data_size/2;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/** parse normal RR rdata element */
+static int
+rrinternal_parse_rdf(ldns_buffer* strbuf, char* token, size_t token_len,
+       uint8_t* rr, size_t rr_len, size_t* rr_cur_len, ldns_rdf_type rdftype,
+       uint16_t rr_type, uint16_t r_cnt, uint16_t r_max, size_t dname_len,
+       uint8_t* origin, size_t origin_len)
+{
+       size_t len;
+       int status;
+
+       switch(rdftype) {
+       case LDNS_RDF_TYPE_DNAME:
+               /* check if the origin should be used or concatenated */
+               if(strcmp(token, "@") == 0) {
+                       uint8_t* tocopy;
+                       size_t copylen;
+                       if(origin) {
+                               copylen = origin_len;
+                               tocopy = origin;
+                       } else if(rr_type == LDNS_RR_TYPE_SOA) {
+                               copylen = dname_len;
+                               tocopy = rr; /* copy rr owner name */
+                       } else {
+                               copylen = 1;
+                               tocopy = (uint8_t*)"\0";
+                       }
+                       if((*rr_cur_len) + copylen > rr_len)
+                               return RET_ERR(
+                                       LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                                       ldns_buffer_position(strbuf));
+                       memmove(rr+*rr_cur_len, tocopy, copylen);
+                       (*rr_cur_len) += copylen;
+               } else {
+                       size_t dlen = rr_len - (*rr_cur_len);
+                       int s = ldns_str2wire_dname_buf_origin(token,
+                               rr+*rr_cur_len, &dlen, origin, origin_len);
+                       if(s) return RET_ERR_SHIFT(s,
+                               ldns_buffer_position(strbuf)-strlen(token));
+                       (*rr_cur_len) += dlen;
+               }
+               return LDNS_WIREPARSE_ERR_OK;
+
+       case LDNS_RDF_TYPE_HEX:
+       case LDNS_RDF_TYPE_B64:
+               /* When this is the last rdata field, then the
+                * rest should be read in (cause then these
+                * rdf types may contain spaces). */
+               if(r_cnt == r_max - 1) {
+                       size_t tlen = strlen(token);
+                       (void)ldns_bget_token(strbuf, token+tlen, "\n",
+                               token_len - tlen);
+               }
+               break;
+       default:
+               break;
+       }
+
+       len = rr_len - (*rr_cur_len);
+       if((status=ldns_str2wire_rdf_buf(token, rr+(*rr_cur_len), &len,
+               rdftype)) != 0)
+               return RET_ERR_SHIFT(status,
+                       ldns_buffer_position(strbuf)-strlen(token));
+       *rr_cur_len += len;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/** parse rdata from string into rr buffer(-remainder after dname). */
+static int
+rrinternal_parse_rdata(ldns_buffer* strbuf, char* token, size_t token_len,
+       uint8_t* rr, size_t* rr_len, size_t dname_len, uint16_t rr_type,
+       uint8_t* origin, size_t origin_len)
+{
+       const ldns_rr_descriptor *desc = ldns_rr_descript((uint16_t)rr_type);
+       uint16_t r_cnt, r_min, r_max;
+       size_t rr_cur_len = dname_len + 10, pre_data_pos, token_strlen;
+       int was_unknown_rr_format = 0, parens = 0, status, quoted;
+       const char* delimiters;
+       ldns_rdf_type rdftype;
+       /* a desc is always returned */
+       if(!desc) return LDNS_WIREPARSE_ERR_GENERAL;
+       r_max = ldns_rr_descriptor_maximum(desc);
+       r_min = ldns_rr_descriptor_minimum(desc);
+       /* robust check */
+       if(rr_cur_len > *rr_len)
+               return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                       ldns_buffer_position(strbuf));
+
+       /* because number of fields can be variable, we can't rely on
+        * _maximum() only */
+       for(r_cnt=0; r_cnt < r_max; r_cnt++) {
+               rdftype = ldns_rr_descriptor_field_type(desc, r_cnt);
+               delimiters = rrinternal_get_delims(rdftype, r_cnt, r_max);
+               quoted = rrinternal_get_quoted(strbuf, &delimiters, rdftype);
+
+               /* skip spaces */
+               while(ldns_buffer_remaining(strbuf) > 0 && !quoted &&
+                       *(ldns_buffer_current(strbuf)) == ' ') {
+                       ldns_buffer_skip(strbuf, 1);
+               }
+
+               pre_data_pos = ldns_buffer_position(strbuf);
+               if(ldns_bget_token_par(strbuf, token, delimiters, token_len,
+                       &parens, quoted?NULL:" \t") == -1) {
+                       break;
+               }
+               /* hmmz, rfc3597 specifies that any type can be represented
+                * with \# method, which can contain spaces...
+                * it does specify size though... */
+               token_strlen = strlen(token);
+
+               /* unknown RR data */
+               if(token_strlen>=2 && strncmp(token, "\\#", 2) == 0 &&
+                       !quoted && (token_strlen == 2 || token[2]==' ')) {
+                       was_unknown_rr_format = 1;
+                       if((status=rrinternal_parse_unknown(strbuf, token,
+                               token_len, rr, rr_len, &rr_cur_len, 
+                               pre_data_pos)) != 0)
+                               return status;
+               } else {
+                       /* normal RR */
+                       if((status=rrinternal_parse_rdf(strbuf, token,
+                               token_len, rr, *rr_len, &rr_cur_len, rdftype,
+                               rr_type, r_cnt, r_max, dname_len, origin,
+                               origin_len)) != 0) {
+                               return status;
+                       }
+               }
+               if(quoted) {
+                       if(ldns_buffer_available(strbuf, 1))
+                               ldns_buffer_skip(strbuf, 1);
+                       else    break;
+               }
+       }
+       if(!was_unknown_rr_format && r_cnt+1 < r_min) {
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_MISSING_VALUE,
+                       ldns_buffer_position(strbuf));
+       }
+       while(parens != 0) {
+               /* read remainder, must be "" */
+               if(ldns_bget_token_par(strbuf, token, "\n", token_len,
+                       &parens, " \t") == -1) {
+                       if(parens != 0)
+                               return RET_ERR(LDNS_WIREPARSE_ERR_PARENTHESIS,
+                                       ldns_buffer_position(strbuf));
+                       break;
+               }
+               if(strcmp(token, "") != 0)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_PARENTHESIS,
+                               ldns_buffer_position(strbuf));
+       }
+       /* write rdata length */
+       ldns_write_uint16(rr+dname_len+8, rr_cur_len-dname_len-10);
+       *rr_len = rr_cur_len;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/*
+ * trailing spaces are allowed
+ * leading spaces are not allowed
+ * allow ttl to be optional
+ * class is optional too
+ * if ttl is missing, and default_ttl is 0, use DEF_TTL
+ * allow ttl to be written as 1d3h
+ * So the RR should look like. e.g.
+ * miek.nl. 3600 IN MX 10 elektron.atoom.net
+ * or
+ * miek.nl. 1h IN MX 10 elektron.atoom.net
+ * or
+ * miek.nl. IN MX 10 elektron.atoom.net
+ */
+static int
+ldns_str2wire_rr_buf_internal(const char* str, uint8_t* rr, size_t* len,
+       size_t* dname_len, uint32_t default_ttl, uint8_t* origin,
+       size_t origin_len, uint8_t* prev, size_t prev_len, int question)
+{
+       int status;
+       int not_there = 0;
+       char token[LDNS_MAX_RDFLEN+1];
+       uint32_t ttl;
+       uint16_t tp, cl;
+
+       /* string in buffer */
+       ldns_buffer strbuf;
+       ldns_buffer_init_frm_data(&strbuf, (uint8_t*)str, strlen(str));
+
+       /* parse the owner */
+       if((status=rrinternal_get_owner(&strbuf, rr, len, dname_len, origin,
+               origin_len, prev, prev_len, token, sizeof(token))) != 0)
+               return status;
+
+       /* parse the [ttl] [class] <type> */
+       if((status=rrinternal_get_ttl(&strbuf, token, sizeof(token),
+               &not_there, &ttl, default_ttl)) != 0)
+               return status;
+       if((status=rrinternal_get_class(&strbuf, token, sizeof(token),
+               &not_there, &cl)) != 0)
+               return status;
+       if((status=rrinternal_get_type(&strbuf, token, sizeof(token),
+               &not_there, &tp)) != 0)
+               return status;
+       /* put ttl, class, type into the rr result */
+       if((status=rrinternal_writetype(&strbuf, rr, *len, *dname_len, tp, cl,
+               ttl, question)) != 0)
+               return status;
+       /* for a question-RR we are done, no rdata */
+       if(question) {
+               *len = *dname_len + 4;
+               return LDNS_WIREPARSE_ERR_OK;
+       }
+
+       /* rdata */
+       if((status=rrinternal_parse_rdata(&strbuf, token, sizeof(token),
+               rr, len, *dname_len, tp, origin, origin_len)) != 0)
+               return status;
+
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_rr_buf(const char* str, uint8_t* rr, size_t* len,
+       size_t* dname_len, uint32_t default_ttl, uint8_t* origin,
+       size_t origin_len, uint8_t* prev, size_t prev_len)
+{
+       return ldns_str2wire_rr_buf_internal(str, rr, len, dname_len,
+               default_ttl, origin, origin_len, prev, prev_len, 0);
+}
+
+int ldns_str2wire_rr_question_buf(const char* str, uint8_t* rr, size_t* len,
+       size_t* dname_len, uint8_t* origin, size_t origin_len, uint8_t* prev,
+       size_t prev_len)
+{
+       return ldns_str2wire_rr_buf_internal(str, rr, len, dname_len,
+               0, origin, origin_len, prev, prev_len, 1);
+}
+
+uint16_t ldns_wirerr_get_type(uint8_t* rr, size_t len, size_t dname_len)
+{
+       if(len < dname_len+2)
+               return 0;
+       return ldns_read_uint16(rr+dname_len);
+}
+
+uint16_t ldns_wirerr_get_class(uint8_t* rr, size_t len, size_t dname_len)
+{
+       if(len < dname_len+4)
+               return 0;
+       return ldns_read_uint16(rr+dname_len+2);
+}
+
+uint32_t ldns_wirerr_get_ttl(uint8_t* rr, size_t len, size_t dname_len)
+{
+       if(len < dname_len+8)
+               return 0;
+       return ldns_read_uint32(rr+dname_len+4);
+}
+
+uint16_t ldns_wirerr_get_rdatalen(uint8_t* rr, size_t len, size_t dname_len)
+{
+       if(len < dname_len+10)
+               return 0;
+       return ldns_read_uint16(rr+dname_len+8);
+}
+
+uint8_t* ldns_wirerr_get_rdata(uint8_t* rr, size_t len, size_t dname_len)
+{
+       if(len < dname_len+10)
+               return NULL;
+       return rr+dname_len+10;
+}
+
+uint8_t* ldns_wirerr_get_rdatawl(uint8_t* rr, size_t len, size_t dname_len)
+{
+       if(len < dname_len+10)
+               return NULL;
+       return rr+dname_len+8;
+}
+
+const char* ldns_get_errorstr_parse(int e)
+{
+       ldns_lookup_table *lt;
+       lt = ldns_lookup_by_id(ldns_wireparse_errors, LDNS_WIREPARSE_ERROR(e));
+       return lt?lt->name:"unknown error";
+}
+
+int ldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len,
+       struct ldns_file_parse_state* parse_state)
+{
+       char line[LDNS_RR_BUF_SIZE+1];
+       ssize_t size;
+
+       /* read an entire line in from the file */
+       if((size = ldns_fget_token_l(in, line, LDNS_PARSE_SKIP_SPACE,
+               LDNS_RR_BUF_SIZE, parse_state?&parse_state->lineno:NULL))
+               == -1) {
+               /* if last line was empty, we are now at feof, which is not
+                * always a parse error (happens when for instance last line
+                * was a comment)
+                */
+               return LDNS_WIREPARSE_ERR_SYNTAX;
+       }
+
+       /* we can have the situation, where we've read ok, but still got
+        * no bytes to play with, in this case size is 0 */
+       if(size == 0) {
+               *len = 0;
+               *dname_len = 0;
+               return LDNS_WIREPARSE_ERR_OK;
+       }
+
+       if(strncmp(line, "$ORIGIN", 7) == 0 && isspace(line[7])) {
+               size_t off = 8;
+               int s;
+               *len = 0;
+               *dname_len = 0;
+               if(!parse_state) return LDNS_WIREPARSE_ERR_OK;
+               while(isspace(line[off]))
+                       off++;
+               parse_state->origin_len = sizeof(parse_state->origin);
+               s = ldns_str2wire_dname_buf(line+off, parse_state->origin,
+                       &parse_state->origin_len);
+               if(s) parse_state->origin_len = 0;
+               return s;
+       } else if(strncmp(line, "$TTL", 4) == 0 && isspace(line[4])) {
+               const char* end = NULL;
+               size_t off = 8;
+               *len = 0;
+               *dname_len = 0;
+               if(!parse_state) return LDNS_WIREPARSE_ERR_OK;
+               while(isspace(line[off]))
+                       off++;
+               parse_state->default_ttl = ldns_str2period(line+off, &end);
+       } else if (strncmp(line, "$INCLUDE", 8) == 0) {
+               *len = 0;
+               *dname_len = 0;
+               return LDNS_WIREPARSE_ERR_INCLUDE;
+       } else {
+               return ldns_str2wire_rr_buf(line, rr, len, dname_len,
+                       parse_state?parse_state->default_ttl:0,
+                       (parse_state&&parse_state->origin_len)?
+                               parse_state->origin:NULL,
+                       parse_state->origin_len,
+                       (parse_state&&parse_state->prev_rr_len)?
+                               parse_state->prev_rr:NULL,
+                       parse_state->prev_rr_len);
+       }
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_rdf_buf(const char* str, uint8_t* rd, size_t* len,
+       ldns_rdf_type rdftype)
+{
+       switch (rdftype) {
+       case LDNS_RDF_TYPE_DNAME:
+               return ldns_str2wire_dname_buf(str, rd, len);
+       case LDNS_RDF_TYPE_INT8:
+               return ldns_str2wire_int8_buf(str, rd, len);
+       case LDNS_RDF_TYPE_INT16:
+               return ldns_str2wire_int16_buf(str, rd, len);
+       case LDNS_RDF_TYPE_INT32:
+               return ldns_str2wire_int32_buf(str, rd, len);
+       case LDNS_RDF_TYPE_A:
+               return ldns_str2wire_a_buf(str, rd, len);
+       case LDNS_RDF_TYPE_AAAA:
+               return ldns_str2wire_aaaa_buf(str, rd, len);
+       case LDNS_RDF_TYPE_STR:
+               return ldns_str2wire_str_buf(str, rd, len);
+       case LDNS_RDF_TYPE_APL:
+               return ldns_str2wire_apl_buf(str, rd, len);
+       case LDNS_RDF_TYPE_B64:
+               return ldns_str2wire_b64_buf(str, rd, len);
+       case LDNS_RDF_TYPE_B32_EXT:
+               return ldns_str2wire_b32_ext_buf(str, rd, len);
+       case LDNS_RDF_TYPE_HEX:
+               return ldns_str2wire_hex_buf(str, rd, len);
+       case LDNS_RDF_TYPE_NSEC:
+               return ldns_str2wire_nsec_buf(str, rd, len);
+       case LDNS_RDF_TYPE_TYPE:
+               return ldns_str2wire_type_buf(str, rd, len);
+       case LDNS_RDF_TYPE_CLASS:
+               return ldns_str2wire_class_buf(str, rd, len);
+       case LDNS_RDF_TYPE_CERT_ALG:
+               return ldns_str2wire_cert_alg_buf(str, rd, len);
+       case LDNS_RDF_TYPE_ALG:
+               return ldns_str2wire_alg_buf(str, rd, len);
+       case LDNS_RDF_TYPE_TIME:
+               return ldns_str2wire_time_buf(str, rd, len);
+       case LDNS_RDF_TYPE_PERIOD:
+               return ldns_str2wire_period_buf(str, rd, len);
+       case LDNS_RDF_TYPE_LOC:
+               return ldns_str2wire_loc_buf(str, rd, len);
+       case LDNS_RDF_TYPE_WKS:
+               return ldns_str2wire_wks_buf(str, rd, len);
+       case LDNS_RDF_TYPE_NSAP:
+               return ldns_str2wire_nsap_buf(str, rd, len);
+       case LDNS_RDF_TYPE_ATMA:
+               return ldns_str2wire_atma_buf(str, rd, len);
+       case LDNS_RDF_TYPE_IPSECKEY:
+               return ldns_str2wire_ipseckey_buf(str, rd, len);
+       case LDNS_RDF_TYPE_NSEC3_SALT:
+               return ldns_str2wire_nsec3_salt_buf(str, rd, len);
+       case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER:
+               return ldns_str2wire_b32_ext_buf(str, rd, len);
+       case LDNS_RDF_TYPE_ILNP64:
+               return ldns_str2wire_ilnp64_buf(str, rd, len);
+       case LDNS_RDF_TYPE_EUI48:
+               return ldns_str2wire_eui48_buf(str, rd, len);
+       case LDNS_RDF_TYPE_EUI64:
+               return ldns_str2wire_eui64_buf(str, rd, len);
+       case LDNS_RDF_TYPE_TAG:
+               return ldns_str2wire_tag_buf(str, rd, len);
+       case LDNS_RDF_TYPE_LONG_STR:
+               return ldns_str2wire_long_str_buf(str, rd, len);
+       case LDNS_RDF_TYPE_INT16_DATA:
+               return ldns_str2wire_int16_data_buf(str, rd, len);
+       case LDNS_RDF_TYPE_UNKNOWN:
+       case LDNS_RDF_TYPE_SERVICE:
+               return LDNS_WIREPARSE_ERR_NOT_IMPL;
+       case LDNS_RDF_TYPE_NONE:
+       default:
+               break;
+       }
+       return LDNS_WIREPARSE_ERR_GENERAL;
+}
+
+int ldns_str2wire_int8_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       char* end;
+       uint8_t r = (uint8_t)strtol((char*)str, &end, 10);
+       if(*end != 0)
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_INT, end-(char*)str);
+       if(*len < 1)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       rd[0] = r;
+       *len = 1;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_int16_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       char* end;
+       uint16_t r = (uint16_t)strtol((char*)str, &end, 10);
+       if(*end != 0)
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_INT, end-(char*)str);
+       if(*len < 2)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       ldns_write_uint16(rd, r);
+       *len = 2;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_int32_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       char* end;
+       uint32_t r;
+       errno = 0; /* must set to zero before call,
+                       note race condition on errno */
+       if(*str == '-')
+               r = (uint32_t)strtol((char*)str, &end, 10);
+       else    r = (uint32_t)strtoul((char*)str, &end, 10);
+       if(*end != 0)
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_INT, end-(char*)str);
+       if(errno == ERANGE)
+               return LDNS_WIREPARSE_ERR_SYNTAX_INTEGER_OVERFLOW;
+       if(*len < 4)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       ldns_write_uint32(rd, r);
+       *len = 4;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_a_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       struct in_addr address;
+       if(inet_pton(AF_INET, (char*)str, &address) != 1)
+               return LDNS_WIREPARSE_ERR_SYNTAX_IP4;
+       if(*len < sizeof(address))
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       memmove(rd, &address, sizeof(address));
+       *len = sizeof(address);
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_aaaa_buf(const char* str, uint8_t* rd, size_t* len)
+{
+#ifdef AF_INET6
+       uint8_t address[LDNS_IP6ADDRLEN + 1];
+       if(inet_pton(AF_INET6, (char*)str, address) != 1)
+               return LDNS_WIREPARSE_ERR_SYNTAX_IP6;
+       if(*len < LDNS_IP6ADDRLEN)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       memmove(rd, address, LDNS_IP6ADDRLEN);
+       *len = LDNS_IP6ADDRLEN;
+       return LDNS_WIREPARSE_ERR_OK;
+#else
+       return LDNS_WIREPARSE_ERR_NOT_IMPL;
+#endif
+}
+
+int ldns_str2wire_str_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       uint8_t ch = 0;
+       size_t sl = 0;
+       const char* s = str;
+       /* skip length byte */
+       if(*len < 1)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       
+       /* read characters */
+       while(ldns_parse_char(&ch, &s)) {
+               if(sl >= 255)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_INVALID_STR, s-str);
+               if(*len < sl+1)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                               s-str);
+               rd[++sl] = ch;
+       }
+       if(!s)
+               return LDNS_WIREPARSE_ERR_SYNTAX_BAD_ESCAPE;
+       rd[0] = (uint8_t)sl;
+       *len = sl+1;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_apl_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       const char *my_str = str;
+
+       char my_ip_str[64];
+       size_t ip_str_len;
+
+       uint16_t family;
+       int negation;
+       size_t adflength = 0;
+       uint8_t data[16+4];
+       uint8_t prefix;
+       size_t i;
+
+       /* [!]afi:address/prefix */
+       if (strlen(my_str) < 2
+                       || strchr(my_str, ':') == NULL
+                       || strchr(my_str, '/') == NULL
+                       || strchr(my_str, ':') > strchr(my_str, '/')) {
+               return LDNS_WIREPARSE_ERR_INVALID_STR;
+       }
+
+       if (my_str[0] == '!') {
+               negation = 1;
+               my_str += 1;
+       } else {
+               negation = 0;
+       }
+
+       family = (uint16_t) atoi(my_str);
+
+       my_str = strchr(my_str, ':') + 1;
+
+       /* need ip addr and only ip addr for inet_pton */
+       ip_str_len = (size_t) (strchr(my_str, '/') - my_str);
+       if(ip_str_len+1 > sizeof(my_ip_str))
+               return LDNS_WIREPARSE_ERR_INVALID_STR;
+       (void)strlcpy(my_ip_str, my_str, sizeof(my_ip_str));
+
+       if (family == 1) {
+               /* ipv4 */
+               if(inet_pton(AF_INET, my_ip_str, data+4) == 0)
+                       return LDNS_WIREPARSE_ERR_INVALID_STR;
+               for (i = 0; i < 4; i++) {
+                       if (data[i+4] != 0) {
+                               adflength = i + 1;
+                       }
+               }
+       } else if (family == 2) {
+               /* ipv6 */
+               if (inet_pton(AF_INET6, my_ip_str, data+4) == 0)
+                       return LDNS_WIREPARSE_ERR_INVALID_STR;
+               for (i = 0; i < 16; i++) {
+                       if (data[i+4] != 0) {
+                               adflength = i + 1;
+                       }
+               }
+       } else {
+               /* unknown family */
+               return LDNS_WIREPARSE_ERR_INVALID_STR;
+       }
+
+       my_str = strchr(my_str, '/') + 1;
+       prefix = (uint8_t) atoi(my_str);
+
+       ldns_write_uint16(data, family);
+       data[2] = prefix;
+       data[3] = (uint8_t)adflength;
+       if (negation) {
+               /* set bit 1 of byte 3 */
+               data[3] = data[3] | 0x80;
+       }
+
+       if(*len < 4+adflength)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       memmove(rd, data, 4+adflength);
+       *len = 4+adflength;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_b64_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       size_t sz = ldns_b64_pton_calculate_size(strlen(str));
+       int n;
+       if(*len < sz)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       n = ldns_b64_pton(str, rd, *len);
+       if(n < 0)
+               return LDNS_WIREPARSE_ERR_SYNTAX_B64;
+       *len = (size_t)n;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_b32_ext_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       size_t slen = strlen(str);
+       size_t sz = ldns_b32_pton_calculate_size(slen);
+       int n;
+       if(*len < 1+sz)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       rd[0] = (uint8_t)sz;
+       n = ldns_b32_pton_extended_hex(str, slen, rd+1, *len-1);
+       if(n < 0)
+               return LDNS_WIREPARSE_ERR_SYNTAX_B32_EXT;
+       *len = (size_t)n+1;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_hex_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       const char* s = str;
+       size_t dlen = 0; /* number of hexdigits parsed */
+       while(*s) {
+               if(isspace(*s)) {
+                       s++;
+                       continue;
+               }
+               if(!isxdigit(*s))
+                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str);
+               if(*len < dlen/2 + 1)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                               s-str);
+               if((dlen&1)==0)
+                       rd[dlen/2] = (uint8_t)ldns_hexdigit_to_int(*s++) * 16;
+               else    rd[dlen/2] += (uint8_t)ldns_hexdigit_to_int(*s++);
+               dlen++;
+       }
+       if((dlen&1)!=0)
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str);
+       *len = dlen/2;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_nsec_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       const char *delim = "\n\t ";
+       char token[64]; /* for a type name */
+       size_t type_count = 0;
+       int block;
+       size_t used = 0;
+       uint16_t maxtype = 0;
+       uint8_t typebits[8192]; /* 65536 bits */
+       uint8_t window_in_use[256];
+
+       /* string in buffer */
+       ldns_buffer strbuf;
+       ldns_buffer_init_frm_data(&strbuf, (uint8_t*)str, strlen(str));
+
+       /* parse the types */
+       memset(typebits, 0, sizeof(typebits));
+       memset(window_in_use, 0, sizeof(window_in_use));
+       while(ldns_buffer_remaining(&strbuf) > 0 &&
+               ldns_bget_token(&strbuf, token, delim, sizeof(token)) != -1) {
+               uint16_t t = ldns_get_rr_type_by_name(token);
+               if(token[0] == 0)
+                       continue;
+               if(t == 0 && strcmp(token, "TYPE0") != 0)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_TYPE,
+                               ldns_buffer_position(&strbuf));
+               typebits[t/8] |= (0x80>>(t%8));
+               window_in_use[t/256] = 1;
+               type_count++;
+               if(t > maxtype) maxtype = t;
+       }
+
+       /* empty NSEC bitmap */
+       if(type_count == 0) {
+               *len = 0;
+               return LDNS_WIREPARSE_ERR_OK;
+       }
+
+       /* encode windows {u8 windowblock, u8 bitmaplength, 0-32u8 bitmap},
+        * block is 0-255 upper octet of types, length if 0-32. */
+       for(block = 0; block <= (int)maxtype/256; block++) {
+               int i, blocklen = 0;
+               if(!window_in_use[block])
+                       continue;
+               for(i=0; i<32; i++) {
+                       if(typebits[block*32+i] != 0)
+                               blocklen = i+1;
+               }
+               if(blocklen == 0)
+                       continue; /* empty window should have been !in_use */
+               if(used+blocklen+2 > *len)
+                       return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+               rd[used+0] = (uint8_t)block;
+               rd[used+1] = (uint8_t)blocklen;
+               for(i=0; i<blocklen; i++) {
+                       rd[used+2+i] = typebits[block*32+i];
+               }
+               used += blocklen+2;
+       }
+       *len = used;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_type_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       uint16_t t = ldns_get_rr_type_by_name(str);
+       if(t == 0 && strcmp(str, "TYPE0") != 0)
+               return LDNS_WIREPARSE_ERR_SYNTAX_TYPE;
+       if(*len < 2)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       ldns_write_uint16(rd, t);
+       *len = 2;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_class_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       uint16_t c = ldns_get_rr_class_by_name(str);
+       if(c == 0 && strcmp(str, "CLASS0") != 0)
+               return LDNS_WIREPARSE_ERR_SYNTAX_CLASS;
+       if(*len < 2)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       ldns_write_uint16(rd, c);
+       *len = 2;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/* An certificate alg field can either be specified as a 8 bits number
+ * or by its symbolic name. Handle both */
+int ldns_str2wire_cert_alg_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       ldns_lookup_table *lt = ldns_lookup_by_name(ldns_cert_algorithms, str);
+       if(*len < 2)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       if(lt) {
+               ldns_write_uint16(rd, (uint16_t)lt->id);
+       } else {
+               int s = ldns_str2wire_int16_buf(str, rd, len);
+               if(s) return s;
+               if(ldns_read_uint16(rd) == 0)
+                       return LDNS_WIREPARSE_ERR_CERT_BAD_ALGORITHM;
+       }
+       *len = 2;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/* An alg field can either be specified as a 8 bits number
+ * or by its symbolic name. Handle both */
+int ldns_str2wire_alg_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       ldns_lookup_table *lt = ldns_lookup_by_name(ldns_algorithms, str);
+       if(*len < 1)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       if(lt) {
+               rd[0] = (uint8_t)lt->id;
+               *len = 1;
+       } else {
+               /* try as-is (a number) */
+               return ldns_str2wire_int8_buf(str, rd, len);
+       }
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_time_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       /* convert a time YYYYDDMMHHMMSS to wireformat */
+       struct tm tm;
+       if(*len < 4)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+
+       /* Try to scan the time... */
+       memset(&tm, 0, sizeof(tm));
+       if (strlen(str) == 14 && sscanf(str, "%4d%2d%2d%2d%2d%2d",
+               &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour,
+               &tm.tm_min, &tm.tm_sec) == 6) {
+               tm.tm_year -= 1900;
+               tm.tm_mon--;
+               /* Check values */
+               if (tm.tm_year < 70)
+                       return LDNS_WIREPARSE_ERR_SYNTAX_TIME;
+               if (tm.tm_mon < 0 || tm.tm_mon > 11)
+                       return LDNS_WIREPARSE_ERR_SYNTAX_TIME;
+               if (tm.tm_mday < 1 || tm.tm_mday > 31)
+                       return LDNS_WIREPARSE_ERR_SYNTAX_TIME;
+               if (tm.tm_hour < 0 || tm.tm_hour > 23)
+                       return LDNS_WIREPARSE_ERR_SYNTAX_TIME;
+               if (tm.tm_min < 0 || tm.tm_min > 59)
+                       return LDNS_WIREPARSE_ERR_SYNTAX_TIME;
+               if (tm.tm_sec < 0 || tm.tm_sec > 59)
+                       return LDNS_WIREPARSE_ERR_SYNTAX_TIME;
+
+               ldns_write_uint32(rd, ldns_mktime_from_utc(&tm));
+       } else {
+               /* handle it as 32 bits timestamp */
+               char *end;
+               uint32_t l = (uint32_t)strtol((char*)str, &end, 10);
+               if(*end != 0)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_TIME,
+                               end-(char*)str);
+               ldns_write_uint32(rd, l);
+       }
+       *len = 4;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_period_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       const char* end;
+       uint32_t p = ldns_str2period(str, &end);
+       if(*end != 0)
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_PERIOD, end-str);
+       if(*len < 4)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       ldns_write_uint32(rd, p);
+       *len = 4;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+/** read "<digits>[.<digits>][mM]" into mantissa exponent format for LOC type */
+static int
+loc_parse_cm(char* my_str, char** endstr, uint8_t* m, uint8_t* e)
+{
+       uint32_t meters = 0, cm = 0, val;
+       while (isblank(*my_str)) {
+               my_str++;
+       }
+       meters = (uint32_t)strtol(my_str, &my_str, 10);
+       if (*my_str == '.') {
+               my_str++;
+               cm = (uint32_t)strtol(my_str, &my_str, 10);
+       }
+       if (meters >= 1) {
+               *e = 2;
+               val = meters;
+       } else  {
+               *e = 0;
+               val = cm;
+       }
+       while(val >= 10) {
+               (*e)++;
+               val /= 10;
+       }
+       *m = (uint8_t)val;
+
+       if (*e > 9)
+               return 0;
+       if (*my_str == 'm' || *my_str == 'M') {
+               my_str++;
+       }
+       *endstr = my_str;
+       return 1;
+}
+
+int ldns_str2wire_loc_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       uint32_t latitude = 0;
+       uint32_t longitude = 0;
+       uint32_t altitude = 0;
+
+       uint32_t equator = (uint32_t)1<<31; /* 2**31 */
+
+       uint32_t h = 0;
+       uint32_t m = 0;
+       uint8_t size_b = 1, size_e = 2;
+       uint8_t horiz_pre_b = 1, horiz_pre_e = 6;
+       uint8_t vert_pre_b = 1, vert_pre_e = 3;
+
+       double s = 0.0;
+       int northerness;
+       int easterness;
+
+       char *my_str = (char *) str;
+
+       /* only support version 0 */
+       if (isdigit((int) *my_str)) {
+               h = (uint32_t) strtol(my_str, &my_str, 10);
+       } else {
+               return LDNS_WIREPARSE_ERR_INVALID_STR;
+       }
+
+       while (isblank((int) *my_str)) {
+               my_str++;
+       }
+
+       if (isdigit((int) *my_str)) {
+               m = (uint32_t) strtol(my_str, &my_str, 10);
+       } else if (*my_str == 'N' || *my_str == 'S') {
+               goto north;
+       } else {
+               return LDNS_WIREPARSE_ERR_INVALID_STR;
+       }
+
+       while (isblank((int) *my_str)) {
+               my_str++;
+       }
+
+       if (isdigit((int) *my_str)) {
+               s = strtod(my_str, &my_str);
+       }
+north:
+       while (isblank((int) *my_str)) {
+               my_str++;
+       }
+
+       if (*my_str == 'N') {
+               northerness = 1;
+       } else if (*my_str == 'S') {
+               northerness = 0;
+       } else {
+               return LDNS_WIREPARSE_ERR_INVALID_STR;
+       }
+
+       my_str++;
+
+       /* store number */
+       s = 1000.0 * s;
+       /* add a little to make floor in conversion a round */
+       s += 0.0005;
+       latitude = (uint32_t) s;
+       latitude += 1000 * 60 * m;
+       latitude += 1000 * 60 * 60 * h;
+       if (northerness) {
+               latitude = equator + latitude;
+       } else {
+               latitude = equator - latitude;
+       }
+       while (isblank(*my_str)) {
+               my_str++;
+       }
+
+       if (isdigit((int) *my_str)) {
+               h = (uint32_t) strtol(my_str, &my_str, 10);
+       } else {
+               return LDNS_WIREPARSE_ERR_INVALID_STR;
+       }
+
+       while (isblank((int) *my_str)) {
+               my_str++;
+       }
+
+       if (isdigit((int) *my_str)) {
+               m = (uint32_t) strtol(my_str, &my_str, 10);
+       } else if (*my_str == 'E' || *my_str == 'W') {
+               goto east;
+       } else {
+               return LDNS_WIREPARSE_ERR_INVALID_STR;
+       }
+
+       while (isblank(*my_str)) {
+               my_str++;
+       }
+
+       if (isdigit((int) *my_str)) {
+               s = strtod(my_str, &my_str);
+       }
+
+east:
+       while (isblank(*my_str)) {
+               my_str++;
+       }
+
+       if (*my_str == 'E') {
+               easterness = 1;
+       } else if (*my_str == 'W') {
+               easterness = 0;
+       } else {
+               return LDNS_WIREPARSE_ERR_INVALID_STR;
+       }
+
+       my_str++;
+
+       /* store number */
+       s *= 1000.0;
+       /* add a little to make floor in conversion a round */
+       s += 0.0005;
+       longitude = (uint32_t) s;
+       longitude += 1000 * 60 * m;
+       longitude += 1000 * 60 * 60 * h;
+
+       if (easterness) {
+               longitude += equator;
+       } else {
+               longitude = equator - longitude;
+       }
+
+       altitude = (uint32_t)(strtod(my_str, &my_str)*100.0 +
+               10000000.0 + 0.5);
+       if (*my_str == 'm' || *my_str == 'M') {
+               my_str++;
+       }
+
+       if (strlen(my_str) > 0) {
+               if(!loc_parse_cm(my_str, &my_str, &size_b, &size_e))
+                       return LDNS_WIREPARSE_ERR_INVALID_STR;
+       }
+
+       if (strlen(my_str) > 0) {
+               if(!loc_parse_cm(my_str, &my_str, &horiz_pre_b, &horiz_pre_e))
+                       return LDNS_WIREPARSE_ERR_INVALID_STR;
+       }
+
+       if (strlen(my_str) > 0) {
+               if(!loc_parse_cm(my_str, &my_str, &vert_pre_b, &vert_pre_e))
+                       return LDNS_WIREPARSE_ERR_INVALID_STR;
+       }
+
+       if(*len < 16)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       rd[0] = 0;
+       rd[1] = 0;
+       rd[1] = ((size_b << 4) & 0xf0) | (size_e & 0x0f);
+       rd[2] = ((horiz_pre_b << 4) & 0xf0) | (horiz_pre_e & 0x0f);
+       rd[3] = ((vert_pre_b << 4) & 0xf0) | (vert_pre_e & 0x0f);
+       ldns_write_uint32(rd + 4, latitude);
+       ldns_write_uint32(rd + 8, longitude);
+       ldns_write_uint32(rd + 12, altitude);
+       *len = 16;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       int rd_len = 1;
+       int have_proto = 0;
+       char token[50], proto_str[50];
+       ldns_buffer strbuf;
+       ldns_buffer_init_frm_data(&strbuf, (uint8_t*)str, strlen(str));
+       proto_str[0]=0;
+
+       /* check we have one byte for proto */
+       if(*len < 1)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+
+       while(ldns_bget_token(&strbuf, token, "\t\n ", sizeof(token)) > 0) {
+               if(!have_proto) {
+                       struct protoent *p = getprotobyname(token);
+                       have_proto = 1;
+                       if(p) rd[0] = (uint8_t)p->p_proto;
+                       else rd[0] = (uint8_t)atoi(token);
+                       (void)strlcpy(proto_str, token, sizeof(proto_str));
+               } else {
+                       int serv_port;
+                       struct servent *serv = getservbyname(token, proto_str);
+                       if(serv) serv_port=(int)ntohs((uint16_t)serv->s_port);
+                       else {
+                               serv_port = atoi(token);
+                               if(serv_port == 0 && strcmp(token, "0") != 0)
+                                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX,
+                                               ldns_buffer_position(&strbuf));
+                               if(serv_port < 0 || serv_port > 65535)
+                                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX,
+                                               ldns_buffer_position(&strbuf));
+                       }
+                       if(rd_len < 1+serv_port/8+1) {
+                               /* bitmap is larger, init new bytes at 0 */
+                               if(*len < 1+(size_t)serv_port/8+1)
+                                       return RET_ERR(
+                                       LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                                       ldns_buffer_position(&strbuf));
+                               memset(rd+rd_len, 0, 1+(size_t)serv_port/8+1-rd_len);
+                               rd_len = 1+serv_port/8+1;
+                       }
+                       rd[1+ serv_port/8] |= (1 << (7 - serv_port % 8));
+               }
+       }
+       *len = (size_t)rd_len;
+
+#ifdef HAVE_ENDSERVENT
+       endservent();
+#endif
+#ifdef HAVE_ENDPROTOENT
+       endprotoent();
+#endif
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_nsap_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       const char* s = str;
+       size_t slen;
+       size_t dlen = 0; /* number of hexdigits parsed */
+
+       /* just a hex string with optional dots? */
+       if (s[0] != '0' || s[1] != 'x')
+               return LDNS_WIREPARSE_ERR_INVALID_STR;
+       s += 2;
+       slen = strlen(s);
+       if(slen > LDNS_MAX_RDFLEN*2)
+               return LDNS_WIREPARSE_ERR_LABEL_OVERFLOW;
+       while(*s) {
+               if(isspace(*s) || *s == '.') {
+                       s++;
+                       continue;
+               }
+               if(!isxdigit(*s))
+                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str);
+               if(*len < dlen/2 + 1)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                               s-str);
+               if((dlen&1)==0)
+                       rd[dlen/2] += ldns_hexdigit_to_int(*s++) * 16;
+               else    rd[dlen/2] += ldns_hexdigit_to_int(*s++);
+               dlen++;
+       }
+       if((dlen&1)!=0)
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str);
+       *len = dlen/2;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_atma_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       const char* s = str;
+       size_t slen = strlen(str);
+       size_t dlen = 0; /* number of hexdigits parsed */
+
+       /* just a hex string with optional dots? */
+       /* notimpl e.164 format */
+       if(slen > LDNS_MAX_RDFLEN*2)
+               return LDNS_WIREPARSE_ERR_LABEL_OVERFLOW;
+       while(*s) {
+               if(isspace(*s) || *s == '.') {
+                       s++;
+                       continue;
+               }
+               if(!isxdigit(*s))
+                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str);
+               if(*len < dlen/2 + 1)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                               s-str);
+               if((dlen&1)==0)
+                       rd[dlen/2] += ldns_hexdigit_to_int(*s++) * 16;
+               else    rd[dlen/2] += ldns_hexdigit_to_int(*s++);
+               dlen++;
+       }
+       if((dlen&1)!=0)
+               return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str);
+       *len = dlen/2;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_ipseckey_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       size_t gwlen = 0, keylen = 0;
+       int s;
+       uint8_t gwtype;
+       char token[512];
+       ldns_buffer strbuf;
+       ldns_buffer_init_frm_data(&strbuf, (uint8_t*)str, strlen(str));
+
+       if(*len < 3)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       /* precedence */
+       if(ldns_bget_token(&strbuf, token, "\t\n ", sizeof(token)) <= 0)
+               return RET_ERR(LDNS_WIREPARSE_ERR_INVALID_STR,
+                       ldns_buffer_position(&strbuf));
+       rd[0] = (uint8_t)atoi(token);
+       /* gateway_type */
+       if(ldns_bget_token(&strbuf, token, "\t\n ", sizeof(token)) <= 0)
+               return RET_ERR(LDNS_WIREPARSE_ERR_INVALID_STR,
+                       ldns_buffer_position(&strbuf));
+       rd[1] = (uint8_t)atoi(token);
+       gwtype = rd[1];
+       /* algorithm */
+       if(ldns_bget_token(&strbuf, token, "\t\n ", sizeof(token)) <= 0)
+               return RET_ERR(LDNS_WIREPARSE_ERR_INVALID_STR,
+                       ldns_buffer_position(&strbuf));
+       rd[2] = (uint8_t)atoi(token);
+
+       /* gateway */
+       if(ldns_bget_token(&strbuf, token, "\t\n ", sizeof(token)) <= 0)
+               return RET_ERR(LDNS_WIREPARSE_ERR_INVALID_STR,
+                       ldns_buffer_position(&strbuf));
+       if(gwtype == 0) {
+               /* NOGATEWAY */
+               if(strcmp(token, ".") != 0)
+                       return RET_ERR(LDNS_WIREPARSE_ERR_INVALID_STR,
+                               ldns_buffer_position(&strbuf));
+               gwlen = 0;
+       } else if(gwtype == 1) {
+               /* IP4 */
+               gwlen = *len - 3;
+               s = ldns_str2wire_a_buf(token, rd+3, &gwlen);
+               if(s) return RET_ERR_SHIFT(s, ldns_buffer_position(&strbuf));
+       } else if(gwtype == 2) {
+               /* IP6 */
+               gwlen = *len - 3;
+               s = ldns_str2wire_aaaa_buf(token, rd+3, &gwlen);
+               if(s) return RET_ERR_SHIFT(s, ldns_buffer_position(&strbuf));
+       } else if(gwtype == 3) {
+               /* DNAME */
+               gwlen = *len - 3;
+               s = ldns_str2wire_dname_buf(token, rd+3, &gwlen);
+               if(s) return RET_ERR_SHIFT(s, ldns_buffer_position(&strbuf));
+       } else {
+               /* unknown gateway type */
+               return RET_ERR(LDNS_WIREPARSE_ERR_INVALID_STR,
+                       ldns_buffer_position(&strbuf));
+       }
+       /* double check for size */
+       if(*len < 3 + gwlen)
+               return RET_ERR(LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL,
+                       ldns_buffer_position(&strbuf));
+
+       /* publickey in remainder of strbuf */
+       keylen = *len - 3 - gwlen;
+       s = ldns_str2wire_b64_buf((const char*)ldns_buffer_current(&strbuf),
+               rd+3+gwlen, &keylen);
+       if(s) return RET_ERR_SHIFT(s, ldns_buffer_position(&strbuf));
+
+       *len = 3 + gwlen + keylen;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_nsec3_salt_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       int i, salt_length_str = (int)strlen(str);
+       if (salt_length_str == 1 && str[0] == '-') {
+               salt_length_str = 0;
+       } else if (salt_length_str % 2 != 0) {
+               return LDNS_WIREPARSE_ERR_SYNTAX_HEX;
+       }
+       if (salt_length_str > 512)
+               return LDNS_WIREPARSE_ERR_SYNTAX_HEX;
+       if(*len < 1+(size_t)salt_length_str / 2)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       rd[0] = (uint8_t) (salt_length_str / 2);
+       for (i = 0; i < salt_length_str; i += 2) {
+               if (isxdigit((int)str[i]) && isxdigit((int)str[i+1])) {
+                       rd[1+i/2] = (uint8_t)(ldns_hexdigit_to_int(str[i])*16
+                               + ldns_hexdigit_to_int(str[i+1]));
+               } else {
+                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_HEX, i);
+               }
+       }
+       *len = 1 + (size_t)rd[0];
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_ilnp64_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       unsigned int a, b, c, d;
+       uint16_t shorts[4];
+       int l;
+       if(*len < sizeof(shorts))
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+
+       if (sscanf(str, "%4x:%4x:%4x:%4x%n", &a, &b, &c, &d, &l) != 4 ||
+                       l != (int)strlen(str) || /* more data to read */
+                       strpbrk(str, "+-")       /* signed hexes */
+                       ) {
+               return LDNS_WIREPARSE_ERR_SYNTAX_ILNP64;
+       } 
+       shorts[0] = htons(a);
+       shorts[1] = htons(b);
+       shorts[2] = htons(c);
+       shorts[3] = htons(d);
+       memmove(rd, &shorts, sizeof(shorts));
+       *len = sizeof(shorts);
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_eui48_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       unsigned int a, b, c, d, e, f;
+       int l;
+
+       if(*len < 6)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       if (sscanf(str, "%2x-%2x-%2x-%2x-%2x-%2x%n",
+                       &a, &b, &c, &d, &e, &f, &l) != 6 ||
+                       l != (int)strlen(str) || /* more data to read */
+                       strpbrk(str, "+-")       /* signed hexes */
+                       ) {
+               return LDNS_WIREPARSE_ERR_SYNTAX_EUI48;
+       } 
+       rd[0] = a;
+       rd[1] = b;
+       rd[2] = c;
+       rd[3] = d;
+       rd[4] = e;
+       rd[5] = f;
+       *len = 6;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_eui64_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       unsigned int a, b, c, d, e, f, g, h;
+       int l;
+
+       if(*len < 8)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       if (sscanf(str, "%2x-%2x-%2x-%2x-%2x-%2x-%2x-%2x%n",
+                       &a, &b, &c, &d, &e, &f, &g, &h, &l) != 8 ||
+                       l != (int)strlen(str) || /* more data to read */
+                       strpbrk(str, "+-")       /* signed hexes */
+                       ) {
+               return LDNS_WIREPARSE_ERR_SYNTAX_EUI64;
+       }
+       rd[0] = a;
+       rd[1] = b;
+       rd[2] = c;
+       rd[3] = d;
+       rd[4] = e;
+       rd[5] = f;
+       rd[6] = g;
+       rd[7] = h;
+       *len = 8;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_tag_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       size_t slen = strlen(str);
+       const char* ptr;
+
+       if (slen > 255)
+               return LDNS_WIREPARSE_ERR_SYNTAX_TAG;
+       if(*len < slen+1)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       for (ptr = str; *ptr; ptr++) {
+               if(!isalnum(*ptr))
+                       return RET_ERR(LDNS_WIREPARSE_ERR_SYNTAX_TAG, ptr-str);
+       }
+       rd[0] = slen;
+       memmove(rd+1, str, slen);
+       *len = slen+1;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_long_str_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       uint8_t ch = 0;
+       const char* pstr = str;
+       size_t length = 0;
+
+       /* Fill data with parsed bytes */
+       while (ldns_parse_char(&ch, &pstr)) {
+               if(*len < length+1)
+                       return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+               rd[length++] = ch;
+       }
+       if(!pstr)
+               return LDNS_WIREPARSE_ERR_SYNTAX_BAD_ESCAPE;
+       *len = length;
+       return LDNS_WIREPARSE_ERR_OK;
+}
+
+int ldns_str2wire_int16_data_buf(const char* str, uint8_t* rd, size_t* len)
+{
+       size_t sz = ldns_b64_pton_calculate_size(strlen(str));
+       int n;
+       if(*len < sz+2)
+               return LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
+       if(sz > 65535)
+               return LDNS_WIREPARSE_ERR_LABEL_OVERFLOW;
+       n = ldns_b64_pton(str, rd+2, (*len)-2);
+       if(n < 0)
+               return LDNS_WIREPARSE_ERR_SYNTAX_B64;
+       ldns_write_uint16(rd, (uint16_t)n);
+       *len = (size_t)n;
+       return LDNS_WIREPARSE_ERR_OK;
+}
diff --git a/ldns/str2wire.h b/ldns/str2wire.h
new file mode 100644 (file)
index 0000000..8746bfc
--- /dev/null
@@ -0,0 +1,532 @@
+/**
+ * str2wire.h -  read txt presentation of RRs
+ *
+ * (c) NLnet Labs, 2005-2006
+ *
+ * See the file LICENSE for the license
+ */
+
+/**
+ * \file
+ *
+ * Parses text to wireformat.
+ */
+
+#ifndef LDNS_STR2WIRE_H
+#define LDNS_STR2WIRE_H
+
+/* include rrdef for MAX_DOMAINLEN constant */
+#include <ldns/rrdef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+struct ldns_struct_lookup_table;
+
+/** buffer to read an RR, cannot be larger than 64K because of packet size */
+#define LDNS_RR_BUF_SIZE 65535 /* bytes */
+#define LDNS_DEFAULT_TTL       3600
+
+/*
+ * To convert class and type to string see
+ * ldns_get_rr_class_by_name(str)
+ * ldns_get_rr_type_by_name(str)
+ * from rrdef.h
+ */
+
+/**
+ * Convert text string into dname wireformat, mallocless, with user buffer.
+ * @param str: the text string with the domain name.
+ * @param buf: the result buffer, suggested size LDNS_MAX_DOMAINLEN+1
+ * @param len: length of the buffer on input, length of the result on output.
+ * @return 0 on success, otherwise an error.
+ */
+int ldns_str2wire_dname_buf(const char* str, uint8_t* buf, size_t* len);
+
+/**
+ * Same as ldns_str2wire_dname_buf, but concatenates origin if the domain
+ * name is relative (does not end in '.').
+ * @param str: the text string with the domain name.
+ * @param buf: the result buffer, suggested size LDNS_MAX_DOMAINLEN+1
+ * @param len: length of the buffer on input, length of the result on output.
+ * @param origin: the origin to append or NULL (nothing is appended).
+ * @param origin_len: length of origin.
+ * @return 0 on success, otherwise an error.
+ */
+int ldns_str2wire_dname_buf_origin(const char* str, uint8_t* buf, size_t* len,
+       uint8_t* origin, size_t origin_len);
+
+/**
+ * Convert text string into dname wireformat
+ * @param str: the text string with the domain name.
+ * @param len: returned length of wireformat.
+ * @return wireformat dname (malloced) or NULL on failure.
+ */
+uint8_t* ldns_str2wire_dname(const char* str, size_t* len);
+
+/**
+ * Convert text RR to wireformat, with user buffer.
+ * @param str: the RR data in text presentation format.
+ * @param rr: the buffer where the result is stored into.  This buffer has
+ *     the wire-dname(uncompressed), type, class, ttl, rdatalen, rdata.
+ *     These values are probably not aligned, and in network format.
+ *     Use the ldns_wirerr_get_xxx functions to access them safely.
+ *     buffer size LDNS_RR_BUF_SIZE is suggested.
+ * @param len: on input the length of the buffer, on output the amount of
+ *     the buffer used for the rr.
+ * @param dname_len: if non-NULL, filled with the dname length as result.
+ *     Because after the dname you find the type, class, ttl, rdatalen, rdata.
+ * @param default_ttl: TTL used if no TTL available.
+ * @param origin: used for origin dname (if not NULL)
+ * @param origin_len: length of origin.
+ * @param prev: used for prev_rr dname (if not NULL)
+ * @param prev_len: length of prev.
+ * @return 0 on success, an error on failure.
+ */
+int ldns_str2wire_rr_buf(const char* str, uint8_t* rr, size_t* len,
+       size_t* dname_len, uint32_t default_ttl, uint8_t* origin,
+       size_t origin_len, uint8_t* prev, size_t prev_len);
+
+/**
+ * Same as ldns_str2wire_rr_buf, but there is no rdata, it returns an RR
+ * with zero rdata and no ttl.  It has name, type, class.
+ * You can access those with the ldns_wirerr_get_type and class functions.
+ * @param str: the RR data in text presentation format.
+ * @param rr: the buffer where the result is stored into.
+ * @param len: on input the length of the buffer, on output the amount of
+ *     the buffer used for the rr.
+ * @param dname_len: if non-NULL, filled with the dname length as result.
+ *     Because after the dname you find the type, class, ttl, rdatalen, rdata.
+ * @param origin: used for origin dname (if not NULL)
+ * @param origin_len: length of origin.
+ * @param prev: used for prev_rr dname (if not NULL)
+ * @param prev_len: length of prev.
+ * @return 0 on success, an error on failure.
+ */
+int ldns_str2wire_rr_question_buf(const char* str, uint8_t* rr, size_t* len,
+       size_t* dname_len, uint8_t* origin, size_t origin_len, uint8_t* prev,
+       size_t prev_len);
+
+/**
+ * Get the type of the RR.
+ * @param rr: the RR in wire format.
+ * @param len: rr length.
+ * @param dname_len: dname length to skip.
+ * @return type in host byteorder
+ */
+uint16_t ldns_wirerr_get_type(uint8_t* rr, size_t len, size_t dname_len);
+
+/**
+ * Get the class of the RR.
+ * @param rr: the RR in wire format.
+ * @param len: rr length.
+ * @param dname_len: dname length to skip.
+ * @return class in host byteorder
+ */
+uint16_t ldns_wirerr_get_class(uint8_t* rr, size_t len, size_t dname_len);
+
+/**
+ * Get the ttl of the RR.
+ * @param rr: the RR in wire format.
+ * @param len: rr length.
+ * @param dname_len: dname length to skip.
+ * @return ttl in host byteorder
+ */
+uint32_t ldns_wirerr_get_ttl(uint8_t* rr, size_t len, size_t dname_len);
+
+/**
+ * Get the rdata length of the RR.
+ * @param rr: the RR in wire format.
+ * @param len: rr length.
+ * @param dname_len: dname length to skip.
+ * @return rdata length in host byteorder
+ *     If the rdata length is larger than the rr-len allows, it is truncated.
+ *     So, that it is safe to read the data length returned
+ *     from this function from the rdata pointer of ldns_wirerr_get_rdata.
+ */
+uint16_t ldns_wirerr_get_rdatalen(uint8_t* rr, size_t len, size_t dname_len);
+
+/**
+ * Get the rdata pointer of the RR.
+ * @param rr: the RR in wire format.
+ * @param len: rr length.
+ * @param dname_len: dname length to skip.
+ * @return rdata pointer
+ */
+uint8_t* ldns_wirerr_get_rdata(uint8_t* rr, size_t len, size_t dname_len);
+
+/**
+ * Get the rdata pointer of the RR. prefixed with rdata length.
+ * @param rr: the RR in wire format.
+ * @param len: rr length.
+ * @param dname_len: dname length to skip.
+ * @return pointer to rdatalength, followed by the rdata.
+ */
+uint8_t* ldns_wirerr_get_rdatawl(uint8_t* rr, size_t len, size_t dname_len);
+
+/**
+ * Parse result codes
+ */
+#define LDNS_WIREPARSE_MASK 0x0fff
+#define LDNS_WIREPARSE_SHIFT 12
+#define LDNS_WIREPARSE_ERROR(e) ((e)&LDNS_WIREPARSE_MASK)
+#define LDNS_WIREPARSE_OFFSET(e) (((e)&~LDNS_WIREPARSE_MASK)>>LDNS_WIREPARSE_SHIFT)
+/* use lookuptable to get error string, ldns_wireparse_errors */
+#define LDNS_WIREPARSE_ERR_OK 0
+#define LDNS_WIREPARSE_ERR_GENERAL 342
+#define LDNS_WIREPARSE_ERR_DOMAINNAME_OVERFLOW 343
+#define LDNS_WIREPARSE_ERR_DOMAINNAME_UNDERFLOW 344
+#define LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL 345
+#define LDNS_WIREPARSE_ERR_LABEL_OVERFLOW 346
+#define LDNS_WIREPARSE_ERR_EMPTY_LABEL 347
+#define LDNS_WIREPARSE_ERR_SYNTAX_BAD_ESCAPE 348
+#define LDNS_WIREPARSE_ERR_SYNTAX 349
+#define LDNS_WIREPARSE_ERR_SYNTAX_TTL 350
+#define LDNS_WIREPARSE_ERR_SYNTAX_TYPE 351
+#define LDNS_WIREPARSE_ERR_SYNTAX_CLASS 352
+#define LDNS_WIREPARSE_ERR_SYNTAX_RDATA 353
+#define LDNS_WIREPARSE_ERR_SYNTAX_MISSING_VALUE 354
+#define LDNS_WIREPARSE_ERR_INVALID_STR 355
+#define LDNS_WIREPARSE_ERR_SYNTAX_B64 356
+#define LDNS_WIREPARSE_ERR_SYNTAX_B32_EXT 357
+#define LDNS_WIREPARSE_ERR_SYNTAX_HEX 358
+#define LDNS_WIREPARSE_ERR_CERT_BAD_ALGORITHM 359
+#define LDNS_WIREPARSE_ERR_SYNTAX_TIME 360
+#define LDNS_WIREPARSE_ERR_SYNTAX_PERIOD 361
+#define LDNS_WIREPARSE_ERR_SYNTAX_ILNP64 362
+#define LDNS_WIREPARSE_ERR_SYNTAX_EUI48 363
+#define LDNS_WIREPARSE_ERR_SYNTAX_EUI64 364
+#define LDNS_WIREPARSE_ERR_SYNTAX_TAG 365
+#define LDNS_WIREPARSE_ERR_NOT_IMPL 366
+#define LDNS_WIREPARSE_ERR_SYNTAX_INT 367
+#define LDNS_WIREPARSE_ERR_SYNTAX_IP4 368
+#define LDNS_WIREPARSE_ERR_SYNTAX_IP6 369
+#define LDNS_WIREPARSE_ERR_SYNTAX_INTEGER_OVERFLOW 370
+#define LDNS_WIREPARSE_ERR_INCLUDE 371
+#define LDNS_WIREPARSE_ERR_PARENTHESIS 372
+
+/**
+ * Get reference to a constant string for the (parse) error.
+ * @param e: error return value
+ * @return string.
+ */
+const char* ldns_get_errorstr_parse(int e);
+
+/**
+ * wire parse state for parsing files
+ */
+struct ldns_file_parse_state {
+       /** the origin domain name, if len!=0. uncompressed wireformat */
+       uint8_t origin[LDNS_MAX_DOMAINLEN+1];
+       /** length of origin domain name, in bytes. 0 if not set. */
+       size_t origin_len;
+       /** the previous domain name, if len!=0. uncompressed wireformat*/
+       uint8_t prev_rr[LDNS_MAX_DOMAINLEN+1];
+       /** length of the previous domain name, in bytes. 0 if not set. */
+       size_t prev_rr_len;
+       /** default TTL, this is used if the text does not specify a TTL,
+        * host byteorder */
+       uint32_t default_ttl;
+       /** line number information */
+       int lineno;
+};
+
+/**
+ * Read one RR from zonefile with buffer for the data.
+ * @param in: file that is read from (one RR, multiple lines if it spans them).
+ * @param rr: this is malloced by the user and the result is stored here,
+ *     if an RR is read.  If no RR is read this is signalled with the
+ *     return len set to 0 (for ORIGIN, TTL directives).
+ * @param len: on input, the length of the rr buffer.  on output the rr len.
+ *     Buffer size of 64k should be enough.
+ * @param dname_len: returns the length of the dname initial part of the rr.
+ * @param parse_state: pass a pointer to user-allocated struct.
+ *     Contents are maintained by this function.
+ *     If you pass NULL then ORIGIN and TTL directives are not honored.
+ *     You can start out with a particular origin by pre-filling it.
+ *     otherwise, zero the structure before passing it.
+ *     lineno is incremented when a newline is passed by the parser,
+ *     you should initialize it at 1 at the start of the file.
+ * @return 0 on success, error on failure.
+ */
+int ldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len,
+       struct ldns_file_parse_state* parse_state);
+
+/**
+ * Convert one rdf in rdata to wireformat and parse from string.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @param rdftype: the type of the rdf.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_rdf_buf(const char* str, uint8_t* rd, size_t* len,
+       ldns_rdf_type rdftype);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_INT8 from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_int8_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_INT16 from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_int16_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_INT32 from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_int32_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_A from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_a_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_AAAA from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_aaaa_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_STR from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_str_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_APL from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_apl_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_B64 from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_b64_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_B32_EXT from string to wireformat.
+ * And also LDNS_RDF_TYPE_NSEC3_NEXT_OWNER.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_b32_ext_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_HEX from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_hex_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_NSEC from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_nsec_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_TYPE from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_type_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_CLASS from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_class_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_CERT_ALG from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_cert_alg_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_ALG from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_alg_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_TIME from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_time_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_PERIOD from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_period_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_LOC from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_loc_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_WKS from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_wks_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_NSAP from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_nsap_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_ATMA from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_atma_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_IPSECKEY from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_ipseckey_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_NSEC3_SALT from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_nsec3_salt_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_ILNP64 from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_ilnp64_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_EUI48 from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_eui48_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_EUI64 from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_eui64_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_TAG from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_tag_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_LONG_STR from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_long_str_buf(const char* str, uint8_t* rd, size_t* len);
+
+/**
+ * Convert rdf of type LDNS_RDF_TYPE_INT16_DATA from string to wireformat.
+ * @param str: the text to convert for this rdata element.
+ * @param rd: rdata buffer for the wireformat.
+ * @param len: length of rd buffer on input, used length on output.
+ * @return 0 on success, error on failure.
+ */
+int ldns_str2wire_int16_data_buf(const char* str, uint8_t* rd, size_t* len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LDNS_STR2WIRE_H */
diff --git a/ldns/wire2str.c b/ldns/wire2str.c
new file mode 100644 (file)
index 0000000..8bd74f1
--- /dev/null
@@ -0,0 +1,1925 @@
+/*
+ * wire2str.c
+ *
+ * conversion routines from the wire format
+ * to the presentation format (strings)
+ *
+ * (c) NLnet Labs, 2004-2006
+ *
+ * See the file LICENSE for the license
+ */
+/**
+ * \file
+ *
+ * Contains functions to translate the wireformat to text
+ * representation, as well as functions to print them.
+ */
+#include "config.h"
+#include "ldns/wire2str.h"
+#include "ldns/str2wire.h"
+#include "ldns/rrdef.h"
+#include "ldns/pkthdr.h"
+#include "ldns/parseutil.h"
+#include "ldns/sbuffer.h"
+#include "ldns/keyraw.h"
+#include <stdarg.h>
+#include <ctype.h>
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+/* lookup tables for standard DNS stuff  */
+/* Taken from RFC 2535, section 7.  */
+static ldns_lookup_table ldns_algorithms_data[] = {
+       { LDNS_RSAMD5, "RSAMD5" },
+       { LDNS_DH, "DH" },
+       { LDNS_DSA, "DSA" },
+       { LDNS_ECC, "ECC" },
+       { LDNS_RSASHA1, "RSASHA1" },
+       { LDNS_DSA_NSEC3, "DSA-NSEC3-SHA1" },
+       { LDNS_RSASHA1_NSEC3, "RSASHA1-NSEC3-SHA1" },
+       { LDNS_RSASHA256, "RSASHA256"},
+       { LDNS_RSASHA512, "RSASHA512"},
+       { LDNS_ECC_GOST, "ECC-GOST"},
+       { LDNS_ECDSAP256SHA256, "ECDSAP256SHA256"},
+       { LDNS_ECDSAP384SHA384, "ECDSAP384SHA384"},
+       { LDNS_INDIRECT, "INDIRECT" },
+       { LDNS_PRIVATEDNS, "PRIVATEDNS" },
+       { LDNS_PRIVATEOID, "PRIVATEOID" },
+       { 0, NULL }
+};
+ldns_lookup_table* ldns_algorithms = ldns_algorithms_data;
+
+/* hash algorithms in DS record */
+static ldns_lookup_table ldns_hashes_data[] = {
+       { LDNS_SHA1, "SHA1" },
+       { LDNS_SHA256, "SHA256" },
+       { LDNS_HASH_GOST, "HASH-GOST" },
+       { LDNS_SHA384, "SHA384" },
+       { 0, NULL }
+};
+ldns_lookup_table* ldns_hashes = ldns_hashes_data;
+
+/* Taken from RFC 4398  */
+static ldns_lookup_table ldns_cert_algorithms_data[] = {
+       { LDNS_CERT_PKIX, "PKIX" },
+       { LDNS_CERT_SPKI, "SPKI" },
+       { LDNS_CERT_PGP, "PGP" },
+       { LDNS_CERT_IPKIX, "IPKIX" },
+       { LDNS_CERT_ISPKI, "ISPKI" },
+       { LDNS_CERT_IPGP, "IPGP" },
+       { LDNS_CERT_ACPKIX, "ACPKIX" },
+       { LDNS_CERT_IACPKIX, "IACPKIX" },
+       { LDNS_CERT_URI, "URI" },
+       { LDNS_CERT_OID, "OID" },
+       { 0, NULL }
+};
+ldns_lookup_table* ldns_cert_algorithms = ldns_cert_algorithms_data;
+
+/* if these are used elsewhere */
+static ldns_lookup_table ldns_rcodes_data[] = {
+       { LDNS_RCODE_NOERROR, "NOERROR" },
+       { LDNS_RCODE_FORMERR, "FORMERR" },
+       { LDNS_RCODE_SERVFAIL, "SERVFAIL" },
+       { LDNS_RCODE_NXDOMAIN, "NXDOMAIN" },
+       { LDNS_RCODE_NOTIMPL, "NOTIMPL" },
+       { LDNS_RCODE_REFUSED, "REFUSED" },
+       { LDNS_RCODE_YXDOMAIN, "YXDOMAIN" },
+       { LDNS_RCODE_YXRRSET, "YXRRSET" },
+       { LDNS_RCODE_NXRRSET, "NXRRSET" },
+       { LDNS_RCODE_NOTAUTH, "NOTAUTH" },
+       { LDNS_RCODE_NOTZONE, "NOTZONE" },
+       { 0, NULL }
+};
+ldns_lookup_table* ldns_rcodes = ldns_rcodes_data;
+
+static ldns_lookup_table ldns_opcodes_data[] = {
+       { LDNS_PACKET_QUERY, "QUERY" },
+       { LDNS_PACKET_IQUERY, "IQUERY" },
+       { LDNS_PACKET_STATUS, "STATUS" },
+       { LDNS_PACKET_NOTIFY, "NOTIFY" },
+       { LDNS_PACKET_UPDATE, "UPDATE" },
+       { 0, NULL }
+};
+ldns_lookup_table* ldns_opcodes = ldns_opcodes_data;
+
+static ldns_lookup_table ldns_wireparse_errors_data[] = {
+       { LDNS_WIREPARSE_ERR_OK, "no parse error" },
+       { LDNS_WIREPARSE_ERR_GENERAL, "parse error" },
+       { LDNS_WIREPARSE_ERR_DOMAINNAME_OVERFLOW, "Domainname length overflow" },
+       { LDNS_WIREPARSE_ERR_DOMAINNAME_UNDERFLOW, "Domainname length underflow (zero length)" },
+       { LDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL, "buffer too small" },
+       { LDNS_WIREPARSE_ERR_LABEL_OVERFLOW, "Label length overflow" },
+       { LDNS_WIREPARSE_ERR_EMPTY_LABEL, "Empty label" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_BAD_ESCAPE, "Syntax error, bad escape sequence" },
+       { LDNS_WIREPARSE_ERR_SYNTAX, "Syntax error, could not parse the RR" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_TTL, "Syntax error, could not parse the RR's TTL" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_TYPE, "Syntax error, could not parse the RR's type" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_CLASS, "Syntax error, could not parse the RR's class" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_RDATA, "Syntax error, could not parse the RR's rdata" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_MISSING_VALUE, "Syntax error, value expected" },
+       { LDNS_WIREPARSE_ERR_INVALID_STR, "Conversion error, string expected" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_B64, "Conversion error, b64 encoding expected" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_B32_EXT, "Conversion error, b32 ext encoding expected" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_HEX, "Conversion error, hex encoding expected" },
+       { LDNS_WIREPARSE_ERR_CERT_BAD_ALGORITHM, "Bad algorithm type for CERT record" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_TIME, "Conversion error, time encoding expected" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_PERIOD, "Conversion error, time period encoding expected" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_ILNP64, "Conversion error, 4 colon seperated hex numbers expected" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_EUI48,
+               "Conversion error, 6 two character hex numbers "
+               "seperated by dashes expected (i.e. xx-xx-xx-xx-xx-xx" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_EUI64,
+               "Conversion error, 8 two character hex numbers "
+               "seperated by dashes expected (i.e. xx-xx-xx-xx-xx-xx-xx-xx" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_TAG,
+               "Conversion error, a non-zero sequence of US-ASCII letters "
+               "and numbers in lower case expected" },
+       { LDNS_WIREPARSE_ERR_NOT_IMPL, "not implemented" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_INT, "Conversion error, integer expected" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_IP4, "Conversion error, ip4 addr expected" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_IP6, "Conversion error, ip6 addr expected" },
+       { LDNS_WIREPARSE_ERR_SYNTAX_INTEGER_OVERFLOW, "Syntax error, integer overflow" },
+       { LDNS_WIREPARSE_ERR_INCLUDE, "$INCLUDE directive was seen in the zone" },
+       { LDNS_WIREPARSE_ERR_PARENTHESIS, "Parse error, parenthesis mismatch" },
+       { 0, NULL }
+};
+ldns_lookup_table* ldns_wireparse_errors = ldns_wireparse_errors_data;
+
+static ldns_lookup_table ldns_edns_flags_data[] = {
+       { 3600, "do"},
+       { 0, NULL}
+};
+ldns_lookup_table* ldns_edns_flags = ldns_edns_flags_data;
+
+static ldns_lookup_table ldns_edns_options_data[] = {
+       { 1, "LLQ" },
+       { 2, "UL" },
+       { 3, "NSID" },
+       /* 4 draft-cheshire-edns0-owner-option */
+       { 5, "DAU" },
+       { 6, "DHU" },
+       { 7, "N3U" },
+       { 8, "edns-client-subnet" },
+       { 0, NULL}
+};
+ldns_lookup_table* ldns_edns_options = ldns_edns_options_data;
+
+char* ldns_wire2str_pkt(uint8_t* data, size_t len)
+{
+       size_t slen = (size_t)ldns_wire2str_pkt_buf(data, len, NULL, 0);
+       char* result = (char*)malloc(slen+1);
+       if(!result) return NULL;
+       ldns_wire2str_pkt_buf(data, len, result, slen+1);
+       return result;
+}
+
+char* ldns_wire2str_rr(uint8_t* rr, size_t len)
+{
+       size_t slen = (size_t)ldns_wire2str_rr_buf(rr, len, NULL, 0);
+       char* result = (char*)malloc(slen+1);
+       if(!result) return NULL;
+       ldns_wire2str_rr_buf(rr, len, result, slen+1);
+       return result;
+}
+
+char* ldns_wire2str_type(uint16_t rrtype)
+{
+       char buf[16];
+       ldns_wire2str_type_buf(rrtype, buf, sizeof(buf));
+       return strdup(buf);
+}
+
+char* ldns_wire2str_class(uint16_t rrclass)
+{
+       char buf[16];
+       ldns_wire2str_class_buf(rrclass, buf, sizeof(buf));
+       return strdup(buf);
+}
+
+char* ldns_wire2str_dname(uint8_t* dname, size_t dname_len)
+{
+       size_t slen=(size_t)ldns_wire2str_dname_buf(dname, dname_len, NULL, 0);
+       char* result = (char*)malloc(slen+1);
+       if(!result) return NULL;
+       ldns_wire2str_dname_buf(dname, dname_len, result, slen+1);
+       return result;
+}
+
+char* ldns_wire2str_rcode(int rcode)
+{
+       char buf[16];
+       ldns_wire2str_rcode_buf(rcode, buf, sizeof(buf));
+       return strdup(buf);
+}
+
+int ldns_wire2str_pkt_buf(uint8_t* d, size_t dlen, char* s, size_t slen)
+{
+       /* use arguments as temporary variables */
+       return ldns_wire2str_pkt_scan(&d, &dlen, &s, &slen);
+}
+
+int ldns_wire2str_rr_buf(uint8_t* d, size_t dlen, char* s, size_t slen)
+{
+       /* use arguments as temporary variables */
+       return ldns_wire2str_rr_scan(&d, &dlen, &s, &slen, NULL, 0);
+}
+
+int ldns_wire2str_rdata_buf(uint8_t* rdata, size_t rdata_len, char* str,
+       size_t str_len, uint16_t rrtype)
+{
+       /* use arguments as temporary variables */
+       return ldns_wire2str_rdata_scan(&rdata, &rdata_len, &str, &str_len,
+               rrtype, NULL, 0);
+}
+
+int ldns_wire2str_rr_unknown_buf(uint8_t* d, size_t dlen, char* s, size_t slen)
+{
+       /* use arguments as temporary variables */
+       return ldns_wire2str_rr_unknown_scan(&d, &dlen, &s, &slen, NULL, 0);
+}
+
+int ldns_wire2str_rr_comment_buf(uint8_t* rr, size_t rrlen, size_t dname_len,
+       char* s, size_t slen)
+{
+       uint16_t rrtype = ldns_wirerr_get_type(rr, rrlen, dname_len);
+       return ldns_wire2str_rr_comment_print(&s, &slen, rr, rrlen, dname_len,
+               rrtype);
+}
+
+int ldns_wire2str_type_buf(uint16_t rrtype, char* s, size_t slen)
+{
+       /* use arguments as temporary variables */
+       return ldns_wire2str_type_print(&s, &slen, rrtype);
+}
+
+int ldns_wire2str_class_buf(uint16_t rrclass, char* s, size_t slen)
+{
+       /* use arguments as temporary variables */
+       return ldns_wire2str_class_print(&s, &slen, rrclass);
+}
+
+int ldns_wire2str_rcode_buf(int rcode, char* s, size_t slen)
+{
+       /* use arguments as temporary variables */
+       return ldns_wire2str_rcode_print(&s, &slen, rcode);
+}
+
+int ldns_wire2str_dname_buf(uint8_t* d, size_t dlen, char* s, size_t slen)
+{
+       /* use arguments as temporary variables */
+       return ldns_wire2str_dname_scan(&d, &dlen, &s, &slen, NULL, 0);
+}
+
+int ldns_str_vprint(char** str, size_t* slen, const char* format, va_list args)
+{
+       int w = vsnprintf(*str, *slen, format, args);
+       if(w < 0) {
+               /* error in printout */
+               return 0;
+       } else if((size_t)w >= *slen) {
+               *str = NULL; /* we do not want str to point outside of buffer*/
+               *slen = 0;
+       } else {
+               *str += w;
+               *slen -= w;
+       }
+       return w;
+}
+
+int ldns_str_print(char** str, size_t* slen, const char* format, ...)
+{
+       int w;
+       va_list args;
+       va_start(args, format);
+       w = ldns_str_vprint(str, slen, format, args);
+       va_end(args);
+       return w;
+}
+
+/** print hex format into text buffer for specified length */
+static int print_hex_buf(char** s, size_t* slen, uint8_t* buf, size_t len)
+{
+       const char* hex = "0123456789ABCDEF";
+       size_t i;
+       for(i=0; i<len; i++) {
+               (void)ldns_str_print(s, slen, "%c%c", hex[(buf[i]&0xf0)>>4],
+                       hex[buf[i]&0x0f]);
+       }
+       return (int)len*2;
+}
+
+/** print remainder of buffer in hex format with prefixed text */
+static int print_remainder_hex(const char* pref, uint8_t** d, size_t* dlen,
+       char** s, size_t* slen)
+{
+       int w = 0;
+       w += ldns_str_print(s, slen, pref);
+       w += print_hex_buf(s, slen, *d, *dlen);
+       *d += *dlen;
+       *dlen = 0;
+       return w;
+}
+
+int ldns_wire2str_pkt_scan(uint8_t** d, size_t* dlen, char** s, size_t* slen)
+{
+       int w = 0;
+       unsigned qdcount, ancount, nscount, arcount, i;
+       uint8_t* pkt = *d;
+       size_t pktlen = *dlen;
+       if(*dlen >= LDNS_HEADER_SIZE) {
+               qdcount = (unsigned)LDNS_QDCOUNT(*d);
+               ancount = (unsigned)LDNS_ANCOUNT(*d);
+               nscount = (unsigned)LDNS_NSCOUNT(*d);
+               arcount = (unsigned)LDNS_ARCOUNT(*d);
+       } else {
+               qdcount = ancount = nscount = arcount = 0;
+       }
+       w += ldns_wire2str_header_scan(d, dlen, s, slen);
+       w += ldns_str_print(s, slen, "\n");
+       w += ldns_str_print(s, slen, ";; QUESTION SECTION:\n");
+       for(i=0; i<qdcount; i++) {
+               w += ldns_wire2str_rrquestion_scan(d, dlen, s, slen,
+                       pkt, pktlen);
+               if(!*dlen) break;
+       }
+       w += ldns_str_print(s, slen, "\n");
+       w += ldns_str_print(s, slen, ";; ANSWER SECTION:\n");
+       for(i=0; i<ancount; i++) {
+               w += ldns_wire2str_rr_scan(d, dlen, s, slen, pkt, pktlen);
+               if(!*dlen) break;
+       }
+       w += ldns_str_print(s, slen, "\n");
+       w += ldns_str_print(s, slen, ";; AUTHORITY SECTION:\n");
+       for(i=0; i<nscount; i++) {
+               w += ldns_wire2str_rr_scan(d, dlen, s, slen, pkt, pktlen);
+               if(!*dlen) break;
+       }
+       w += ldns_str_print(s, slen, "\n");
+       w += ldns_str_print(s, slen, ";; ADDITIONAL SECTION:\n");
+       for(i=0; i<arcount; i++) {
+               w += ldns_wire2str_rr_scan(d, dlen, s, slen, pkt, pktlen);
+               if(!*dlen) break;
+       }
+       /* other fields: WHEN(time), SERVER(IP) not available here. */
+       w += ldns_str_print(s, slen, ";; MSG SIZE  rcvd: %d\n", (int)pktlen);
+       if(*dlen > 0) {
+               w += print_remainder_hex(";; trailing garbage 0x",
+                       d, dlen, s, slen);
+               w += ldns_str_print(s, slen, "\n");
+       }
+       return w;
+}
+
+/** scan type, class and ttl and printout, for rr */
+static int ldns_rr_tcttl_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       int w = 0;
+       uint16_t t, c;
+       uint32_t ttl;
+       if(*dl < 8) {
+               if(*dl < 4)
+                       return w + print_remainder_hex("; Error malformed 0x",
+                               d, dl, s, sl);
+               /* these print values or 0x.. if none left */
+               t = ldns_read_uint16(*d);
+               c = ldns_read_uint16((*d)+2);
+               (*d)+=4;
+               (*dl)-=4;
+               w += ldns_wire2str_class_print(s, sl, c);
+               w += ldns_str_print(s, sl, "\t");
+               w += ldns_wire2str_type_print(s, sl, t);
+               if(*dl == 0)
+                       return w + ldns_str_print(s, sl, "; Error no ttl");
+               else    return w + print_remainder_hex(
+                               "; Error malformed ttl 0x", d, dl, s, sl);
+               return w;
+       }
+       t = ldns_read_uint16(*d);
+       c = ldns_read_uint16((*d)+2);
+       ttl = ldns_read_uint32((*d)+4);
+       (*d)+=8;
+       (*dl)-=8;
+       w += ldns_str_print(s, sl, "%lu\t", (unsigned long)ttl);
+       w += ldns_wire2str_class_print(s, sl, c);
+       w += ldns_str_print(s, sl, "\t");
+       w += ldns_wire2str_type_print(s, sl, t);
+       return w;
+}
+
+int ldns_wire2str_rr_scan(uint8_t** d, size_t* dlen, char** s, size_t* slen,
+       uint8_t* pkt, size_t pktlen)
+{
+       int w = 0;
+       uint8_t* rr = *d;
+       size_t rrlen = *dlen, dname_off, rdlen, ordlen;
+       uint16_t rrtype = 0;
+       
+       if(*dlen >= 3 && (*d)[0]==0 &&
+               ldns_read_uint16((*d)+1)==LDNS_RR_TYPE_OPT) {
+               /* perform EDNS OPT processing */
+               return ldns_wire2str_edns_scan(d, dlen, s, slen, pkt, pktlen);
+       }
+
+       /* try to scan the rdata with pretty-printing, but if that fails, then
+        * scan the rdata as an unknown RR type */
+       w += ldns_wire2str_dname_scan(d, dlen, s, slen, pkt, pktlen);
+       w += ldns_str_print(s, slen, "\t");
+       dname_off = rrlen-(*dlen);
+       if(*dlen == 4) {
+               /* like a question-RR */
+               uint16_t t = ldns_read_uint16(*d);
+               uint16_t c = ldns_read_uint16((*d)+2);
+               (*d)+=4;
+               (*dlen)-=4;
+               w += ldns_wire2str_class_print(s, slen, c);
+               w += ldns_str_print(s, slen, "\t");
+               w += ldns_wire2str_type_print(s, slen, t);
+               w += ldns_str_print(s, slen, " ; Error no ttl,rdata\n");
+               return w;
+       }
+       if(*dlen < 8) {
+               if(*dlen == 0)
+                       return w + ldns_str_print(s, slen, ";Error missing RR\n");
+               w += print_remainder_hex(";Error partial RR 0x", d, dlen, s, slen);
+               return w + ldns_str_print(s, slen, "\n");
+       }
+       rrtype = ldns_read_uint16(*d);
+       w += ldns_rr_tcttl_scan(d, dlen, s, slen);
+       w += ldns_str_print(s, slen, "\t");
+
+       /* rdata */
+       if(*dlen < 2) {
+               if(*dlen == 0)
+                       return w + ldns_str_print(s, slen, ";Error missing rdatalen\n");
+               w += print_remainder_hex(";Error missing rdatalen 0x",
+                       d, dlen, s, slen);
+               return w + ldns_str_print(s, slen, "\n");
+       }
+       rdlen = ldns_read_uint16(*d);
+       ordlen = rdlen;
+       (*d)+=2;
+       (*dlen)-=2;
+       if(*dlen < rdlen) {
+               w += ldns_str_print(s, slen, "\\# %u ", (unsigned)rdlen);
+               if(*dlen == 0)
+                       return w + ldns_str_print(s, slen, ";Error missing rdata\n");
+               w += print_remainder_hex(";Error partial rdata 0x", d, dlen, s, slen);
+               return w + ldns_str_print(s, slen, "\n");
+       }
+       w += ldns_wire2str_rdata_scan(d, &rdlen, s, slen, rrtype, pkt, pktlen);
+       (*dlen) -= (ordlen-rdlen);
+
+       /* default comment */
+       w += ldns_wire2str_rr_comment_print(s, slen, rr, rrlen, dname_off,
+               rrtype);
+       w += ldns_str_print(s, slen, "\n");
+       return w;
+}
+
+int ldns_wire2str_rrquestion_scan(uint8_t** d, size_t* dlen, char** s,
+       size_t* slen, uint8_t* pkt, size_t pktlen)
+{
+       int w = 0;
+       uint16_t t, c;
+       w += ldns_wire2str_dname_scan(d, dlen, s, slen, pkt, pktlen);
+       w += ldns_str_print(s, slen, "\t");
+       if(*dlen < 4) {
+               if(*dlen == 0)
+                       return w + ldns_str_print(s, slen, "Error malformed\n");
+               w += print_remainder_hex("Error malformed 0x", d, dlen, s, slen);
+               return w + ldns_str_print(s, slen, "\n");
+       }
+       t = ldns_read_uint16(*d);
+       c = ldns_read_uint16((*d)+2);
+       (*d)+=4;
+       (*dlen)-=4;
+       w += ldns_wire2str_class_print(s, slen, c);
+       w += ldns_str_print(s, slen, "\t");
+       w += ldns_wire2str_type_print(s, slen, t);
+       w += ldns_str_print(s, slen, "\n");
+       return w;
+}
+
+int ldns_wire2str_rr_unknown_scan(uint8_t** d, size_t* dlen, char** s,
+       size_t* slen, uint8_t* pkt, size_t pktlen)
+{
+       size_t rdlen, ordlen;
+       int w = 0;
+       w += ldns_wire2str_dname_scan(d, dlen, s, slen, pkt, pktlen);
+       w += ldns_str_print(s, slen, "\t");
+       w += ldns_rr_tcttl_scan(d, dlen, s, slen);
+       w += ldns_str_print(s, slen, "\t");
+       if(*dlen < 2) {
+               if(*dlen == 0)
+                       return w + ldns_str_print(s, slen, ";Error missing rdatalen\n");
+               w += print_remainder_hex(";Error missing rdatalen 0x",
+                       d, dlen, s, slen);
+               return w + ldns_str_print(s, slen, "\n");
+       }
+       rdlen = ldns_read_uint16(*d);
+       ordlen = rdlen;
+       (*d) += 2;
+       (*dlen) -= 2;
+       if(*dlen < rdlen) {
+               w += ldns_str_print(s, slen, "\\# %u ", (unsigned)rdlen);
+               if(*dlen == 0)
+                       return w + ldns_str_print(s, slen, ";Error missing rdata\n");
+               w += print_remainder_hex(";Error partial rdata 0x", d, dlen, s, slen);
+               return w + ldns_str_print(s, slen, "\n");
+       }
+       w += ldns_wire2str_rdata_unknown_scan(d, &rdlen, s, slen);
+       (*dlen) -= (ordlen-rdlen);
+       w += ldns_str_print(s, slen, "\n");
+       return w;
+}
+
+/** print rr comment for type DNSKEY */
+static int rr_comment_dnskey(char** s, size_t* slen, uint8_t* rr,
+       size_t rrlen, size_t dname_off)
+{
+       size_t rdlen;
+       uint8_t* rdata;
+       int flags, w = 0;
+       if(rrlen < dname_off + 10) return 0;
+       rdlen = ldns_read_uint16(rr+dname_off+8);
+       if(rrlen < dname_off + 10 + rdlen) return 0;
+       rdata = rr + dname_off + 10;
+       flags = (int)ldns_read_uint16(rdata);
+       w += ldns_str_print(s, slen, " ;{");
+
+       /* id */
+       w += ldns_str_print(s, slen, "id = %u",
+               ldns_calc_keytag_raw(rdata, rdlen));
+
+       /* flags */
+       if((flags&LDNS_KEY_ZONE_KEY)) {
+               if((flags&LDNS_KEY_SEP_KEY))
+                       w += ldns_str_print(s, slen, " (ksk)");
+               else    w += ldns_str_print(s, slen, " (zsk)");
+       }
+
+       /* keysize */
+       if(rdlen > 4) {
+               w += ldns_str_print(s, slen, ", ");
+               w += ldns_str_print(s, slen, "size = %db",
+                       (int)ldns_rr_dnskey_key_size_raw(
+                       (unsigned char*)rdata+4, rdlen-4, (int)(rdata[3])));
+       }
+
+       w += ldns_str_print(s, slen, "}");
+       return w;
+}
+
+/** print rr comment for type RRSIG */
+static int rr_comment_rrsig(char** s, size_t* slen, uint8_t* rr,
+       size_t rrlen, size_t dname_off)
+{
+       size_t rdlen;
+       uint8_t* rdata;
+       if(rrlen < dname_off + 10) return 0;
+       rdlen = ldns_read_uint16(rr+dname_off+8);
+       if(rrlen < dname_off + 10 + rdlen) return 0;
+       rdata = rr + dname_off + 10;
+       if(rdlen < 18) return 0;
+       return ldns_str_print(s, slen, " ;{id = %d}",
+               (int)ldns_read_uint16(rdata+16));
+}
+
+/** print rr comment for type NSEC3 */
+static int rr_comment_nsec3(char** s, size_t* slen, uint8_t* rr,
+       size_t rrlen, size_t dname_off)
+{
+       size_t rdlen;
+       uint8_t* rdata;
+       int w = 0;
+       if(rrlen < dname_off + 10) return 0;
+       rdlen = ldns_read_uint16(rr+dname_off+8);
+       if(rrlen < dname_off + 10 + rdlen) return 0;
+       rdata = rr + dname_off + 10;
+       if(rdlen < 2) return 0;
+       if((rdata[1] & LDNS_NSEC3_VARS_OPTOUT_MASK))
+               w += ldns_str_print(s, slen, " ;{flags: optout}");
+       return w;
+}
+
+int ldns_wire2str_rr_comment_print(char** s, size_t* slen, uint8_t* rr,
+       size_t rrlen, size_t dname_off, uint16_t rrtype)
+{
+       if(rrtype == LDNS_RR_TYPE_DNSKEY) {
+               return rr_comment_dnskey(s, slen, rr, rrlen, dname_off);
+       } else if(rrtype == LDNS_RR_TYPE_RRSIG) {
+               return rr_comment_rrsig(s, slen, rr, rrlen, dname_off);
+       } else if(rrtype == LDNS_RR_TYPE_NSEC3) {
+               return rr_comment_nsec3(s, slen, rr, rrlen, dname_off);
+       }
+       return 0;
+}
+
+int ldns_wire2str_header_scan(uint8_t** d, size_t* dlen, char** s,
+       size_t* slen)
+{
+       int w = 0;
+       int opcode, rcode;
+       w += ldns_str_print(s, slen, ";; ->>HEADER<<- ");
+       if(*dlen == 0)
+               return w+ldns_str_print(s, slen, "Error empty packet");
+       if(*dlen < 4)
+               return w+print_remainder_hex("Error header too short 0x", d, dlen, s, slen);
+       opcode = (int)LDNS_OPCODE_WIRE(*d);
+       rcode = (int)LDNS_RCODE_WIRE(*d);
+       w += ldns_str_print(s, slen, "opcode: ");
+       w += ldns_wire2str_opcode_print(s, slen, opcode);
+       w += ldns_str_print(s, slen, ", ");
+       w += ldns_str_print(s, slen, "rcode: ");
+       w += ldns_wire2str_rcode_print(s, slen, rcode);
+       w += ldns_str_print(s, slen, ", ");
+       w += ldns_str_print(s, slen, "id: %d\n", (int)LDNS_ID_WIRE(*d));
+       w += ldns_str_print(s, slen, ";; flags:");
+       if(LDNS_QR_WIRE(*d)) w += ldns_str_print(s, slen, " qr");
+       if(LDNS_AA_WIRE(*d)) w += ldns_str_print(s, slen, " aa");
+       if(LDNS_TC_WIRE(*d)) w += ldns_str_print(s, slen, " tc");
+       if(LDNS_RD_WIRE(*d)) w += ldns_str_print(s, slen, " rd");
+       if(LDNS_CD_WIRE(*d)) w += ldns_str_print(s, slen, " cd");
+       if(LDNS_RA_WIRE(*d)) w += ldns_str_print(s, slen, " ra");
+       if(LDNS_AD_WIRE(*d)) w += ldns_str_print(s, slen, " ad");
+       if(LDNS_Z_WIRE(*d))  w += ldns_str_print(s, slen, " z");
+       w += ldns_str_print(s, slen, " ; ");
+       if(*dlen < LDNS_HEADER_SIZE)
+               return w+print_remainder_hex("Error header too short 0x", d, dlen, s, slen);
+       w += ldns_str_print(s, slen, "QUERY: %d, ", (int)LDNS_QDCOUNT(*d));
+       w += ldns_str_print(s, slen, "ANSWER: %d, ", (int)LDNS_ANCOUNT(*d));
+       w += ldns_str_print(s, slen, "AUTHORITY: %d, ", (int)LDNS_NSCOUNT(*d));
+       w += ldns_str_print(s, slen, "ADDITIONAL: %d ", (int)LDNS_ARCOUNT(*d));
+       *d += LDNS_HEADER_SIZE;
+       *dlen -= LDNS_HEADER_SIZE;
+       return w;
+}
+
+int ldns_wire2str_rdata_scan(uint8_t** d, size_t* dlen, char** s,
+       size_t* slen, uint16_t rrtype, uint8_t* pkt, size_t pktlen)
+{
+       /* try to prettyprint, but if that fails, use unknown format */
+       uint8_t* origd = *d;
+       char* origs = *s;
+       size_t origdlen = *dlen, origslen = *slen;
+       uint16_t r_cnt, r_max;
+       ldns_rdf_type rdftype;
+       int w = 0, n;
+
+       const ldns_rr_descriptor *desc = ldns_rr_descript(rrtype);
+       if(!desc) /* unknown format */
+               return ldns_wire2str_rdata_unknown_scan(d, dlen, s, slen);
+       /* dlen equals the rdatalen for the rdata */
+
+       r_max = ldns_rr_descriptor_maximum(desc);
+       for(r_cnt=0; r_cnt < r_max; r_cnt++) {
+               if(*dlen == 0) {
+                       if(r_cnt < ldns_rr_descriptor_minimum(desc))
+                               goto failed;
+                       break; /* nothing more to print */
+               }
+               rdftype = ldns_rr_descriptor_field_type(desc, r_cnt);
+               if(r_cnt != 0)
+                       w += ldns_str_print(s, slen, " ");
+               n = ldns_wire2str_rdf_scan(d, dlen, s, slen, rdftype,
+                       pkt, pktlen);
+               if(n == -1) {
+               failed:
+                       /* failed, use unknown format */
+                       *d = origd; *s = origs;
+                       *dlen = origdlen; *slen = origslen;
+                       return ldns_wire2str_rdata_unknown_scan(d, dlen,
+                               s, slen);
+               }
+               w += n;
+       }
+       return w;
+}
+
+int ldns_wire2str_rdata_unknown_scan(uint8_t** d, size_t* dlen, char** s,
+       size_t* slen)
+{
+       int w = 0;
+
+       /* print length */
+       w += ldns_str_print(s, slen, "\\# %u", (unsigned)*dlen);
+
+       /* print rdlen in hex */
+       if(*dlen != 0)
+               w += ldns_str_print(s, slen, " ");
+       w += print_hex_buf(s, slen, *d, *dlen);
+       (*d) += *dlen;
+       (*dlen) = 0;
+       return w;
+}
+
+/** print and escape one character for a domain dname */
+static int dname_char_print(char** s, size_t* slen, char c)
+{
+       if(c == '.' || c == ';' || c == '(' || c == ')' || c == '\\')
+               return ldns_str_print(s, slen, "\\%c", c);
+       else if(!(isascii((int)c) && isgraph((int)c)))
+               return ldns_str_print(s, slen, "\\%03u", (unsigned)c);
+       /* plain printout */
+       if(*slen) {
+               **s = c;
+               (*s)++;
+               (*slen)--;
+       }
+       return 1;
+}
+
+int ldns_wire2str_dname_scan(uint8_t** d, size_t* dlen, char** s, size_t* slen,
+       uint8_t* pkt, size_t pktlen)
+{
+       int w = 0;
+       /* spool labels onto the string, use compression if its there */
+       uint8_t* pos = *d;
+       unsigned i, counter=0;
+       const unsigned maxcompr = 1000; /* loop detection, max compr ptrs */
+       int in_buf = 1;
+       if(*dlen == 0) return ldns_str_print(s, slen, "ErrorMissingDname");
+       if(*pos == 0) {
+               (*d)++;
+               (*dlen)--;
+               return ldns_str_print(s, slen, ".");
+       }
+       while(*pos) {
+               /* read label length */
+               uint8_t labellen = *pos++;
+               if(in_buf) { (*d)++; (*dlen)--; }
+
+               /* find out what sort of label we have */
+               if((labellen&0xc0) == 0xc0) {
+                       /* compressed */
+                       uint16_t target = 0;
+                       if(in_buf && *dlen == 0)
+                               return w + ldns_str_print(s, slen,
+                                       "ErrorPartialDname");
+                       else if(!in_buf && pos+1 > pkt+pktlen)
+                               return w + ldns_str_print(s, slen,
+                                       "ErrorPartialDname");
+                       target = ((labellen&0x3f)<<8) | *pos;
+                       if(in_buf) { (*d)++; (*dlen)--; }
+                       /* move to target, if possible */
+                       if(!pkt || target >= pktlen)
+                               return w + ldns_str_print(s, slen,
+                                       "ErrorComprPtrOutOfBounds");
+                       if(counter++ > maxcompr)
+                               return w + ldns_str_print(s, slen,
+                                       "ErrorComprPtrLooped");
+                       in_buf = 0;
+                       pos = pkt+target;
+                       continue;
+               } else if((labellen&0xc0)) {
+                       /* notimpl label type */
+                       w += ldns_str_print(s, slen,
+                               "ErrorLABELTYPE%xIsUnknown",
+                               (int)(labellen&0xc0));
+                       return w;
+               }
+
+               /* spool label characters, end with '.' */
+               if(in_buf && *dlen < labellen) labellen = *dlen;
+               else if(!in_buf && pos+labellen > pkt+pktlen)
+                       labellen = (uint8_t)(pkt + pktlen - pos);
+               for(i=0; i<(unsigned)labellen; i++) {
+                       w += dname_char_print(s, slen, (char)(*pos++));
+               }
+               if(in_buf) {
+                       (*d) += labellen;
+                       (*dlen) -= labellen;
+                       if(*dlen == 0) break;
+               }
+               w += ldns_str_print(s, slen, ".");
+       }
+       /* skip over final root label */
+       if(in_buf && *dlen > 0) { (*d)++; (*dlen)--; }
+       /* in case we printed no labels, terminate dname */
+       if(w == 0) w += ldns_str_print(s, slen, ".");
+       return w;
+}
+
+int ldns_wire2str_opcode_print(char** s, size_t* slen, int opcode)
+{
+       ldns_lookup_table *lt = ldns_lookup_by_id(ldns_opcodes, opcode);
+       if (lt && lt->name) {
+               return ldns_str_print(s, slen, "%s", lt->name);
+       }
+       return ldns_str_print(s, slen, "OPCODE%u", (unsigned)opcode);
+}
+
+int ldns_wire2str_rcode_print(char** s, size_t* slen, int rcode)
+{
+       ldns_lookup_table *lt = ldns_lookup_by_id(ldns_rcodes, rcode);
+       if (lt && lt->name) {
+               return ldns_str_print(s, slen, "%s", lt->name);
+       }
+       return ldns_str_print(s, slen, "RCODE%u", (unsigned)rcode);
+}
+
+int ldns_wire2str_class_print(char** s, size_t* slen, uint16_t rrclass)
+{
+       ldns_lookup_table *lt = ldns_lookup_by_id(ldns_rr_classes,
+               (int)rrclass);
+       if (lt && lt->name) {
+               return ldns_str_print(s, slen, "%s", lt->name);
+       }
+       return ldns_str_print(s, slen, "CLASS%u", (unsigned)rrclass);
+}
+
+int ldns_wire2str_type_print(char** s, size_t* slen, uint16_t rrtype)
+{
+       const ldns_rr_descriptor *descriptor = ldns_rr_descript(rrtype);
+       if (descriptor && descriptor->_name) {
+               return ldns_str_print(s, slen, "%s", descriptor->_name);
+       }
+       return ldns_str_print(s, slen, "TYPE%u", (unsigned)rrtype);
+}
+
+int ldns_wire2str_edns_option_code_print(char** s, size_t* slen,
+       uint16_t opcode)
+{
+       ldns_lookup_table *lt = ldns_lookup_by_id(ldns_edns_options,
+               (int)opcode);
+       if (lt && lt->name) {
+               return ldns_str_print(s, slen, "%s", lt->name);
+       }
+       return ldns_str_print(s, slen, "OPT%u", (unsigned)opcode);
+}
+
+int ldns_wire2str_class_scan(uint8_t** d, size_t* dlen, char** s, size_t* slen)
+{
+       uint16_t c;
+       if(*dlen == 0) return 0;
+       if(*dlen < 2) return print_remainder_hex("Error malformed 0x", d, dlen, s, slen);
+       c = ldns_read_uint16(*d);
+       (*d)+=2;
+       (*dlen)-=2;
+       return ldns_wire2str_class_print(s, slen, c);
+}
+
+int ldns_wire2str_type_scan(uint8_t** d, size_t* dlen, char** s, size_t* slen)
+{
+       uint16_t t;
+       if(*dlen == 0) return 0;
+       if(*dlen < 2) return print_remainder_hex("Error malformed 0x", d, dlen, s, slen);
+       t = ldns_read_uint16(*d);
+       (*d)+=2;
+       (*dlen)-=2;
+       return ldns_wire2str_type_print(s, slen, t);
+}
+
+int ldns_wire2str_ttl_scan(uint8_t** d, size_t* dlen, char** s, size_t* slen)
+{
+       uint32_t ttl;
+       if(*dlen == 0) return 0;
+       if(*dlen < 4) return print_remainder_hex("Error malformed 0x", d, dlen, s, slen);
+       ttl = ldns_read_uint32(*d);
+       (*d)+=4;
+       (*dlen)-=4;
+       return ldns_str_print(s, slen, "%u", (unsigned)ttl);
+}
+
+int ldns_wire2str_rdf_scan(uint8_t** d, size_t* dlen, char** s, size_t* slen,
+       ldns_rdf_type rdftype, uint8_t* pkt, size_t pktlen)
+{
+       if(*dlen == 0) return 0;
+       switch(rdftype) {
+       case LDNS_RDF_TYPE_NONE:
+               return 0;
+       case LDNS_RDF_TYPE_DNAME:
+               return ldns_wire2str_dname_scan(d, dlen, s, slen, pkt, pktlen);
+       case LDNS_RDF_TYPE_INT8:
+               return ldns_wire2str_int8_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_INT16:
+               return ldns_wire2str_int16_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_INT32:
+               return ldns_wire2str_int32_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_PERIOD:
+               return ldns_wire2str_period_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_TSIGTIME:
+               return ldns_wire2str_tsigtime_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_A:
+               return ldns_wire2str_a_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_AAAA:
+               return ldns_wire2str_aaaa_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_STR:
+               return ldns_wire2str_str_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_APL:
+               return ldns_wire2str_apl_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_B32_EXT:
+               return ldns_wire2str_b32_ext_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_B64:
+               return ldns_wire2str_b64_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_HEX:
+               return ldns_wire2str_hex_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_NSEC:
+               return ldns_wire2str_nsec_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_NSEC3_SALT:
+               return ldns_wire2str_nsec3_salt_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_TYPE:
+               return ldns_wire2str_type_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_CLASS:
+               return ldns_wire2str_class_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_CERT_ALG:
+               return ldns_wire2str_cert_alg_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_ALG:
+               return ldns_wire2str_alg_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_UNKNOWN:
+               return ldns_wire2str_unknown_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_TIME:
+               return ldns_wire2str_time_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_LOC:
+               return ldns_wire2str_loc_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_WKS:
+       case LDNS_RDF_TYPE_SERVICE:
+               return ldns_wire2str_wks_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_NSAP:
+               return ldns_wire2str_nsap_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_ATMA:
+               return ldns_wire2str_atma_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_IPSECKEY:
+               return ldns_wire2str_ipseckey_scan(d, dlen, s, slen, pkt,
+                       pktlen);
+       case LDNS_RDF_TYPE_INT16_DATA:
+               return ldns_wire2str_int16_data_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER:
+               return ldns_wire2str_b32_ext_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_ILNP64:
+               return ldns_wire2str_ilnp64_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_EUI48:
+               return ldns_wire2str_eui48_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_EUI64:
+               return ldns_wire2str_eui64_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_TAG:
+               return ldns_wire2str_tag_scan(d, dlen, s, slen);
+       case LDNS_RDF_TYPE_LONG_STR:
+               return ldns_wire2str_long_str_scan(d, dlen, s, slen);
+       }
+       /* unknown rdf type */
+       return -1;
+}
+
+int ldns_wire2str_int8_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       int w;
+       if(*dl < 1) return -1;
+       w = ldns_str_print(s, sl, "%u", (unsigned)**d);
+       (*d)++;
+       (*dl)--;
+       return w;
+}
+
+int ldns_wire2str_int16_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       int w;
+       if(*dl < 2) return -1;
+       w = ldns_str_print(s, sl, "%lu", (unsigned long)ldns_read_uint16(*d));
+       (*d)+=2;
+       (*dl)-=2;
+       return w;
+}
+
+int ldns_wire2str_int32_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       int w;
+       if(*dl < 4) return -1;
+       w = ldns_str_print(s, sl, "%lu", (unsigned long)ldns_read_uint32(*d));
+       (*d)+=4;
+       (*dl)-=4;
+       return w;
+}
+
+int ldns_wire2str_period_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       int w;
+       if(*dl < 4) return -1;
+       w = ldns_str_print(s, sl, "%u", (unsigned)ldns_read_uint32(*d));
+       (*d)+=4;
+       (*dl)-=4;
+       return w;
+}
+
+int ldns_wire2str_tsigtime_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       /* tsigtime is 48 bits network order unsigned integer */
+       int w;
+       uint64_t tsigtime = 0;
+       uint64_t d0, d1, d2, d3, d4, d5;
+       if(*dl < 6) return -1;
+       d0 = (*d)[0]; /* cast to uint64 for shift operations */
+       d1 = (*d)[1];
+       d2 = (*d)[2];
+       d3 = (*d)[3];
+       d4 = (*d)[4];
+       d5 = (*d)[5];
+       tsigtime = (d0<<40) | (d1<<32) | (d2<<24) | (d3<<16) | (d4<<8) | d5;
+       w = ldns_str_print(s, sl, "%llu", (long long)tsigtime);
+       (*d)+=6;
+       (*dl)-=6;
+       return w;
+}
+
+int ldns_wire2str_a_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       char buf[32];
+       int w;
+       if(*dl < 4) return -1;
+       if(!inet_ntop(AF_INET, *d, buf, (socklen_t)sizeof(buf)))
+               return -1;
+       w = ldns_str_print(s, sl, "%s", buf);
+       (*d)+=4;
+       (*dl)-=4;
+       return w;
+}
+
+int ldns_wire2str_aaaa_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+#ifdef AF_INET6
+       char buf[64];
+       int w;
+       if(*dl < 16) return -1;
+       if(!inet_ntop(AF_INET6, *d, buf, (socklen_t)sizeof(buf)))
+               return -1;
+       w = ldns_str_print(s, sl, "%s", buf);
+       (*d)+=16;
+       (*dl)-=16;
+       return w;
+#else
+       return -1;
+#endif
+}
+
+/** printout escaped TYPE_STR character */
+static int str_char_print(char** s, size_t* sl, char c)
+{
+       if(isprint((int)c) || c == '\t') {
+               if(c == '\"' || c == '\\')
+                       return ldns_str_print(s, sl, "\\%c", c);
+               if(*sl) {
+                       **s = c;
+                       (*s)++;
+                       (*sl)--;
+               }
+               return 1;
+       }
+       return ldns_str_print(s, sl, "\\%03u", (unsigned)c);
+}
+
+int ldns_wire2str_str_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       int w = 0;
+       size_t i, len;
+       if(*dl < 1) return -1;
+       len = **d;
+       if(*dl < 1+len) return -1;
+       (*d)++;
+       (*dl)--;
+       w += ldns_str_print(s, sl, "\"");
+       for(i=0; i<len; i++)
+               w += str_char_print(s, sl, (char)(*d)[i]);
+       w += ldns_str_print(s, sl, "\"");
+       (*d)+=len;
+       (*dl)-=len;
+       return w;
+}
+
+int ldns_wire2str_apl_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       int i, w = 0;
+       uint16_t family;
+       uint8_t negation, prefix, adflength;
+       if(*dl < 4) return -1;
+       family = ldns_read_uint16(*d);
+       prefix = (*d)[2];
+       negation = ((*d)[3] & LDNS_APL_NEGATION);
+       adflength = ((*d)[3] & LDNS_APL_MASK);
+       if(*dl < 4+(size_t)adflength) return -1;
+       if(family != LDNS_APL_IP4 && family != LDNS_APL_IP6)
+               return -1; /* unknown address family */
+       if(negation)
+               w += ldns_str_print(s, sl, "!");
+       w += ldns_str_print(s, sl, "%u:", (unsigned)family);
+       if(family == LDNS_APL_IP4) {
+               /* check if prefix <32 ? */
+               /* address is variable length 0 - 4 */
+               for(i=0; i<4; i++) {
+                       if(i > 0)
+                               w += ldns_str_print(s, sl, ".");
+                       if(i < (int)adflength)
+                               w += ldns_str_print(s, sl, "%d", (*d)[4+i]);
+                       else    w += ldns_str_print(s, sl, "0");
+               }
+       } else if(family == LDNS_APL_IP6) {
+               /* check if prefix <128 ? */
+               /* address is variable length 0 - 16 */
+               for(i=0; i<16; i++) {
+                       if(i%2 == 0 && i>0)
+                               w += ldns_str_print(s, sl, ":");
+                       if(i < (int)adflength)
+                               w += ldns_str_print(s, sl, "%02x", (*d)[4+i]);
+                       else    w += ldns_str_print(s, sl, "00");
+               }
+       }
+       w += ldns_str_print(s, sl, "/%u", (unsigned)prefix);
+       (*d) += 4+adflength;
+       (*dl) -= 4+adflength;
+       return w;
+}
+
+int ldns_wire2str_b32_ext_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       size_t datalen;
+       size_t sz;
+       if(*dl < 1) return -1;
+       datalen = (*d)[0];
+       if(*dl < 1+datalen) return -1;
+       sz = ldns_b32_ntop_calculate_size(datalen);
+       if(*sl < sz+1) {
+               (*d) += datalen+1;
+               (*dl) -= (datalen+1);
+               return (int)sz; /* out of space really, but would need buffer
+                       in order to truncate the output */
+       }
+       ldns_b32_ntop_extended_hex((*d)+1, datalen, *s, *sl);
+       (*d) += datalen+1;
+       (*dl) -= (datalen+1);
+       (*s) += sz;
+       (*sl) -= sz;
+       return (int)sz;
+}
+
+/** scan number of bytes from wire into b64 presentation format */
+static int ldns_wire2str_b64_scan_num(uint8_t** d, size_t* dl, char** s,
+       size_t* sl, size_t num)
+{
+       /* b64_ntop_calculate size includes null at the end */
+       size_t sz = ldns_b64_ntop_calculate_size(num)-1;
+       if(*sl < sz+1) {
+               (*d) += num;
+               (*dl) -= num;
+               return (int)sz; /* out of space really, but would need buffer
+                       in order to truncate the output */
+       }
+       ldns_b64_ntop(*d, num, *s, *sl);
+       (*d) += num;
+       (*dl) -= num;
+       (*s) += sz;
+       (*sl) -= sz;
+       return (int)sz;
+}
+
+int ldns_wire2str_b64_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       return ldns_wire2str_b64_scan_num(d, dl, s, sl, *dl);
+}
+
+int ldns_wire2str_hex_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       return print_remainder_hex("", d, dl, s, sl);
+}
+
+int ldns_wire2str_nsec_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       uint8_t* p = *d;
+       size_t pl = *dl;
+       unsigned i, bit, window, block_len;
+       uint16_t t;
+       int w = 0;
+       
+       /* check for errors */
+       while(pl) {
+               if(pl < 2) return -1;
+               block_len = (unsigned)p[1];
+               if(pl < 2+block_len) return -1;
+               p += block_len+2;
+               pl -= block_len+2;
+       }
+
+       /* do it */
+       p = *d;
+       pl = *dl;
+       while(pl) {
+               if(pl < 2) return -1; /* cannot happen */
+               window = (unsigned)p[0];
+               block_len = (unsigned)p[1];
+               if(pl < 2+block_len) return -1; /* cannot happen */
+               p += 2;
+               for(i=0; i<block_len; i++) {
+                       if(p[i] == 0) continue;
+                       /* base type number for this octet */
+                       t = ((window)<<8) | (i << 3);
+                       for(bit=0; bit<8; bit++) {
+                               if((p[i]&(0x80>>bit))) {
+                                       if(w) w += ldns_str_print(s, sl, " ");
+                                       w += ldns_wire2str_type_print(s, sl,
+                                               t+bit);
+                               }
+                       }
+               }
+               p += block_len;
+               pl -= block_len+2;
+       }
+       (*d) += *dl;
+       (*dl) = 0;
+       return w;
+}
+
+int ldns_wire2str_nsec3_salt_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       size_t salt_len;
+       int w;
+       if(*dl < 1) return -1;
+       salt_len = (size_t)(*d)[0];
+       if(*dl < 1+salt_len) return -1;
+       (*d)++;
+       (*dl)--;
+       if(salt_len == 0) {
+               return ldns_str_print(s, sl, "-");
+       }
+       w = print_hex_buf(s, sl, *d, salt_len);
+       (*dl)-=salt_len;
+       (*d)+=salt_len;
+       return w;
+}
+
+int ldns_wire2str_cert_alg_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       ldns_lookup_table *lt;
+       int data, w;
+       if(*dl < 2) return -1;
+       data = (int)ldns_read_uint16(*d);
+       lt = ldns_lookup_by_id(ldns_cert_algorithms, data);
+       if(lt && lt->name)
+               w = ldns_str_print(s, sl, "%s", lt->name);
+       else    w = ldns_str_print(s, sl, "%d", data);
+       (*dl)-=2;
+       (*d)+=2;
+       return w;
+}
+
+int ldns_wire2str_alg_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       /* don't use algorithm mnemonics in the presentation format
+        * this kind of got sneaked into the rfc's */
+       return ldns_wire2str_int8_scan(d, dl, s, sl);
+}
+
+int ldns_wire2str_unknown_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       return ldns_wire2str_rdata_unknown_scan(d, dl, s, sl);
+}
+
+int ldns_wire2str_time_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       /* create a YYYYMMDDHHMMSS string if possible */
+       struct tm tm;
+       char date_buf[16];
+       uint32_t t;
+       memset(&tm, 0, sizeof(tm));
+       if(*dl < 4) return -1;
+       t = ldns_read_uint32(*d);
+       date_buf[15]=0;
+       if(ldns_serial_arithmitics_gmtime_r(t, time(NULL), &tm) &&
+               strftime(date_buf, 15, "%Y%m%d%H%M%S", &tm)) {
+               (*d) += 4;
+               (*dl) -= 4;
+               return ldns_str_print(s, sl, "%s", date_buf);
+       }
+       return -1;
+}
+
+static int
+loc_cm_print(char** str, size_t* sl, uint8_t mantissa, uint8_t exponent)
+{
+       int w = 0;
+       uint8_t i;
+       /* is it 0.<two digits> ? */
+       if(exponent < 2) {
+               if(exponent == 1)
+                       mantissa *= 10;
+               return ldns_str_print(str, sl, "0.%02ld", (long)mantissa);
+       }
+       /* always <digit><string of zeros> */
+       w += ldns_str_print(str, sl, "%d", (int)mantissa);
+       for(i=0; i<exponent-2; i++)
+               w += ldns_str_print(str, sl, "0");
+       return w;
+}
+
+int ldns_wire2str_loc_scan(uint8_t** d, size_t* dl, char** str, size_t* sl)
+{
+       /* we could do checking (ie degrees < 90 etc)? */
+       uint8_t version;
+       uint8_t size;
+       uint8_t horizontal_precision;
+       uint8_t vertical_precision;
+       uint32_t longitude;
+       uint32_t latitude;
+       uint32_t altitude;
+       char northerness;
+       char easterness;
+       uint32_t h;
+       uint32_t m;
+       double s;
+       uint32_t equator = (uint32_t)1 << 31; /* 2**31 */
+       int w = 0;
+
+       if(*dl < 16) return -1;
+       version = (*d)[0];
+       if(version != 0)
+               return ldns_wire2str_hex_scan(d, dl, str, sl);
+       size = (*d)[1];
+       horizontal_precision = (*d)[2];
+       vertical_precision = (*d)[3];
+
+       latitude = ldns_read_uint32((*d)+4);
+       longitude = ldns_read_uint32((*d)+8);
+       altitude = ldns_read_uint32((*d)+12);
+
+       if (latitude > equator) {
+               northerness = 'N';
+               latitude = latitude - equator;
+       } else {
+               northerness = 'S';
+               latitude = equator - latitude;
+       }
+       h = latitude / (1000 * 60 * 60);
+       latitude = latitude % (1000 * 60 * 60);
+       m = latitude / (1000 * 60);
+       latitude = latitude % (1000 * 60);
+       s = (double) latitude / 1000.0;
+       w += ldns_str_print(str, sl, "%02u %02u %0.3f %c ",
+               h, m, s, northerness);
+
+       if (longitude > equator) {
+               easterness = 'E';
+               longitude = longitude - equator;
+       } else {
+               easterness = 'W';
+               longitude = equator - longitude;
+       }
+       h = longitude / (1000 * 60 * 60);
+       longitude = longitude % (1000 * 60 * 60);
+       m = longitude / (1000 * 60);
+       longitude = longitude % (1000 * 60);
+       s = (double) longitude / (1000.0);
+       w += ldns_str_print(str, sl, "%02u %02u %0.3f %c ",
+               h, m, s, easterness);
+
+       s = ((double) altitude) / 100;
+       s -= 100000;
+
+       if(altitude%100 != 0)
+               w += ldns_str_print(str, sl, "%.2f", s);
+       else
+               w += ldns_str_print(str, sl, "%.0f", s);
+
+       w += ldns_str_print(str, sl, "m ");
+
+       w += loc_cm_print(str, sl, (size & 0xf0) >> 4, size & 0x0f);
+       w += ldns_str_print(str, sl, "m ");
+
+       w += loc_cm_print(str, sl, (horizontal_precision & 0xf0) >> 4,
+               horizontal_precision & 0x0f);
+       w += ldns_str_print(str, sl, "m ");
+
+       w += loc_cm_print(str, sl, (vertical_precision & 0xf0) >> 4,
+               vertical_precision & 0x0f);
+       w += ldns_str_print(str, sl, "m");
+
+       (*d)+=16;
+       (*dl)-=16;
+       return w;
+}
+
+int ldns_wire2str_wks_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       /* protocol, followed by bitmap of services */
+       const char* proto_name = NULL;
+       struct protoent *protocol;
+       struct servent *service;
+       uint8_t protocol_nr;
+       int bit, port, w = 0;
+       size_t i;
+
+       /* protocol */
+       if(*dl < 1) return -1;
+       protocol_nr = (*d)[0];
+       (*d)++;
+       (*dl)--;
+       protocol = getprotobynumber((int)protocol_nr);
+       if(protocol && (protocol->p_name != NULL)) {
+               w += ldns_str_print(s, sl, "%s", protocol->p_name);
+               proto_name = protocol->p_name;
+       } else  {
+               w += ldns_str_print(s, sl, "%u", (unsigned)protocol_nr);
+       }
+
+       for(i=0; i<*dl; i++) {
+               if((*d)[i] == 0)
+                       continue;
+               for(bit=0; bit<8; bit++) {
+                       if(!(((*d)[i])&(0x80>>bit)))
+                               continue;
+                       port = (int)i*8 + bit;
+                       service = getservbyport((int)htons((uint16_t)port),
+                               proto_name);
+                       if(service && service->s_name)
+                               w += ldns_str_print(s, sl, " %s",
+                                       service->s_name);
+                       else    w += ldns_str_print(s, sl, " %u",
+                                       (unsigned)port);
+               }
+       }
+
+#ifdef HAVE_ENDSERVENT
+       endservent();
+#endif
+#ifdef HAVE_ENDPROTOENT
+        endprotoent();
+#endif
+       (*d) += *dl;
+       (*dl) = 0;
+       return w;
+}
+
+int ldns_wire2str_nsap_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       return print_remainder_hex("0x", d, dl, s, sl);
+}
+
+int ldns_wire2str_atma_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       return print_remainder_hex("", d, dl, s, sl);
+}
+
+/* internal scan routine that can modify arguments on failure */
+static int ldns_wire2str_ipseckey_scan_internal(uint8_t** d, size_t* dl,
+       char** s, size_t* sl, uint8_t* pkt, size_t pktlen)
+{
+       /* http://www.ietf.org/internet-drafts/draft-ietf-ipseckey-rr-12.txt*/
+       uint8_t precedence, gateway_type, algorithm;
+       size_t public_key_size;
+       int w = 0;
+
+       if(*dl < 3) return -1;
+       precedence = (*d)[0];
+       gateway_type = (*d)[1];
+       algorithm = (*d)[2];
+       if(gateway_type > 3)
+               return -1; /* unknown */
+       (*d)+=3;
+       (*dl)-=3;
+       w += ldns_str_print(s, sl, "%d %d %d ",
+               (int)precedence, (int)gateway_type, (int)algorithm);
+
+       switch(gateway_type) {
+       case 0: /* no gateway */
+               w += ldns_str_print(s, sl, ".");
+               break;
+       case 1: /* ip4 */
+               w += ldns_wire2str_a_scan(d, dl, s, sl);
+               break;
+       case 2: /* ip6 */
+               w += ldns_wire2str_aaaa_scan(d, dl, s, sl);
+               break;
+       case 3: /* dname */
+               w += ldns_wire2str_dname_scan(d, dl, s, sl, pkt, pktlen);
+               break;
+       default: /* unknown */
+               return -1;
+       }
+
+       if(*dl < 1)
+               return -1;
+       public_key_size = (*d)[0];
+       if(*dl < public_key_size+1)
+               return -1;
+       (*d)++;
+       (*dl)--;
+       w += ldns_wire2str_b64_scan_num(d, dl, s, sl, public_key_size);
+       return w;
+}
+
+int ldns_wire2str_ipseckey_scan(uint8_t** d, size_t* dl, char** s, size_t* sl,
+       uint8_t* pkt, size_t pktlen)
+{
+       uint8_t* od = *d;
+       char* os = *s;
+       size_t odl = *dl, osl = *sl;
+       int w=ldns_wire2str_ipseckey_scan_internal(d, dl, s, sl, pkt, pktlen);
+       if(w == -1) {
+               *d = od;
+               *s = os;
+               *dl = odl;
+               *sl = osl;
+               return -1;
+       }
+       return w;
+}
+
+int ldns_wire2str_int16_data_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       uint16_t n;
+       if(*dl < 2)
+               return -1;
+       n = ldns_read_uint16(*d);
+       if(*dl < 2+(size_t)n)
+               return -1;
+       (*d)+=2;
+       (*dl)-=2;
+       return ldns_wire2str_b64_scan_num(d, dl, s, sl, n);
+}
+
+int ldns_wire2str_nsec3_next_owner_scan(uint8_t** d, size_t* dl, char** s,
+       size_t* sl)
+{
+       return ldns_wire2str_b32_ext_scan(d, dl, s, sl);
+}
+
+int ldns_wire2str_ilnp64_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       int w;
+       if(*dl < 8)
+               return -1;
+       w = ldns_str_print(s, sl, "%.4x:%.4x:%.4x:%.4x",
+               ldns_read_uint16(*d), ldns_read_uint16((*d)+2),
+               ldns_read_uint16((*d)+4), ldns_read_uint16((*d)+6));
+       (*d)+=8;
+       (*dl)-=8;
+       return w;
+}
+
+int ldns_wire2str_eui48_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       int w;
+       if(*dl < 6)
+               return -1;
+       w = ldns_str_print(s, sl, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
+               (*d)[0], (*d)[1], (*d)[2], (*d)[3], (*d)[4], (*d)[5]);
+       (*d)+=6;
+       (*dl)-=6;
+       return w;
+}
+
+int ldns_wire2str_eui64_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       int w;
+       if(*dl < 8)
+               return -1;
+       w = ldns_str_print(s, sl, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
+               (*d)[0], (*d)[1], (*d)[2], (*d)[3], (*d)[4], (*d)[5],
+               (*d)[6], (*d)[7]);
+       (*d)+=8;
+       (*dl)-=8;
+       return w;
+}
+
+int ldns_wire2str_tag_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       size_t i, n;
+       int w = 0;
+       if(*dl < 1)
+               return -1;
+       n = (size_t)((*d)[0]);
+       if(*dl < 1+n)
+               return -1;
+       for(i=0; i<n; i++)
+               if(!isalnum((int)(*d)[i]))
+                       return -1;
+       for(i=0; i<n; i++)
+               w += ldns_str_print(s, sl, "%c", (char)(*d)[i]);
+       (*d)+=n+1;
+       (*dl)-=(n+1);
+       return w;
+}
+
+int ldns_wire2str_long_str_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
+{
+       size_t i;
+       int w = 0;
+       w += ldns_str_print(s, sl, "\"");
+       for(i=0; i<*dl; i++)
+               w += str_char_print(s, sl, (char)(*d)[i]);
+       w += ldns_str_print(s, sl, "\"");
+       (*d)+=*dl;
+       (*dl)=0;
+       return w;
+}
+
+int ldns_wire2str_edns_llq_print(char** s, size_t* sl, uint8_t* data,
+       size_t len)
+{
+       /* LLQ constants */
+       const char* llq_errors[] = {"NO-ERROR", "SERV-FULL", "STATIC",
+               "FORMAT-ERR", "NO-SUCH-LLQ", "BAD-VERS", "UNKNOWN_ERR"};
+       const unsigned int llq_errors_num = 7;
+       const char* llq_opcodes[] = {"LLQ-SETUP", "LLQ-REFRESH", "LLQ-EVENT"};
+       const unsigned int llq_opcodes_num = 3;
+       uint16_t version, llq_opcode, error_code;
+       uint64_t llq_id;
+       uint32_t lease_life; /* Requested or granted life of LLQ, in seconds */
+       int w = 0;
+
+       /* read the record */
+       if(len != 18) {
+               w += ldns_str_print(s, sl, "malformed LLQ ");
+               w += print_hex_buf(s, sl, data, len);
+               return w;
+       }
+       version = ldns_read_uint16(data);
+       llq_opcode = ldns_read_uint16(data+2);
+       error_code = ldns_read_uint16(data+4);
+       memmove(&llq_id, data+6, sizeof(llq_id));
+       lease_life = ldns_read_uint32(data+14);
+
+       /* print it */
+       w += ldns_str_print(s, sl, "v%d ", (int)version);
+       if(llq_opcode < llq_opcodes_num)
+               w += ldns_str_print(s, sl, "%s", llq_opcodes[llq_opcode]);
+       else    w += ldns_str_print(s, sl, "opcode %d", (int)llq_opcode);
+       if(error_code < llq_errors_num)
+               w += ldns_str_print(s, sl, " %s", llq_errors[error_code]);
+       else    w += ldns_str_print(s, sl, " error %d", (int)error_code);
+       w += ldns_str_print(s, sl, " id %llx lease-life %lu",
+               (unsigned long long)llq_id, (unsigned long)lease_life);
+       return w;
+}
+
+int ldns_wire2str_edns_ul_print(char** s, size_t* sl, uint8_t* data,
+       size_t len)
+{
+       uint32_t lease;
+       int w = 0;
+       if(len != 4) {
+               w += ldns_str_print(s, sl, "malformed UL ");
+               w += print_hex_buf(s, sl, data, len);
+               return w;
+       }
+       lease = ldns_read_uint32(data);
+       w += ldns_str_print(s, sl, "lease %lu", (unsigned long)lease);
+       return w;
+}
+
+int ldns_wire2str_edns_nsid_print(char** s, size_t* sl, uint8_t* data,
+       size_t len)
+{
+       int w = 0;
+       size_t i, printed=0;
+       w += print_hex_buf(s, sl, data, len);
+       for(i=0; i<len; i++) {
+               if(isprint((int)data[i]) || data[i] == '\t') {
+                       if(!printed) {
+                               w += ldns_str_print(s, sl, " (");
+                               printed = 1;
+                       }
+                       w += ldns_str_print(s, sl, "%c", (char)data[i]);
+               }
+       }
+       if(printed)
+               w += ldns_str_print(s, sl, ")");
+       return w;
+}
+
+int ldns_wire2str_edns_dau_print(char** s, size_t* sl, uint8_t* data,
+       size_t len)
+{
+       ldns_lookup_table *lt;
+       size_t i;
+       int w = 0;
+       for(i=0; i<len; i++) {
+               lt = ldns_lookup_by_id(ldns_algorithms, (int)data[i]);
+               if(lt && lt->name)
+                       w += ldns_str_print(s, sl, " %s", lt->name);
+               else    w += ldns_str_print(s, sl, " %d", (int)data[i]);
+       }
+       return w;
+}
+
+int ldns_wire2str_edns_dhu_print(char** s, size_t* sl, uint8_t* data,
+       size_t len)
+{
+       ldns_lookup_table *lt;
+       size_t i;
+       int w = 0;
+       for(i=0; i<len; i++) {
+               lt = ldns_lookup_by_id(ldns_hashes, (int)data[i]);
+               if(lt && lt->name)
+                       w += ldns_str_print(s, sl, " %s", lt->name);
+               else    w += ldns_str_print(s, sl, " %d", (int)data[i]);
+       }
+       return w;
+}
+
+int ldns_wire2str_edns_n3u_print(char** s, size_t* sl, uint8_t* data,
+       size_t len)
+{
+       size_t i;
+       int w = 0;
+       for(i=0; i<len; i++) {
+               if(data[i] == 1)
+                       w += ldns_str_print(s, sl, " SHA1");
+               else    w += ldns_str_print(s, sl, " %d", (int)data[i]);
+       }
+       return w;
+}
+
+int ldns_wire2str_edns_subnet_print(char** s, size_t* sl, uint8_t* data,
+       size_t len)
+{
+       int w = 0;
+       uint16_t family;
+       uint8_t source, scope;
+       if(len < 4) {
+               w += ldns_str_print(s, sl, "malformed subnet ");
+               w += print_hex_buf(s, sl, data, len);
+               return w;
+       }
+       family = ldns_read_uint16(data);
+       source = data[2];
+       scope = data[3];
+       if(family == 1) {
+               /* IP4 */
+               char buf[64];
+               uint8_t ip4[4];
+               memset(ip4, 0, sizeof(ip4));
+               if(len-4 > 4) {
+                       w += ldns_str_print(s, sl, "trailingdata:");
+                       w += print_hex_buf(s, sl, data+4+4, len-4-4);
+                       w += ldns_str_print(s, sl, " ");
+                       len = 4+4;
+               }
+               memmove(ip4, data+4, len-4);
+               if(!inet_ntop(AF_INET, ip4, buf, (socklen_t)sizeof(buf))) {
+                       w += ldns_str_print(s, sl, "ip4ntoperror ");
+                       w += print_hex_buf(s, sl, data+4+4, len-4-4);
+               } else {
+                       w += ldns_str_print(s, sl, "%s", buf);
+               }
+       } else if(family == 2) {
+               /* IP6 */
+               char buf[64];
+               uint8_t ip6[16];
+               memset(ip6, 0, sizeof(ip6));
+               if(len-4 > 16) {
+                       w += ldns_str_print(s, sl, "trailingdata:");
+                       w += print_hex_buf(s, sl, data+4+16, len-4-16);
+                       w += ldns_str_print(s, sl, " ");
+                       len = 4+16;
+               }
+               memmove(ip6, data+4, len-4);
+#ifdef AF_INET6
+               if(!inet_ntop(AF_INET6, ip6, buf, (socklen_t)sizeof(buf))) {
+                       w += ldns_str_print(s, sl, "ip6ntoperror ");
+                       w += print_hex_buf(s, sl, data+4+4, len-4-4);
+               } else {
+                       w += ldns_str_print(s, sl, "%s", buf);
+               }
+#else
+               w += print_hex_buf(s, sl, data+4+4, len-4-4);
+#endif
+       } else {
+               /* unknown */
+               w += ldns_str_print(s, sl, "family %d ",
+                       (int)family);
+               w += print_hex_buf(s, sl, data, len);
+       }
+       w += ldns_str_print(s, sl, "/%d scope /%d", (int)source, (int)scope);
+       return w;
+}
+
+int ldns_wire2str_edns_option_print(char** s, size_t* sl,
+       uint16_t option_code, uint8_t* optdata, size_t optlen)
+{
+       int w = 0;
+       w += ldns_wire2str_edns_option_code_print(s, sl, option_code);
+       w += ldns_str_print(s, sl, ": ");
+       switch(option_code) {
+       case LDNS_EDNS_LLQ:
+               w += ldns_wire2str_edns_llq_print(s, sl, optdata, optlen);
+               break;
+       case LDNS_EDNS_UL:
+               w += ldns_wire2str_edns_ul_print(s, sl, optdata, optlen);
+               break;
+       case LDNS_EDNS_NSID:
+               w += ldns_wire2str_edns_nsid_print(s, sl, optdata, optlen);
+               break;
+       case LDNS_EDNS_DAU:
+               w += ldns_wire2str_edns_dau_print(s, sl, optdata, optlen);
+               break;
+       case LDNS_EDNS_DHU:
+               w += ldns_wire2str_edns_dhu_print(s, sl, optdata, optlen);
+               break;
+       case LDNS_EDNS_N3U:
+               w += ldns_wire2str_edns_n3u_print(s, sl, optdata, optlen);
+               break;
+       case LDNS_EDNS_CLIENT_SUBNET:
+               w += ldns_wire2str_edns_subnet_print(s, sl, optdata, optlen);
+               break;
+       default:
+               /* unknown option code */
+               w += print_hex_buf(s, sl, optdata, optlen);
+               break;
+       }
+       return w;
+}
+
+/** print the edns options to string */
+static int
+print_edns_opts(char** s, size_t* sl, uint8_t* rdata, size_t rdatalen)
+{
+       uint16_t option_code, option_len;
+       int w = 0;
+       while(rdatalen > 0) {
+               /* option name */
+               if(rdatalen < 4) {
+                       w += ldns_str_print(s, sl, " ; malformed: ");
+                       w += print_hex_buf(s, sl, rdata, rdatalen);
+                       return w;
+               }
+               option_code = ldns_read_uint16(rdata);
+               option_len = ldns_read_uint16(rdata+2);
+               rdata += 4;
+               rdatalen -= 4;
+
+               /* option value */
+               if(rdatalen < (size_t)option_len) {
+                       w += ldns_str_print(s, sl, " ; malformed ");
+                       w += ldns_wire2str_edns_option_code_print(s, sl,
+                               option_code);
+                       w += ldns_str_print(s, sl, ": ");
+                       w += print_hex_buf(s, sl, rdata, rdatalen);
+                       return w;
+               }
+               w += ldns_str_print(s, sl, " ; ");
+               w += ldns_wire2str_edns_option_print(s, sl, option_code,
+                       rdata, option_len);
+               rdata += option_len;
+               rdatalen -= option_len;
+       }
+       return w;
+}
+
+int ldns_wire2str_edns_scan(uint8_t** data, size_t* data_len, char** str,
+        size_t* str_len, uint8_t* pkt, size_t pktlen)
+{
+       int w = 0;
+       uint8_t ext_rcode, edns_version;
+       uint16_t udpsize, edns_bits, rdatalen;
+       w += ldns_str_print(str, str_len, "; EDNS:");
+
+       /* some input checks, domain name */
+       if(*data_len < 1+10)
+               return w + print_remainder_hex("Error malformed 0x",
+                       data, data_len, str, str_len);
+       if(*data[0] != 0) {
+               return w + print_remainder_hex("Error nonrootdname 0x",
+                       data, data_len, str, str_len);
+       }
+       (*data)++;
+       (*data_len)--;
+
+       /* check type and read fixed contents */
+       if(ldns_read_uint16((*data)) != LDNS_RR_TYPE_OPT) {
+               return w + print_remainder_hex("Error nottypeOPT 0x",
+                       data, data_len, str, str_len);
+       }
+       udpsize = ldns_read_uint16((*data)+2);
+       ext_rcode = (*data)[4];
+       edns_version = (*data)[5];
+       edns_bits = ldns_read_uint16((*data)+6);
+       rdatalen = ldns_read_uint16((*data)+8);
+       (*data)+=10;
+       (*data_len)-=10;
+
+       w += ldns_str_print(str, str_len, " version: %u;",
+               (unsigned)edns_version);
+       w += ldns_str_print(str, str_len, " flags:");
+       if((edns_bits & LDNS_EDNS_MASK_DO_BIT))
+               w += ldns_str_print(str, str_len, " do");
+       /* the extended rcode is the value set, shifted four bits,
+        * and or'd with the original rcode */
+       if(ext_rcode) {
+               int rc = ((int)ext_rcode)<<4;
+               if(pkt && pktlen >= LDNS_HEADER_SIZE)
+                       rc |= LDNS_RCODE_WIRE(pkt);
+               w += ldns_str_print(str, str_len, " ; ext-rcode: %d", rc);
+       }
+       w += ldns_str_print(str, str_len, " ; udp: %u", (unsigned)udpsize);
+
+       if(rdatalen) {
+               if(*data_len < rdatalen) {
+                       w += ldns_str_print(str, str_len,
+                               " ; Error EDNS rdata too short; ");
+                       rdatalen = *data_len;
+               }
+               w += print_edns_opts(str, str_len, *data, rdatalen);
+               (*data) += rdatalen;
+               (*data_len) -= rdatalen;
+       }
+       w += ldns_str_print(str, str_len, "\n");
+       return w;
+}
diff --git a/ldns/wire2str.h b/ldns/wire2str.h
new file mode 100644 (file)
index 0000000..a29ace7
--- /dev/null
@@ -0,0 +1,973 @@
+/**
+ * wire2str.h -  txt presentation of RRs
+ *
+ * (c) NLnet Labs, 2005-2006
+ *
+ * See the file LICENSE for the license
+ */
+
+/**
+ * \file
+ *
+ * Contains functions to translate the wireformat to text
+ * representation, as well as functions to print them.
+ */
+
+#ifndef LDNS_WIRE2STR_H
+#define LDNS_WIRE2STR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+struct ldns_struct_lookup_table;
+enum ldns_enum_rdf_type;
+
+/* lookup tables for standard DNS stuff  */
+/** Taken from RFC 2535, section 7.  */
+extern struct ldns_struct_lookup_table* ldns_algorithms;
+/** DS record hash algorithms */
+extern struct ldns_struct_lookup_table* ldns_hashes;
+/** Taken from RFC 2538, section 2.1.  */
+extern struct ldns_struct_lookup_table* ldns_cert_algorithms;
+/** Response codes */
+extern struct ldns_struct_lookup_table* ldns_rcodes;
+/** Operation codes */
+extern struct ldns_struct_lookup_table* ldns_opcodes;
+/** EDNS flags */
+extern struct ldns_struct_lookup_table* ldns_edns_flags;
+/** EDNS option codes */
+extern struct ldns_struct_lookup_table* ldns_edns_options;
+/** error string from wireparse */
+extern struct ldns_struct_lookup_table* ldns_wireparse_errors;
+
+/**
+ * Convert wireformat packet to a string representation
+ * @param data: wireformat packet data (starting at ID bytes).
+ * @param len: length of packet.
+ * @return string(malloced) or NULL on failure.
+ */
+char* ldns_wire2str_pkt(uint8_t* data, size_t len);
+
+/**
+ * Convert wireformat RR to a string representation.
+ * @param rr: the wireformat RR, in uncompressed form.  Starts at the domain
+ *     name start, ends with the rdata of the RR.
+ * @param len: length of the rr wireformat.
+ * @return string(malloced) or NULL on failure.
+ */
+char* ldns_wire2str_rr(uint8_t* rr, size_t len);
+
+/**
+ * Conver wire dname to a string.
+ * @param dname: the dname in uncompressed wireformat.
+ * @param dname_len: length of the dname.
+ * @return string or NULL on failure.
+ */
+char* ldns_wire2str_dname(uint8_t* dname, size_t dname_len);
+
+/**
+ * Convert wire RR type to a string, 'MX', 'TYPE1234'...
+ * @param rrtype: the RR type in host order.
+ * @return malloced string with the RR type or NULL on malloc failure.
+ */
+char* ldns_wire2str_type(uint16_t rrtype);
+
+/**
+ * Convert wire RR class to a string, 'IN', 'CLASS1'.
+ * @param rrclass: the RR class in host order.
+ * @return malloced string with the RR class or NULL on malloc failure.
+ */
+char* ldns_wire2str_class(uint16_t rrclass);
+
+/**
+ * Convert wire packet rcode to a string, 'NOERROR', 'NXDOMAIN'...
+ * @param rcode: as integer, host order
+ * @return malloced string with the rcode or NULL on malloc failure.
+ */
+char* ldns_wire2str_rcode(int rcode);
+
+/**
+ * Print to string, move string along for next content. With va_list.
+ * @param str: string buffer.  Adjusted at end to after the output.
+ * @param slen: length of the string buffer.  Adjusted at end.
+ * @param format: printf format string.
+ * @param args: arguments for printf.
+ * @return number of characters needed. Can be larger than slen.
+ */
+int ldns_str_vprint(char** str, size_t* slen, const char* format, va_list args);
+
+/**
+ * Print to string, move string along for next content.
+ * @param str: string buffer.  Adjusted at end to after the output.
+ * @param slen: length of the string buffer.  Adjusted at end.
+ * @param format: printf format string and arguments for it.
+ * @return number of characters needed. Can be larger than slen.
+ */
+int ldns_str_print(char** str, size_t* slen, const char* format, ...)
+       ATTR_FORMAT(printf, 3, 4);
+
+/**
+ * Convert wireformat packet to a string representation with user buffer
+ * It appends every RR with default comments.
+ * For more formatter options use the function: TBD(TODO)
+ * @param data: wireformat packet data (starting at ID bytes).
+ * @param data_len: length of packet.
+ * @param str: the string buffer for the output.
+ *     If you pass NULL as the str the return value of the function is
+ *     the str_len you need for the entire packet.  It does not include
+ *     the 0 byte at the end.
+ * @param str_len: the size of the string buffer.  If more is needed, it'll
+ *     silently truncate the output to fit in the buffer.
+ * @return the number of characters for this element, excluding zerobyte.
+ *     Is larger than str_len if output was truncated.
+ */
+int ldns_wire2str_pkt_buf(uint8_t* data, size_t data_len, char* str,
+       size_t str_len);
+
+/**
+ * Scan wireformat packet to a string representation with user buffer
+ * It appends every RR with default comments.
+ * For more formatter options use the function: TBD(TODO)
+ * @param data: wireformat packet data (starting at ID bytes).
+ * @param data_len: length of packet.
+ * @param str: the string buffer for the output.
+ * @param str_len: the size of the string buffer.
+ * @return number of characters for string.
+ * returns the number of characters that are needed (except terminating null),
+ * so it may return a value larger than str_len.
+ * On error you get less output (i.e. shorter output in str (null terminated))
+ * On exit the data, data_len, str and str_len values are adjusted to move them
+ * from their original position along the input and output for the content
+ * that has been consumed (and produced) by this function.  If the end of the
+ * output string is reached, *str_len is set to 0.  The output string is null
+ * terminated (shortening the output if necessary).  If the end of the input
+ * is reached *data_len is set to 0.
+ */
+int ldns_wire2str_pkt_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat rr to string, with user buffers.  It shifts the arguments
+ * to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param pkt: packet for decompression, if NULL no decompression.
+ * @param pktlen: length of packet buffer.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_rr_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len, uint8_t* pkt, size_t pktlen);
+
+/**
+ * Scan wireformat question rr to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param pkt: packet for decompression, if NULL no decompression.
+ * @param pktlen: length of packet buffer.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_rrquestion_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len, uint8_t* pkt, size_t pktlen);
+
+/**
+ * Scan wireformat RR to string in unknown RR format, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param pkt: packet for decompression, if NULL no decompression.
+ * @param pktlen: length of packet buffer.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_rr_unknown_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len, uint8_t* pkt, size_t pktlen);
+
+/**
+ * Print to string the RR-information comment in default format,
+ * with user buffers.  Moves string along.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param rr: wireformat data.
+ * @param rrlen: length of data buffer.
+ * @param dname_off: offset in buffer behind owner dname, the compressed size
+ *     of the owner name.
+ * @param rrtype: type of the RR, host format.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_rr_comment_print(char** str, size_t* str_len, uint8_t* rr,
+       size_t rrlen, size_t dname_off, uint16_t rrtype);
+
+/**
+ * Scan wireformat packet header to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_header_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat rdata to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.  The length of the rdata in the
+ *     buffer.  The rdatalen itself has already been scanned, the data
+ *     points to the rdata after the rdatalen.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param rrtype: RR type of Rdata, host format.
+ * @param pkt: packet for decompression, if NULL no decompression.
+ * @param pktlen: length of packet buffer.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_rdata_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len, uint16_t rrtype, uint8_t* pkt, size_t pktlen);
+
+/**
+ * Scan wireformat rdata to string in unknown format, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer, the length of the rdata in buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_rdata_unknown_scan(uint8_t** data, size_t* data_len,
+       char** str, size_t* str_len);
+
+/**
+ * Scan wireformat domain name to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param pkt: packet for decompression, if NULL no decompression.
+ * @param pktlen: length of packet buffer.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_dname_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len, uint8_t* pkt, size_t pktlen);
+
+/**
+ * Scan wireformat rr type to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_type_scan(uint8_t** data, size_t* data_len, char** str,
+        size_t* str_len);
+
+/**
+ * Scan wireformat rr class to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_class_scan(uint8_t** data, size_t* data_len, char** str,
+        size_t* str_len);
+
+/**
+ * Scan wireformat rr ttl to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_ttl_scan(uint8_t** data, size_t* data_len, char** str,
+        size_t* str_len);
+
+
+/**
+ * Print host format rr type to string.  Moves string along, user buffers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param rrtype: host format rr type.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_type_print(char** str, size_t* str_len, uint16_t rrtype);
+
+/**
+ * Print host format rr class to string.  Moves string along, user buffers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param rrclass: host format rr class.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_class_print(char** str, size_t* str_len, uint16_t rrclass);
+
+/**
+ * Print host format rcode to string.  Moves string along, user buffers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param rcode: host format rcode number.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_rcode_print(char** str, size_t* str_len, int rcode);
+
+/**
+ * Print host format opcode to string.  Moves string along, user buffers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param opcode: host format opcode number.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_opcode_print(char** str, size_t* str_len, int opcode);
+
+/**
+ * Print host format EDNS0 option to string.  Moves string along, user buffers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param opcode: host format option number.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_edns_option_code_print(char** str, size_t* str_len,
+       uint16_t opcode);
+
+/**
+ * Convert RR to string presentation format, on one line.  User buffer.
+ * @param rr: wireformat RR data
+ * @param rr_len: length of the rr wire data.
+ * @param str: the string buffer to write to.
+ *     If you pass NULL as the str, the return value of the function is
+ *     the str_len you need for the entire packet.  It does not include
+ *     the 0 byte at the end.
+ * @param str_len: the size of the string buffer.  If more is needed, it'll
+ *     silently truncate the output to fit in the buffer.
+ * @return the number of characters for this element, excluding zerobyte.
+ *     Is larger than str_len if output was truncated.
+ */
+int ldns_wire2str_rr_buf(uint8_t* rr, size_t rr_len, char* str,
+       size_t str_len);
+
+/**
+ * 3597 printout of an RR in unknown rr format.
+ * There are more format and comment options available for printout
+ * with the function: TBD(TODO)
+ * @param rr: wireformat RR data
+ * @param rr_len: length of the rr wire data.
+ * @param str: the string buffer to write to.
+ *     If you pass NULL as the str, the return value of the function is
+ *     the str_len you need for the entire rr.  It does not include
+ *     the 0 byte at the end.
+ * @param str_len: the size of the string buffer.  If more is needed, it'll
+ *     silently truncate the output to fit in the buffer.
+ * @return the number of characters for this element, excluding zerobyte.
+ *     Is larger than str_len if output was truncated.
+ */
+int ldns_wire2str_rr_unknown_buf(uint8_t* rr, size_t rr_len, char* str,
+       size_t str_len);
+
+/**
+ * This creates the comment to print after the RR. ; keytag=... , and other
+ * basic comments for RRs.
+ * There are more format and comment options available for printout
+ * with the function: TBD(TODO)
+ * @param rr: wireformat RR data
+ * @param rr_len: length of the rr wire data.
+ * @param dname_len: length of the dname in front of the RR.
+ * @param str: the string buffer to write to.
+ *     If you pass NULL as the str, the return value of the function is
+ *     the str_len you need for the entire comment.  It does not include
+ *     the 0 byte at the end.
+ * @param str_len: the size of the string buffer.  If more is needed, it'll
+ *     silently truncate the output to fit in the buffer.
+ * @return the number of characters for this element, excluding zerobyte.
+ *     Is larger than str_len if output was truncated.
+ */
+int ldns_wire2str_rr_comment_buf(uint8_t* rr, size_t rr_len, size_t dname_len,
+       char* str, size_t str_len);
+
+/**
+ * Convert RDATA to string presentation format, on one line.  User buffer.
+ * @param rdata: wireformat rdata part of an RR.
+ * @param rdata_len: length of the rr wire data.
+ * @param str: the string buffer to write to.
+ *     If you pass NULL as the str, the return value of the function is
+ *     the str_len you need for the entire packet.  It does not include
+ *     the 0 byte at the end.
+ * @param str_len: the size of the string buffer.  If more is needed, it'll
+ *     silently truncate the output to fit in the buffer.
+ * @param rrtype: rr type of the data
+ * @return the number of characters for this element, excluding zerobyte.
+ *     Is larger than str_len if output was truncated.
+ */
+int ldns_wire2str_rdata_buf(uint8_t* rdata, size_t rdata_len, char* str,
+       size_t str_len, uint16_t rrtype);
+
+/**
+ * Convert wire RR type to a string, 'MX', 'TYPE12'.  With user buffer.
+ * @param rrtype: the RR type in host order.
+ * @param str: the string to write to.
+ * @param len: length of str.
+ * @return the number of characters for this element, excluding zerobyte.
+ *     Is larger than str_len if output was truncated.
+ */
+int ldns_wire2str_type_buf(uint16_t rrtype, char* str, size_t len);
+
+/**
+ * Convert wire RR class to a string, 'IN', 'CLASS12'.  With user buffer.
+ * @param rrclass: the RR class in host order.
+ * @param str: the string to write to.
+ * @param len: length of str.
+ * @return the number of characters for this element, excluding zerobyte.
+ *     Is larger than str_len if output was truncated.
+ */
+int ldns_wire2str_class_buf(uint16_t rrclass, char* str, size_t len);
+
+/**
+ * Convert wire RR rcode to a string, 'NOERROR', 'NXDOMAIN'.  With user buffer.
+ * @param rcode: rcode as integer in host order
+ * @param str: the string to write to.
+ * @param len: length of str.
+ * @return the number of characters for this element, excluding zerobyte.
+ *     Is larger than str_len if output was truncated.
+ */
+int ldns_wire2str_rcode_buf(int rcode, char* str, size_t len);
+
+/**
+ * Convert wire dname to a string, "example.com.".  With user buffer.
+ * @param dname: the dname in uncompressed wireformat.
+ * @param dname_len: length of the dname.
+ * @param str: the string to write to.
+ * @param len: length of string.
+ * @return the number of characters for this element, excluding zerobyte.
+ *     Is larger than str_len if output was truncated.
+ */
+int ldns_wire2str_dname_buf(uint8_t* dname, size_t dname_len, char* str,
+       size_t len);
+
+/**
+ * Scan wireformat rdf field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param rdftype: the type of the rdata field.
+ * @param pkt: packet for decompression, if NULL no decompression.
+ * @param pktlen: length of packet buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_rdf_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len, enum ldns_enum_rdf_type rdftype, uint8_t* pkt,
+       size_t pktlen);
+
+/**
+ * Scan wireformat int8 field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_int8_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat int16 field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_int16_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat int32 field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_int32_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat period field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_period_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat tsigtime field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_tsigtime_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat ip4 A field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_a_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat ip6 AAAA field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_aaaa_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat str field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_str_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat apl field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_apl_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat b32_ext field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_b32_ext_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat b64 field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_b64_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat hex field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_hex_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat nsec bitmap field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_nsec_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat nsec3_salt field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_nsec3_salt_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat cert_alg field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_cert_alg_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat alg field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_alg_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat type unknown field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_unknown_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat time field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_time_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat LOC field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_loc_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat WKS field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_wks_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat NSAP field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_nsap_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat ATMA field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_atma_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat IPSECKEY field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param pkt: packet for decompression, if NULL no decompression.
+ * @param pktlen: length of packet buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_ipseckey_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len, uint8_t* pkt, size_t pktlen);
+
+/**
+ * Scan wireformat int16_data field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_int16_data_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat nsec3_next_owner field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_nsec3_next_owner_scan(uint8_t** data, size_t* data_len,
+       char** str, size_t* str_len);
+
+/**
+ * Scan wireformat ILNP64 field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_ilnp64_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat EUI48 field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_eui48_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat EUI64 field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_eui64_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat TAG field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_tag_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Scan wireformat long_str field to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @return number of characters (except null) needed to print.
+ *     Can return -1 on failure.
+ */
+int ldns_wire2str_long_str_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len);
+
+/**
+ * Print EDNS LLQ option data to string.  User buffers, moves string pointers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param option_data: buffer with EDNS option code data.
+ * @param option_len: length of the data for this option.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_edns_llq_print(char** str, size_t* str_len,
+       uint8_t* option_data, size_t option_len);
+
+/**
+ * Print EDNS UL option data to string.  User buffers, moves string pointers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param option_data: buffer with EDNS option code data.
+ * @param option_len: length of the data for this option.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_edns_ul_print(char** str, size_t* str_len,
+       uint8_t* option_data, size_t option_len);
+
+/**
+ * Print EDNS NSID option data to string.  User buffers, moves string pointers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param option_data: buffer with EDNS option code data.
+ * @param option_len: length of the data for this option.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_edns_nsid_print(char** str, size_t* str_len,
+       uint8_t* option_data, size_t option_len);
+
+/**
+ * Print EDNS DAU option data to string.  User buffers, moves string pointers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param option_data: buffer with EDNS option code data.
+ * @param option_len: length of the data for this option.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_edns_dau_print(char** str, size_t* str_len,
+       uint8_t* option_data, size_t option_len);
+
+/**
+ * Print EDNS DHU option data to string.  User buffers, moves string pointers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param option_data: buffer with EDNS option code data.
+ * @param option_len: length of the data for this option.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_edns_dhu_print(char** str, size_t* str_len,
+       uint8_t* option_data, size_t option_len);
+
+/**
+ * Print EDNS N3U option data to string.  User buffers, moves string pointers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param option_data: buffer with EDNS option code data.
+ * @param option_len: length of the data for this option.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_edns_n3u_print(char** str, size_t* str_len,
+       uint8_t* option_data, size_t option_len);
+
+/**
+ * Print EDNS SUBNET option data to string. User buffers, moves string pointers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param option_data: buffer with EDNS option code data.
+ * @param option_len: length of the data for this option.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_edns_subnet_print(char** str, size_t* str_len,
+       uint8_t* option_data, size_t option_len);
+
+/**
+ * Print an EDNS option as OPT: VALUE.  User buffers, moves string pointers.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param option_code: host format EDNS option code.
+ * @param option_data: buffer with EDNS option code data.
+ * @param option_len: length of the data for this option.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_edns_option_print(char** str, size_t* str_len,
+       uint16_t option_code, uint8_t* option_data, size_t option_len);
+
+/**
+ * Scan wireformat EDNS OPT to string, with user buffers.
+ * It shifts the arguments to move along (see ldns_wire2str_pkt_scan).
+ * @param data: wireformat data.
+ * @param data_len: length of data buffer.
+ * @param str: string buffer.
+ * @param str_len: length of string buffer.
+ * @param pkt: packet with header and other info (may be NULL)
+ * @param pktlen: length of packet buffer.
+ * @return number of characters (except null) needed to print.
+ */
+int ldns_wire2str_edns_scan(uint8_t** data, size_t* data_len, char** str,
+       size_t* str_len, uint8_t* pkt, size_t pktlen);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LDNS_WIRE2STR_H */
index 18f34e45414361e366e3d098db9a20bbaad26fde..44862648b0efb48f085e0a79327be845cbfff1c3 100644 (file)
@@ -49,6 +49,7 @@
 #include "services/cache/infra.h"
 #include "util/data/msgreply.h"
 #include "util/storage/slabhash.h"
+#include "ldns/sbuffer.h"
 
 int 
 context_finalize(struct ub_ctx* ctx)
index 4447b02eb23222f25e0398287c9e22e7a356cee2..a08353982698f15415c07865fb00a0db5920d6f8 100644 (file)
@@ -48,6 +48,7 @@
 #include "util/data/packed_rrset.h"
 struct libworker;
 struct tube;
+struct ldns_buffer;
 struct event_base;
 
 /**
@@ -281,7 +282,7 @@ uint8_t* context_serialize_new_query(struct ctx_query* q, uint32_t* len);
  * @return: an alloc, or NULL on mem error.
  */
 uint8_t* context_serialize_answer(struct ctx_query* q, int err, 
-       ldns_buffer* pkt, uint32_t* len);
+       struct ldns_buffer* pkt, uint32_t* len);
 
 /**
  * Serialize a query cancellation. Serializes query async id
index 870e37699b1793f2b5899fe01f46a1da357ef448..3ec9196fe58314d23547355987cde96418b61060 100644 (file)
@@ -61,6 +61,7 @@
 #include "services/localzone.h"
 #include "services/cache/infra.h"
 #include "services/cache/rrset.h"
+#include "ldns/sbuffer.h"
 #ifdef HAVE_PTHREAD
 #include <signal.h>
 #endif
@@ -1173,18 +1174,10 @@ int ub_ctx_zone_remove(struct ub_ctx* ctx, const char *zone_name)
 /* Add new RR data */
 int ub_ctx_data_add(struct ub_ctx* ctx, const char *data)
 {
-       ldns_buffer* buf;
        int res = ub_ctx_finalize(ctx);
        if (res) return res;
 
-       lock_basic_lock(&ctx->cfglock);
-       buf = ldns_buffer_new(ctx->env->cfg->msg_buffer_size);
-       lock_basic_unlock(&ctx->cfglock);
-       if(!buf) return UB_NOMEM;
-
-       res = local_zones_add_RR(ctx->local_zones, data, buf);
-
-       ldns_buffer_free(buf);
+       res = local_zones_add_RR(ctx->local_zones, data);
        return (!res) ? UB_NOMEM : UB_NOERROR;
 }
 
index 313b41680beafb220af422e0bbccd1f05197ecc2..0863887e9e1d16b7b66e752c1eea1aba26a73671 100644 (file)
@@ -42,8 +42,6 @@
  * returns from the procedure when done.
  */
 #include "config.h"
-#include <ldns/dname.h>
-#include <ldns/wire2host.h>
 #ifdef HAVE_SSL
 #include <openssl/ssl.h>
 #endif
@@ -70,6 +68,8 @@
 #include "util/tube.h"
 #include "iterator/iter_fwd.h"
 #include "iterator/iter_hints.h"
+#include "ldns/sbuffer.h"
+#include "ldns/str2wire.h"
 
 /** handle new query command for bg worker */
 static void handle_newq(struct libworker* w, uint8_t* buf, uint32_t len);
@@ -566,22 +566,12 @@ static int
 setup_qinfo_edns(struct libworker* w, struct ctx_query* q, 
        struct query_info* qinfo, struct edns_data* edns)
 {
-       ldns_rdf* rdf;
        qinfo->qtype = (uint16_t)q->res->qtype;
        qinfo->qclass = (uint16_t)q->res->qclass;
-       rdf = ldns_dname_new_frm_str(q->res->qname);
-       if(!rdf) {
+       qinfo->qname = ldns_str2wire_dname(q->res->qname, &qinfo->qname_len);
+       if(!qinfo->qname) {
                return 0;
        }
-#ifdef UNBOUND_ALLOC_LITE
-       qinfo->qname = memdup(ldns_rdf_data(rdf), ldns_rdf_size(rdf));
-       qinfo->qname_len = ldns_rdf_size(rdf);
-       ldns_rdf_deep_free(rdf);
-       rdf = 0;
-#else
-       qinfo->qname = ldns_rdf_data(rdf);
-       qinfo->qname_len = ldns_rdf_size(rdf);
-#endif
        edns->edns_present = 1;
        edns->ext_rcode = 0;
        edns->edns_version = 0;
@@ -590,7 +580,6 @@ setup_qinfo_edns(struct libworker* w, struct ctx_query* q,
                edns->udp_size = (uint16_t)ldns_buffer_capacity(
                        w->back->udp_buff);
        else    edns->udp_size = 65535;
-       ldns_rdf_free(rdf);
        return 1;
 }
 
index 66644a90f67e63024133293860612da5b0e527d4..509ffd026945a90241bc1fa6ab730cf45fd43eef 100644 (file)
@@ -57,6 +57,7 @@ struct comm_point;
 struct comm_reply;
 struct regional;
 struct tube;
+struct ldns_buffer;
 struct event_base;
 
 /** 
@@ -174,15 +175,15 @@ void libworker_handle_result_write(struct tube* tube, uint8_t* msg, size_t len,
        int err, void* arg);
 
 /** mesh callback with fg results */
-void libworker_fg_done_cb(void* arg, int rcode, ldns_buffer* buf, 
+void libworker_fg_done_cb(void* arg, int rcode, struct ldns_buffer* buf, 
        enum sec_status s, char* why_bogus);
 
 /** mesh callback with bg results */
-void libworker_bg_done_cb(void* arg, int rcode, ldns_buffer* buf, 
+void libworker_bg_done_cb(void* arg, int rcode, struct ldns_buffer* buf, 
        enum sec_status s, char* why_bogus);
 
 /** mesh callback with event results */
-void libworker_event_done_cb(void* arg, int rcode, ldns_buffer* buf, 
+void libworker_event_done_cb(void* arg, int rcode, struct ldns_buffer* buf, 
        enum sec_status s, char* why_bogus);
 
 /** 
@@ -194,7 +195,7 @@ void libworker_event_done_cb(void* arg, int rcode, ldns_buffer* buf,
  *   On error, the res may contain a different status 
  *   (out of memory is not secure, not bogus).
  */
-void libworker_enter_result(struct ub_result* res, ldns_buffer* buf,
+void libworker_enter_result(struct ub_result* res, struct ldns_buffer* buf,
        struct regional* temp, enum sec_status msg_security);
 
 #endif /* LIBUNBOUND_WORKER_H */
index 7dadb5c396561a9ca5b0d18d29e8f25043e479f2..9e9222c65359c06dda1a303b3ae622e14389ce83 100644 (file)
@@ -50,6 +50,7 @@
 #include "util/net_help.h"
 #include "util/regional.h"
 #include "util/config_file.h"
+#include "ldns/sbuffer.h"
 
 /** store rrsets in the rrset cache. 
  * @param env: module environment with caches.
index 42d6acad1a22137f8fd9dd785d419a5ad98b5854..da8c67b0f8cae00f9f366bb2cab3ecf8bd9dd774 100644 (file)
@@ -39,7 +39,7 @@
  * This file contains the infrastructure cache.
  */
 #include "config.h"
-#include <ldns/rr.h>
+#include "ldns/rrdef.h"
 #include "services/cache/infra.h"
 #include "util/storage/slabhash.h"
 #include "util/storage/lookup3.h"
index 642236231121d9bdba6371e9f10b5e08b18cc989..57284667f6693fa3f52202f0b271684bcd5f1720 100644 (file)
@@ -40,6 +40,7 @@
  */
 #include "config.h"
 #include "services/cache/rrset.h"
+#include "ldns/rrdef.h"
 #include "util/storage/slabhash.h"
 #include "util/config_file.h"
 #include "util/data/packed_rrset.h"
index 6eeedb75e5d900c45b5159c504cee3c6a3b4a331..b27c9fff99d8b90fe68efa11269947fdca9806fb 100644 (file)
@@ -49,6 +49,7 @@
 #include "util/log.h"
 #include "util/config_file.h"
 #include "util/net_help.h"
+#include "ldns/sbuffer.h"
 
 #ifdef HAVE_NETDB_H
 #include <netdb.h>
@@ -75,7 +76,7 @@ verbose_print_addr(struct addrinfo *addr)
 #endif /* INET6 */
                if(inet_ntop(addr->ai_family, sinaddr, buf,
                        (socklen_t)sizeof(buf)) == 0) {
-                       strncpy(buf, "(null)", sizeof(buf));
+                       strlcpy(buf, "(null)", sizeof(buf));
                }
                buf[sizeof(buf)-1] = 0;
                verbose(VERB_ALGO, "creating %s%s socket %s %d", 
@@ -581,9 +582,9 @@ make_sock_port(int stype, const char* ifname, const char* port,
                        *noip6 = 0;
                        return -1;
                }
-               strncpy(newif, ifname, sizeof(newif));
+               strlcpy(newif, ifname, sizeof(newif));
                newif[s-ifname] = 0;
-               strncpy(p, s+1, sizeof(p));
+               strlcpy(p, s+1, sizeof(p));
                p[strlen(s+1)]=0;
                return make_sock(stype, newif, p, hints, v6only, noip6,
                        rcv, snd);
index 451a64abcd890ce3de1c3e4122d70ed5159cfc68..106ad84238651546215527259c81152e8045f1ea 100644 (file)
@@ -46,6 +46,7 @@
 struct listen_list;
 struct config_file;
 struct addrinfo;
+struct ldns_buffer;
 
 /**
  * Listening for queries structure.
@@ -57,7 +58,7 @@ struct listen_dnsport {
 
        /** buffer shared by UDP connections, since there is only one
            datagram at any time. */
-       ldns_buffer* udp_buff;
+       struct ldns_buffer* udp_buff;
 
        /** list of comm points used to get incoming events */
        struct listen_list* cps;
index 4a2187ec4f25e0b7fe0042da447798fef6c4d031..ef138b9e02f450e579699021a154e27fce4ae091 100644 (file)
@@ -39,9 +39,9 @@
  * This file contains functions to enable local zone authority service.
  */
 #include "config.h"
-#include <ldns/dname.h>
-#include <ldns/host2wire.h>
 #include "services/localzone.h"
+#include "ldns/str2wire.h"
+#include "ldns/sbuffer.h"
 #include "util/regional.h"
 #include "util/config_file.h"
 #include "util/data/dname.h"
@@ -125,19 +125,10 @@ local_data_cmp(const void* d1, const void* d2)
 int
 parse_dname(const char* str, uint8_t** res, size_t* len, int* labs)
 {
-       ldns_rdf* rdf;
-       *res = NULL;
-       *len = 0;
+       *res = ldns_str2wire_dname(str, len);
        *labs = 0;
-       rdf = ldns_dname_new_frm_str(str);
-       if(!rdf) {
-               log_err("cannot parse name %s", str);
-               return 0;
-       }
-       *res = memdup(ldns_rdf_data(rdf), ldns_rdf_size(rdf));
-       ldns_rdf_deep_free(rdf);
        if(!*res) {
-               log_err("out of memory");
+               log_err("cannot parse name %s", str);
                return 0;
        }
        *labs = dname_count_size_labels(*res, len);
@@ -225,39 +216,28 @@ lz_enter_zone(struct local_zones* zones, const char* name, const char* type,
 /** return name and class and rdata of rr; parses string */
 static int
 get_rr_content(const char* str, uint8_t** nm, uint16_t* type,
-       uint16_t* dclass, time_t* ttl, ldns_buffer* rdata)
+       uint16_t* dclass, time_t* ttl, uint8_t* rr, size_t len,
+       uint8_t** rdata, size_t* rdata_len)
 {
-       ldns_rr* rr = NULL;
-       ldns_status status = ldns_rr_new_frm_str(&rr, str, 3600, NULL, NULL);
-       if(status != LDNS_STATUS_OK) {
-               log_err("error parsing local-data '%s': %s",
-                       str, ldns_get_errorstr_by_id(status));
-               ldns_rr_free(rr);
+       size_t dname_len = 0;
+       int e = ldns_str2wire_rr_buf(str, rr, &len, &dname_len, 3600,
+               NULL, 0, NULL, 0);
+       if(e) {
+               log_err("error parsing local-data at %d: '%s': %s",
+                       LDNS_WIREPARSE_OFFSET(e), str,
+                       ldns_get_errorstr_parse(e));
                return 0;
        }
-       *nm = memdup(ldns_rdf_data(ldns_rr_owner(rr)), 
-               ldns_rdf_size(ldns_rr_owner(rr)));
+       *nm = memdup(rr, dname_len);
        if(!*nm) {
                log_err("out of memory");
-               ldns_rr_free(rr);
                return 0;
        }
-       *dclass = ldns_rr_get_class(rr);
-       *type = ldns_rr_get_type(rr);
-       *ttl = (time_t)ldns_rr_ttl(rr);
-       ldns_buffer_clear(rdata);
-       ldns_buffer_skip(rdata, 2);
-       status = ldns_rr_rdata2buffer_wire(rdata, rr);
-       ldns_rr_free(rr);
-        if(status != LDNS_STATUS_OK) {
-                log_err("error converting RR '%s' to wireformat: %s",
-                        str, ldns_get_errorstr_by_id(status));
-               free(*nm);
-               *nm = NULL;
-                return 0;
-        }
-        ldns_buffer_flip(rdata);
-        ldns_buffer_write_u16_at(rdata, 0, ldns_buffer_limit(rdata) - 2);
+       *dclass = ldns_wirerr_get_class(rr, len, dname_len);
+       *type = ldns_wirerr_get_type(rr, len, dname_len);
+       *ttl = (time_t)ldns_wirerr_get_ttl(rr, len, dname_len);
+       *rdata = ldns_wirerr_get_rdatawl(rr, len, dname_len);
+       *rdata_len = ldns_wirerr_get_rdatalen(rr, len, dname_len)+2;
        return 1;
 }
 
@@ -265,18 +245,18 @@ get_rr_content(const char* str, uint8_t** nm, uint16_t* type,
 static int
 get_rr_nameclass(const char* str, uint8_t** nm, uint16_t* dclass)
 {
-       ldns_rr* rr = NULL;
-       ldns_status status = ldns_rr_new_frm_str(&rr, str, 3600, NULL, NULL);
-       if(status != LDNS_STATUS_OK) {
-               log_err("error parsing local-data '%s': %s",
-                       str, ldns_get_errorstr_by_id(status));
-               ldns_rr_free(rr);
+       uint8_t rr[LDNS_RR_BUF_SIZE];
+       size_t len = sizeof(rr), dname_len = 0;
+       int s = ldns_str2wire_rr_buf(str, rr, &len, &dname_len, 3600,
+               NULL, 0, NULL, 0);
+       if(s != 0) {
+               log_err("error parsing local-data at %d '%s': %s",
+                       LDNS_WIREPARSE_OFFSET(s), str,
+                       ldns_get_errorstr_parse(s));
                return 0;
        }
-       *nm = memdup(ldns_rdf_data(ldns_rr_owner(rr)), 
-               ldns_rdf_size(ldns_rr_owner(rr)));
-       *dclass = ldns_rr_get_class(rr);
-       ldns_rr_free(rr);
+       *nm = memdup(rr, dname_len);
+       *dclass = ldns_wirerr_get_class(rr, len, dname_len);
        if(!*nm) {
                log_err("out of memory");
                return 0;
@@ -304,13 +284,12 @@ local_data_find_type(struct local_data* data, uint16_t type)
 
 /** check for RR duplicates */
 static int
-rr_is_duplicate(struct packed_rrset_data* pd, ldns_buffer* buf)
+rr_is_duplicate(struct packed_rrset_data* pd, uint8_t* rdata, size_t rdata_len)
 {
        size_t i;
        for(i=0; i<pd->count; i++) {
-               if(ldns_buffer_limit(buf) == pd->rr_len[i] &&
-                       memcmp(ldns_buffer_begin(buf), pd->rr_data[i],
-                               ldns_buffer_limit(buf)) == 0) 
+               if(pd->rr_len[i] == rdata_len &&
+                       memcmp(pd->rr_data[i], rdata, rdata_len) == 0)
                        return 1;
        }
        return 0;
@@ -356,7 +335,7 @@ new_local_rrset(struct regional* region, struct local_data* node,
 /** insert RR into RRset data structure; Wastes a couple of bytes */
 static int
 insert_rr(struct regional* region, struct packed_rrset_data* pd,
-       ldns_buffer* buf, time_t ttl)
+       uint8_t* rdata, size_t rdata_len, time_t ttl)
 {
        size_t* oldlen = pd->rr_len;
        time_t* oldttl = pd->rr_ttl;
@@ -379,10 +358,9 @@ insert_rr(struct regional* region, struct packed_rrset_data* pd,
                memcpy(pd->rr_data+1, olddata, 
                        sizeof(*pd->rr_data)*(pd->count-1));
        }
-       pd->rr_len[0] = ldns_buffer_limit(buf);
+       pd->rr_len[0] = rdata_len;
        pd->rr_ttl[0] = ttl;
-       pd->rr_data[0] = regional_alloc_init(region,
-               ldns_buffer_begin(buf), ldns_buffer_limit(buf));
+       pd->rr_data[0] = regional_alloc_init(region, rdata, rdata_len);
        if(!pd->rr_data[0]) {
                log_err("out of memory");
                return 0;
@@ -440,8 +418,7 @@ lz_find_create_node(struct local_zone* z, uint8_t* nm, size_t nmlen,
 
 /** enter data RR into auth zone */
 static int
-lz_enter_rr_into_zone(struct local_zone* z, ldns_buffer* buf,
-       const char* rrstr)
+lz_enter_rr_into_zone(struct local_zone* z, const char* rrstr)
 {
        uint8_t* nm;
        size_t nmlen;
@@ -451,7 +428,11 @@ lz_enter_rr_into_zone(struct local_zone* z, ldns_buffer* buf,
        struct packed_rrset_data* pd;
        uint16_t rrtype = 0, rrclass = 0;
        time_t ttl = 0;
-       if(!get_rr_content(rrstr, &nm, &rrtype, &rrclass, &ttl, buf)) {
+       uint8_t rr[LDNS_RR_BUF_SIZE];
+       uint8_t* rdata;
+       size_t rdata_len;
+       if(!get_rr_content(rrstr, &nm, &rrtype, &rrclass, &ttl, rr, sizeof(rr),
+               &rdata, &rdata_len)) {
                log_err("bad local-data: %s", rrstr);
                return 0;
        }
@@ -487,16 +468,16 @@ lz_enter_rr_into_zone(struct local_zone* z, ldns_buffer* buf,
        log_assert(rrset && pd);
 
        /* check for duplicate RR */
-       if(rr_is_duplicate(pd, buf)) {
+       if(rr_is_duplicate(pd, rdata, rdata_len)) {
                verbose(VERB_ALGO, "ignoring duplicate RR: %s", rrstr);
                return 1;
        } 
-       return insert_rr(z->region, pd, buf, ttl);
+       return insert_rr(z->region, pd, rdata, rdata_len, ttl);
 }
 
 /** enter a data RR into auth data; a zone for it must exist */
 static int
-lz_enter_rr_str(struct local_zones* zones, const char* rr, ldns_buffer* buf)
+lz_enter_rr_str(struct local_zones* zones, const char* rr)
 {
        uint8_t* rr_name;
        uint16_t rr_class;
@@ -518,7 +499,7 @@ lz_enter_rr_str(struct local_zones* zones, const char* rr, ldns_buffer* buf)
        lock_rw_wrlock(&z->lock);
        lock_quick_unlock(&zones->lock);
        free(rr_name);
-       r = lz_enter_rr_into_zone(z, buf, rr);
+       r = lz_enter_rr_into_zone(z, rr);
        lock_rw_unlock(&z->lock);
        return r;
 }
@@ -582,7 +563,7 @@ lz_nodefault(struct config_file* cfg, const char* name)
 /** enter AS112 default zone */
 static int
 add_as112_default(struct local_zones* zones, struct config_file* cfg,
-        ldns_buffer* buf, const char* name)
+        const char* name)
 {
        struct local_zone* z;
        char str[1024]; /* known long enough */
@@ -592,12 +573,12 @@ add_as112_default(struct local_zones* zones, struct config_file* cfg,
                return 0;
        snprintf(str, sizeof(str), "%s 10800 IN SOA localhost. "
                "nobody.invalid. 1 3600 1200 604800 10800", name);
-       if(!lz_enter_rr_into_zone(z, buf, str)) {
+       if(!lz_enter_rr_into_zone(z, str)) {
                lock_rw_unlock(&z->lock);
                return 0;
        }
        snprintf(str, sizeof(str), "%s 10800 IN NS localhost. ", name);
-       if(!lz_enter_rr_into_zone(z, buf, str)) {
+       if(!lz_enter_rr_into_zone(z, str)) {
                lock_rw_unlock(&z->lock);
                return 0;
        }
@@ -607,8 +588,7 @@ add_as112_default(struct local_zones* zones, struct config_file* cfg,
 
 /** enter default zones */
 static int
-lz_enter_defaults(struct local_zones* zones, struct config_file* cfg,
-       ldns_buffer* buf)
+lz_enter_defaults(struct local_zones* zones, struct config_file* cfg)
 {
        struct local_zone* z;
 
@@ -619,14 +599,14 @@ lz_enter_defaults(struct local_zones* zones, struct config_file* cfg,
                !lz_nodefault(cfg, "localhost.")) {
                if(!(z=lz_enter_zone(zones, "localhost.", "static", 
                        LDNS_RR_CLASS_IN)) ||
-                  !lz_enter_rr_into_zone(z, buf,
+                  !lz_enter_rr_into_zone(z,
                        "localhost. 10800 IN NS localhost.") ||
-                  !lz_enter_rr_into_zone(z, buf,
+                  !lz_enter_rr_into_zone(z,
                        "localhost. 10800 IN SOA localhost. nobody.invalid. "
                        "1 3600 1200 604800 10800") ||
-                  !lz_enter_rr_into_zone(z, buf,
+                  !lz_enter_rr_into_zone(z,
                        "localhost. 10800 IN A 127.0.0.1") ||
-                  !lz_enter_rr_into_zone(z, buf,
+                  !lz_enter_rr_into_zone(z,
                        "localhost. 10800 IN AAAA ::1")) {
                        log_err("out of memory adding default zone");
                        if(z) { lock_rw_unlock(&z->lock); }
@@ -639,12 +619,12 @@ lz_enter_defaults(struct local_zones* zones, struct config_file* cfg,
                !lz_nodefault(cfg, "127.in-addr.arpa.")) {
                if(!(z=lz_enter_zone(zones, "127.in-addr.arpa.", "static", 
                        LDNS_RR_CLASS_IN)) ||
-                  !lz_enter_rr_into_zone(z, buf,
+                  !lz_enter_rr_into_zone(z,
                        "127.in-addr.arpa. 10800 IN NS localhost.") ||
-                  !lz_enter_rr_into_zone(z, buf,
+                  !lz_enter_rr_into_zone(z,
                        "127.in-addr.arpa. 10800 IN SOA localhost. "
                        "nobody.invalid. 1 3600 1200 604800 10800") ||
-                  !lz_enter_rr_into_zone(z, buf,
+                  !lz_enter_rr_into_zone(z,
                        "1.0.0.127.in-addr.arpa. 10800 IN PTR localhost.")) {
                        log_err("out of memory adding default zone");
                        if(z) { lock_rw_unlock(&z->lock); }
@@ -657,12 +637,12 @@ lz_enter_defaults(struct local_zones* zones, struct config_file* cfg,
                !lz_nodefault(cfg, "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.")) {
                if(!(z=lz_enter_zone(zones, "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.", "static", 
                        LDNS_RR_CLASS_IN)) ||
-                  !lz_enter_rr_into_zone(z, buf,
+                  !lz_enter_rr_into_zone(z,
                        "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa. 10800 IN NS localhost.") ||
-                  !lz_enter_rr_into_zone(z, buf,
+                  !lz_enter_rr_into_zone(z,
                        "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa. 10800 IN SOA localhost. "
                        "nobody.invalid. 1 3600 1200 604800 10800") ||
-                  !lz_enter_rr_into_zone(z, buf,
+                  !lz_enter_rr_into_zone(z,
                        "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa. 10800 IN PTR localhost.")) {
                        log_err("out of memory adding default zone");
                        if(z) { lock_rw_unlock(&z->lock); }
@@ -670,37 +650,37 @@ lz_enter_defaults(struct local_zones* zones, struct config_file* cfg,
                }
                lock_rw_unlock(&z->lock);
        }
-       if (    !add_as112_default(zones, cfg, buf, "10.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "16.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "17.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "18.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "19.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "20.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "21.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "22.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "23.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "24.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "25.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "26.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "27.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "28.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "29.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "30.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "31.172.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "168.192.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "0.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "254.169.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "2.0.192.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "100.51.198.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "113.0.203.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "255.255.255.255.in-addr.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "d.f.ip6.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "8.e.f.ip6.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "9.e.f.ip6.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "a.e.f.ip6.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "b.e.f.ip6.arpa.") ||
-               !add_as112_default(zones, cfg, buf, "8.b.d.0.1.0.0.2.ip6.arpa.")) {
+       if (    !add_as112_default(zones, cfg, "10.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "16.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "17.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "18.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "19.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "20.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "21.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "22.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "23.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "24.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "25.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "26.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "27.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "28.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "29.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "30.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "31.172.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "168.192.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "0.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "254.169.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "2.0.192.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "100.51.198.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "113.0.203.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "255.255.255.255.in-addr.arpa.") ||
+               !add_as112_default(zones, cfg, "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.") ||
+               !add_as112_default(zones, cfg, "d.f.ip6.arpa.") ||
+               !add_as112_default(zones, cfg, "8.e.f.ip6.arpa.") ||
+               !add_as112_default(zones, cfg, "9.e.f.ip6.arpa.") ||
+               !add_as112_default(zones, cfg, "a.e.f.ip6.arpa.") ||
+               !add_as112_default(zones, cfg, "b.e.f.ip6.arpa.") ||
+               !add_as112_default(zones, cfg, "8.b.d.0.1.0.0.2.ip6.arpa.")) {
                log_err("out of memory adding default zone");
                return 0;
        }
@@ -825,12 +805,11 @@ lz_setup_implicit(struct local_zones* zones, struct config_file* cfg)
 
 /** enter auth data */
 static int
-lz_enter_data(struct local_zones* zones, struct config_file* cfg,
-       ldns_buffer* buf)
+lz_enter_data(struct local_zones* zones, struct config_file* cfg)
 {
        struct config_strlist* p;
        for(p = cfg->local_data; p; p = p->next) {
-               if(!lz_enter_rr_str(zones, p->str, buf))
+               if(!lz_enter_rr_str(zones, p->str))
                        return 0;
        }
        return 1;
@@ -851,35 +830,27 @@ lz_freeup_cfg(struct config_file* cfg)
 int 
 local_zones_apply_cfg(struct local_zones* zones, struct config_file* cfg)
 {
-       ldns_buffer* buf = ldns_buffer_new(65535);
-       if(!buf) fatal_exit("cannot create temporary buffer");
-
        /* create zones from zone statements. */
        if(!lz_enter_zones(zones, cfg)) {
-               ldns_buffer_free(buf);
                return 0;
        }
        /* apply default zones+content (unless disabled, or overridden) */
-       if(!lz_enter_defaults(zones, cfg, buf)) {
-               ldns_buffer_free(buf);
+       if(!lz_enter_defaults(zones, cfg)) {
                return 0;
        }
        /* create implicit transparent zone from data. */
        if(!lz_setup_implicit(zones, cfg)) {
-               ldns_buffer_free(buf);
                return 0;
        }
 
        /* setup parent ptrs for lookup during data entry */
        init_parents(zones);
        /* insert local data */
-       if(!lz_enter_data(zones, cfg, buf)) {
-               ldns_buffer_free(buf);
+       if(!lz_enter_data(zones, cfg)) {
                return 0;
        }
        /* freeup memory from cfg struct. */
        lz_freeup_cfg(cfg);
-       ldns_buffer_free(buf);
        return 1;
 }
 
@@ -1255,7 +1226,7 @@ void local_zones_del_zone(struct local_zones* zones, struct local_zone* z)
 }
 
 int
-local_zones_add_RR(struct local_zones* zones, const char* rr, ldns_buffer* buf)
+local_zones_add_RR(struct local_zones* zones, const char* rr)
 {
        uint8_t* rr_name;
        uint16_t rr_class;
@@ -1281,7 +1252,7 @@ local_zones_add_RR(struct local_zones* zones, const char* rr, ldns_buffer* buf)
        }
        lock_rw_wrlock(&z->lock);
        lock_quick_unlock(&zones->lock);
-       r = lz_enter_rr_into_zone(z, buf, rr);
+       r = lz_enter_rr_into_zone(z, rr);
        lock_rw_unlock(&z->lock);
        return r;
 }
index 794988e66bb9e1fe26db462545d57c806b03771c..ec707a338d48f621e9d030c59aa6c69b51133843 100644 (file)
@@ -48,6 +48,7 @@ struct regional;
 struct config_file;
 struct edns_data;
 struct query_info;
+struct ldns_buffer;
 
 /**
  * Local zone type
@@ -224,7 +225,7 @@ void local_zones_print(struct local_zones* zones);
  * value is true, but the buffer is cleared (empty).
  */
 int local_zones_answer(struct local_zones* zones, struct query_info* qinfo,
-       struct edns_data* edns, ldns_buffer* buf, struct regional* temp);
+       struct edns_data* edns, struct ldns_buffer* buf, struct regional* temp);
 
 /**
  * Parse the string into localzone type.
@@ -286,11 +287,9 @@ void local_zones_del_zone(struct local_zones* zones, struct local_zone* zone);
  * name of the RR is created.
  * @param zones: the zones tree. Not locked by caller.
  * @param rr: string with on RR.
- * @param buf: buffer for scratch.
  * @return false on failure.
  */
-int local_zones_add_RR(struct local_zones* zones, const char* rr, 
-       ldns_buffer* buf);
+int local_zones_add_RR(struct local_zones* zones, const char* rr);
 
 /**
  * Remove data from domain name in the tree.
index a8cb115ab935f9d74f5b46aebdaa3f90f9b2c049..e225e6162eb7e978159852919fea377820729359 100644 (file)
@@ -43,7 +43,6 @@
  * send back to clients.
  */
 #include "config.h"
-#include <ldns/wire2host.h>
 #include "services/mesh.h"
 #include "services/outbound_list.h"
 #include "services/cache/dns.h"
@@ -56,6 +55,7 @@
 #include "util/fptr_wlist.h"
 #include "util/alloc.h"
 #include "util/config_file.h"
+#include "ldns/sbuffer.h"
 
 /** subtract timers and the values do not overflow or become negative */
 static void
index 54a3cafecc9e5cb0dd6d27ec43513ad871d5a35a..dc9e6a1e2e890e2528c7d5ea7949d6ae8d0d0d2a 100644 (file)
@@ -51,6 +51,7 @@
 #include "util/data/msgparse.h"
 #include "util/module.h"
 #include "services/modstack.h"
+struct ldns_buffer;
 struct mesh_state;
 struct mesh_reply;
 struct mesh_cb;
@@ -125,7 +126,7 @@ struct mesh_area {
 
        /** backup of query if other operations recurse and need the
         * network buffers */
-       ldns_buffer* qbuf_bak;
+       struct ldns_buffer* qbuf_bak;
 
        /** double linked list of the run-to-completion query states.
         * These are query states with a reply */
@@ -219,7 +220,7 @@ struct mesh_reply {
  * Mesh result callback func.
  * called as func(cb_arg, rcode, buffer_with_reply, security, why_bogus);
  */
-typedef void (*mesh_cb_func_t)(void*, int, ldns_buffer*, enum sec_status, 
+typedef void (*mesh_cb_func_t)(void*, int, struct ldns_buffer*, enum sec_status, 
        char*);
 
 /**
@@ -235,7 +236,7 @@ struct mesh_cb {
        /** flags of query, for reply flags */
        uint16_t qflags;
        /** buffer for reply */
-       ldns_buffer* buf;
+       struct ldns_buffer* buf;
 
        /** callback routine for results. if rcode != 0 buf has message.
         * called as cb(cb_arg, rcode, buf, sec_state);
@@ -294,7 +295,7 @@ void mesh_new_client(struct mesh_area* mesh, struct query_info* qinfo,
  * @return 0 on error.
  */
 int mesh_new_callback(struct mesh_area* mesh, struct query_info* qinfo,
-       uint16_t qflags, struct edns_data* edns, ldns_buffer* buf, 
+       uint16_t qflags, struct edns_data* edns, struct ldns_buffer* buf, 
        uint16_t qid, mesh_cb_func_t cb, void* cb_arg);
 
 /**
@@ -473,7 +474,7 @@ int mesh_state_add_reply(struct mesh_state* s, struct edns_data* edns,
  * @return: 0 on alloc error.
  */
 int mesh_state_add_cb(struct mesh_state* s, struct edns_data* edns,
-        ldns_buffer* buf, mesh_cb_func_t cb, void* cb_arg, uint16_t qid, 
+        struct ldns_buffer* buf, mesh_cb_func_t cb, void* cb_arg, uint16_t qid, 
        uint16_t qflags);
 
 /**
@@ -548,7 +549,7 @@ int mesh_state_ref_compare(const void* ap, const void* bp);
  *    You can pass NULL if there is no buffer that must be backed up.
  * @return false if no space is available.
  */
-int mesh_make_new_space(struct mesh_area* mesh, ldns_buffer* qbuf);
+int mesh_make_new_space(struct mesh_area* mesh, struct ldns_buffer* qbuf);
 
 /**
  * Insert mesh state into a double linked list.  Inserted at end.
index ece59098a72d7f4c1a912e004486350a2aefd2d6..b5e3b3ae6a4172eae012b6804153a8748478ac69 100644 (file)
@@ -45,7 +45,6 @@
 #  include <sys/types.h>
 #endif
 #include <sys/time.h>
-#include <ldns/wire2host.h>
 #include "services/outside_network.h"
 #include "services/listen_dnsport.h"
 #include "services/cache/infra.h"
@@ -58,6 +57,7 @@
 #include "util/net_help.h"
 #include "util/random.h"
 #include "util/fptr_wlist.h"
+#include "ldns/sbuffer.h"
 #ifdef HAVE_OPENSSL_SSL_H
 #include <openssl/ssl.h>
 #endif
index 87fe8ff108de178efbd15655644f4a79074eb9fc..3d294155f59515376cd42f39196c56670faf68b0 100644 (file)
@@ -54,6 +54,7 @@ struct waiting_udp;
 struct infra_cache;
 struct port_comm;
 struct port_if;
+struct ldns_buffer;
 
 /**
  * Send queries to outside servers and wait for answers from servers.
@@ -69,7 +70,7 @@ struct outside_network {
 
        /** buffer shared by UDP connections, since there is only one
            datagram at any time. */
-       ldns_buffer* udp_buff;
+       struct ldns_buffer* udp_buff;
        /** serviced_callbacks malloc overhead when processing multiple
         * identical serviced queries to the same server. */
        size_t svcd_overhead;
@@ -411,7 +412,7 @@ void outside_network_quit_prepare(struct outside_network* outnet);
  * @return: NULL on error for malloc or socket. Else the pending query object.
  */
 struct pending* pending_udp_query(struct outside_network* outnet, 
-       ldns_buffer* packet, struct sockaddr_storage* addr, 
+       struct ldns_buffer* packet, struct sockaddr_storage* addr, 
        socklen_t addrlen, int timeout, comm_point_callback_t* callback, 
        void* callback_arg);
 
@@ -431,7 +432,7 @@ struct pending* pending_udp_query(struct outside_network* outnet,
  * @return: false on error for malloc or socket. Else the pending TCP object.
  */
 struct waiting_tcp* pending_tcp_query(struct outside_network* outnet, 
-       ldns_buffer* packet, struct sockaddr_storage* addr, 
+       struct ldns_buffer* packet, struct sockaddr_storage* addr, 
        socklen_t addrlen, int timeout, comm_point_callback_t* callback, 
        void* callback_arg, int ssl_upstream);
 
@@ -476,7 +477,7 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
        uint16_t flags, int dnssec, int want_dnssec, int tcp_upstream,
        int ssl_upstream, struct sockaddr_storage* addr, socklen_t addrlen,
        uint8_t* zone, size_t zonelen, comm_point_callback_t* callback,
-       void* callback_arg, ldns_buffer* buff);
+       void* callback_arg, struct ldns_buffer* buff);
 
 /**
  * Remove service query callback.
index 2b6d4232b177e32f87708481c3167ec9a8574d21..ff54caea2db7315aea0eba75a59fd609339ad6b9 100644 (file)
 
 #include "config.h"
 #include "libunbound/unbound.h"
-#include <ldns/rr.h>
+#include "ldns/rrdef.h"
 #include <expat.h>
 #ifndef HAVE_EXPAT_H
 #error "need libexpat to parse root-anchors.xml file."
@@ -669,6 +669,15 @@ count_unused(struct ip_list* p)
        return num;
 }
 
+static int get_random(void)
+{
+       int r;
+       if (RAND_bytes((unsigned char*)&r, (int)sizeof(r)) == 1) {
+               return r;
+       }
+       return (int)random();
+}
+
 /** pick random unused element from IP list */
 static struct ip_list*
 pick_random_ip(struct ip_list* list)
@@ -678,7 +687,7 @@ pick_random_ip(struct ip_list* list)
        int sel;
        if(num == 0) return NULL;
        /* not perfect, but random enough */
-       sel = (int)ldns_get_random() % num;
+       sel = get_random() % num;
        /* skip over unused elements that we did not select */
        while(sel > 0 && p) {
                if(!p->used) sel--;
index c73d8bdc7c9c10957bdb0a2a031234c555428eda..77d2e2e1f746bc4f8e6d62f1516300e46837647e 100644 (file)
@@ -53,6 +53,7 @@
 #include "iterator/iter_hints.h"
 #include "validator/validator.h"
 #include "services/localzone.h"
+#include "ldns/sbuffer.h"
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #endif
@@ -343,9 +344,9 @@ morechecks(struct config_file* cfg, const char* fname)
                if(fname[0] != '/') {
                        if(getcwd(buf, sizeof(buf)) == NULL)
                                fatal_exit("getcwd: %s", strerror(errno));
-                       strncat(buf, "/", sizeof(buf)-strlen(buf)-1);
+                       strlcat(buf, "/", sizeof(buf));
                }
-               strncat(buf, fname, sizeof(buf)-strlen(buf)-1);
+               strlcat(buf, fname, sizeof(buf));
                if(strncmp(buf, cfg->chrootdir, strlen(cfg->chrootdir)) != 0)
                        fatal_exit("config file %s is not inside chroot %s",
                                buf, cfg->chrootdir);
index 715aa4a6516bc9cff4df1f9fdc9ef73ce7eefd0d..c3fb58a123504cc8267e67229c0bfb77afbeced1 100644 (file)
@@ -60,7 +60,8 @@
 #define unbound_lite_wrapstr(s) s
 #endif
 #include "libunbound/unbound.h"
-#include <ldns/ldns.h>
+#include "ldns/rrdef.h"
+#include "ldns/wire2str.h"
 #ifdef HAVE_NSS
 /* nss3 */
 #include "nss.h"
@@ -215,61 +216,36 @@ secure_str(struct ub_result* result)
 static void
 pretty_type(char* s, size_t len, int t)
 {
-       char* d = ldns_rr_type2str(t);
+       char d[16];
+       ldns_wire2str_type_buf((uint16_t)t, d, sizeof(d));
        snprintf(s, len, "%s", d);
-       free(d);
 }
 
 /** nice string for class */
 static void
 pretty_class(char* s, size_t len, int c)
 {
-       char* d = ldns_rr_class2str(c);
+       char d[16];
+       ldns_wire2str_class_buf((uint16_t)c, d, sizeof(d));
        snprintf(s, len, "%s", d);
-       free(d);
 }
 
 /** nice string for rcode */
 static void
 pretty_rcode(char* s, size_t len, int r)
 {
-       ldns_lookup_table *rcode = ldns_lookup_by_id(ldns_rcodes, r);
-       if(rcode) {
-               snprintf(s, len, "%s", rcode->name);
-       } else {
-               snprintf(s, len, "RCODE%d", r);
-       }
+       char d[16];
+       ldns_wire2str_rcode_buf(r, d, sizeof(d));
+       snprintf(s, len, "%s", d);
 }
 
 /** convert and print rdata */
 static void
 print_rd(int t, char* data, size_t len)
 {
-       size_t i, pos = 0;
-       uint8_t* rd = (uint8_t*)malloc(len+2);
-       ldns_rr* rr = ldns_rr_new();
-       ldns_status status;
-       if(!rd || !rr) {
-               fprintf(stderr, "out of memory");
-               exit(1);
-       }
-       ldns_rr_set_type(rr, t);
-       ldns_write_uint16(rd, len);
-       memmove(rd+2, data, len);
-       ldns_rr_set_owner(rr, NULL);
-       status = ldns_wire2rdf(rr, rd, len+2, &pos);
-       if(status != LDNS_STATUS_OK) {
-               free(rd);
-               ldns_rr_free(rr);
-               printf("error_printing_data");
-               return;
-       }
-       for(i=0; i<ldns_rr_rd_count(rr); i++) {
-               printf(" ");
-               ldns_rdf_print(stdout, ldns_rr_rdf(rr, i));
-       }
-       ldns_rr_free(rr);
-       free(rd);
+       char s[65535];
+       ldns_wire2str_rdata_buf((uint8_t*)data, len, s, sizeof(s), (uint16_t)t);
+       printf(" %s", s);
 }
 
 /** pretty line of RR data for results */
@@ -344,24 +320,14 @@ pretty_output(char* q, int t, int c, struct ub_result* result, int docname)
                        else if(t == LDNS_RR_TYPE_MX)
                                printf(" has no mail handler record");
                        else if(t == LDNS_RR_TYPE_ANY) {
-                               ldns_pkt* p = NULL;
-                               if(ldns_wire2pkt(&p, result->answer_packet,
-                                 (size_t)result->answer_len)==LDNS_STATUS_OK){
-                                       if(ldns_rr_list_rr_count(
-                                               ldns_pkt_answer(p)) == 0)
-                                               printf(" has no records\n");
-                                       else {
-                                               printf(" ANY:\n");
-                                               ldns_rr_list_print(stdout,
-                                                       ldns_pkt_answer(p));
-                                       }
-                               } else {
-                                       fprintf(stderr, "could not parse "
-                                               "reply packet to ANY query\n");
+                               char* s = ldns_wire2str_pkt(
+                                       result->answer_packet,
+                                       (size_t)result->answer_len);
+                               if(!s) {
+                                       fprintf(stderr, "alloc failure\n");
                                        exit(1);
                                }
-                               ldns_pkt_free(p);
-
+                               printf("%s\n", s);
                        } else  printf(" has no %s record", tstr);
                        printf(" %s\n", secstatus);
                }
index 4fc2e7d9098ea91a88c8b2f63a90570079b0edce..ccf9b59105ea621efceb5ec203eb65a14ddfbbc9 100644 (file)
@@ -166,21 +166,21 @@ void libworker_handle_control_cmd(struct tube* ATTR_UNUSED(tube),
 }
 
 void libworker_fg_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), 
-       ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s),
+       struct ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s),
        char* ATTR_UNUSED(why_bogus))
 {
        log_assert(0);
 }
 
 void libworker_bg_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), 
-       ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s),
+       struct ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s),
        char* ATTR_UNUSED(why_bogus))
 {
        log_assert(0);
 }
 
 void libworker_event_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), 
-       ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s),
+       struct ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s),
        char* ATTR_UNUSED(why_bogus))
 {
        log_assert(0);
index 7ec013c0cb9f566e5dcfbde5187e0c0a1b836c94..05f15dcf515e718c35b5237137f6a22e5c8adda3 100644 (file)
@@ -48,6 +48,7 @@
 #include "libunbound/context.h"
 #include "util/locks.h"
 #include "util/log.h"
+#include "ldns/rrdef.h"
 #ifdef UNBOUND_ALLOC_LITE
 #undef malloc
 #undef calloc
index b42a3b1aa7cd93b4d6e042f221aa394e48421dce..0c15b5e31310133b12f26b8a3dab21309f745ec8 100644 (file)
@@ -50,6 +50,7 @@
 #include <sys/time.h>
 #include "util/net_help.h"
 #include "util/config_file.h"
+#include "ldns/sbuffer.h"
 #include <signal.h>
 
 /** number of reads per select for delayer */
@@ -889,12 +890,12 @@ proxy_list_clear(struct proxy* p)
                        if(inet_ntop(AF_INET6, 
                                &((struct sockaddr_in6*)&p->addr)->sin6_addr,
                                from, (socklen_t)sizeof(from)) == 0)
-                               strncpy(from, "err", sizeof(from));
+                               strlcpy(from, "err", sizeof(from));
                } else {
                        if(inet_ntop(AF_INET, 
                                &((struct sockaddr_in*)&p->addr)->sin_addr,
                                from, (socklen_t)sizeof(from)) == 0)
-                               strncpy(from, "err", sizeof(from));
+                               strlcpy(from, "err", sizeof(from));
                }
                printf("client[%d]: last %s@%d of %d : %u in, %u out, "
                        "%u returned\n", i++, from, port, (int)p->numreuse+1,
index 085068c67c56feb9b93693be14a3f4ba14f89fc9..d16c0dcc21d2e0db1f86eaf6178bddd5d1656472 100644 (file)
 #include "services/outside_network.h"
 #include "services/cache/infra.h"
 #include "testcode/replay.h"
-#include "testcode/ldns-testpkts.h"
+#include "testcode/testpkts.h"
 #include "util/log.h"
 #include "util/fptr_wlist.h"
+#include "ldns/sbuffer.h"
+#include "ldns/wire2str.h"
+#include "ldns/str2wire.h"
 #include <signal.h>
 struct worker;
 struct daemon_remote;
@@ -108,11 +111,11 @@ fake_event_cleanup(void)
 
 /** helper function that logs a ldns_pkt packet to logfile */
 static void
-log_pkt(const char* desc, ldns_pkt* pkt)
+log_pkt(const char* desc, uint8_t* pkt, size_t len)
 {
-       char* str = ldns_pkt2str(pkt);
+       char* str = ldns_wire2str_pkt(pkt, len);
        if(!str)
-               log_info("%s: (failed)", desc);
+               fatal_exit("%s: (failed out of memory wire2str_pkt)", desc);
        else {
                log_info("%s%s", desc, str);
                free(str);
@@ -150,7 +153,7 @@ delete_fake_pending(struct fake_pending* pend)
                return;
        free(pend->zone);
        ldns_buffer_free(pend->buffer);
-       ldns_pkt_free(pend->pkt);
+       free(pend->pkt);
        free(pend);
 }
 
@@ -164,7 +167,7 @@ delete_replay_answer(struct replay_answer* a)
                ldns_buffer_free(a->repinfo.c->buffer);
                free(a->repinfo.c);
        }
-       ldns_pkt_free(a->pkt);
+       free(a->pkt);
        free(a);
 }
 
@@ -186,7 +189,8 @@ pending_matches_current(struct replay_runtime* runtime,
                        sockaddr_cmp(&p->addr, p->addrlen, &runtime->now->addr,
                        runtime->now->addrlen) != 0)
                        continue;
-               if((e=find_match(runtime->now->match, p->pkt, p->transport))) {
+               if((e=find_match(runtime->now->match, p->pkt, p->pkt_len,
+                       p->transport))) {
                        *entry = e;
                        *pend = p;
                        return 1;
@@ -212,13 +216,16 @@ pending_find_match(struct replay_runtime* runtime, struct entry** entry,
                if(p->start_step <= timenow && timenow <= p->end_step &&
                  (p->addrlen == 0 || sockaddr_cmp(&p->addr, p->addrlen,
                        &pend->addr, pend->addrlen) == 0) &&
-                 (*entry = find_match(p->match, pend->pkt, pend->transport))) {
+                 (*entry = find_match(p->match, pend->pkt, pend->pkt_len,
+                        pend->transport))) {
                        log_info("matched query time %d in range [%d, %d] "
                                "with entry line %d", timenow, 
                                p->start_step, p->end_step, (*entry)->lineno);
                        if(p->addrlen != 0)
                                log_addr(0, "matched ip", &p->addr, p->addrlen);
-                       log_pkt("matched pkt: ", (*entry)->reply_list->reply);
+                       log_pkt("matched pkt: ",
+                               (*entry)->reply_list->reply_pkt,
+                               (*entry)->reply_list->reply_len);
                        return 1;
                }
                p = p->next_range;
@@ -275,31 +282,26 @@ pending_list_delete(struct replay_runtime* runtime, struct fake_pending* pend)
  * Fill buffer with reply from the entry.
  */
 static void
-fill_buffer_with_reply(ldns_buffer* buffer, struct entry* entry, ldns_pkt* q)
+fill_buffer_with_reply(ldns_buffer* buffer, struct entry* entry, uint8_t* q,
+       size_t qlen)
 {
-       ldns_status status;
-       ldns_pkt* answer_pkt = NULL;
+       uint8_t* c;
+       size_t clen;
        log_assert(entry && entry->reply_list);
        ldns_buffer_clear(buffer);
        if(entry->reply_list->reply_from_hex) {
-               status = ldns_buffer2pkt_wire(&answer_pkt, 
-                       entry->reply_list->reply_from_hex);
-               if(status != LDNS_STATUS_OK) {
-                       log_err("testbound: hex packet unparsable, used asis.");
-                       ldns_buffer_write(buffer, 
-                       ldns_buffer_begin(entry->reply_list->reply_from_hex), 
-                       ldns_buffer_limit(entry->reply_list->reply_from_hex));
-               }
+               c = ldns_buffer_begin(entry->reply_list->reply_from_hex);
+               clen = ldns_buffer_limit(entry->reply_list->reply_from_hex);
+               if(!c) fatal_exit("out of memory");
        } else {
-               answer_pkt = ldns_pkt_clone(entry->reply_list->reply);
+               c = entry->reply_list->reply_pkt;
+               clen = entry->reply_list->reply_len;
        }
-       if(answer_pkt) {
-               if(q) adjust_packet(entry, answer_pkt, q);
-               status = ldns_pkt2buffer_wire(buffer, answer_pkt);
-               if(status != LDNS_STATUS_OK)
-                       fatal_exit("ldns: cannot pkt2buffer_wire parsed pkt");
+       if(c) {
+               if(q) adjust_packet(entry, &c, &clen, q, qlen);
+               ldns_buffer_write(buffer, c, clen);
+               if(q) free(c);
        }
-       ldns_pkt_free(answer_pkt);
        ldns_buffer_flip(buffer);
 }
 
@@ -324,7 +326,7 @@ answer_callback_from_entry(struct replay_runtime* runtime,
        c.type = comm_udp;
        if(pend->transport == transport_tcp)
                c.type = comm_tcp;
-       fill_buffer_with_reply(c.buffer, entry, pend->pkt);
+       fill_buffer_with_reply(c.buffer, entry, pend->pkt, pend->pkt_len);
        repinfo.c = &c;
        repinfo.addrlen = pend->addrlen;
        memcpy(&repinfo.addr, &pend->addr, pend->addrlen);
@@ -351,7 +353,8 @@ answer_check_it(struct replay_runtime* runtime)
                if((runtime->now->addrlen == 0 || sockaddr_cmp(
                        &runtime->now->addr, runtime->now->addrlen,
                        &ans->repinfo.addr, ans->repinfo.addrlen) == 0) &&
-                       find_match(runtime->now->match, ans->pkt, tr)) {
+                       find_match(runtime->now->match, ans->pkt,
+                               ans->pkt_len, tr)) {
                        log_info("testbound matched event entry from line %d",
                                runtime->now->match->lineno);
                        log_info("testbound: do STEP %d %s", 
@@ -394,9 +397,10 @@ fake_front_query(struct replay_runtime* runtime, struct replay_moment *todo)
        if(todo->match->match_transport == transport_tcp)
                repinfo.c->type = comm_tcp;
        else    repinfo.c->type = comm_udp;
-       fill_buffer_with_reply(repinfo.c->buffer, todo->match, NULL);
+       fill_buffer_with_reply(repinfo.c->buffer, todo->match, NULL, 0);
        log_info("testbound: incoming QUERY");
-       log_pkt("query pkt", todo->match->reply_list->reply);
+       log_pkt("query pkt", todo->match->reply_list->reply_pkt,
+               todo->match->reply_list->reply_len);
        /* call the callback for incoming queries */
        if((*runtime->callback_query)(repinfo.c, runtime->cb_arg, 
                NETEVENT_NOERROR, &repinfo)) {
@@ -424,13 +428,13 @@ fake_pending_callback(struct replay_runtime* runtime,
        if(!p) fatal_exit("No pending queries.");
        cb_arg = p->cb_arg;
        cb = p->callback;
-       log_assert(todo->qname == NULL); /* or find that one */
        c.buffer = ldns_buffer_new(runtime->bufsize);
        c.type = comm_udp;
        if(p->transport == transport_tcp)
                c.type = comm_tcp;
        if(todo->evt_type == repevt_back_reply && todo->match) {
-               fill_buffer_with_reply(c.buffer, todo->match, p->pkt);
+               fill_buffer_with_reply(c.buffer, todo->match, p->pkt,
+                       p->pkt_len);
        }
        repinfo.c = &c;
        repinfo.addrlen = p->addrlen;
@@ -552,16 +556,17 @@ do_infra_rtt(struct replay_runtime* runtime)
 {
        struct replay_moment* now = runtime->now;
        int rto;
-       ldns_rdf* dp = ldns_dname_new_frm_str(now->variable);
+       size_t dplen = 0;
+       uint8_t* dp = ldns_str2wire_dname(now->variable, &dplen);
        if(!dp) fatal_exit("cannot parse %s", now->variable);
-       rto = infra_rtt_update(runtime->infra, &now->addr,
-               now->addrlen, ldns_rdf_data(dp), ldns_rdf_size(dp),
-               LDNS_RR_TYPE_A, atoi(now->string), -1, runtime->now_secs);
+       rto = infra_rtt_update(runtime->infra, &now->addr, now->addrlen,
+               dp, dplen, LDNS_RR_TYPE_A, atoi(now->string),
+               -1, runtime->now_secs);
        log_addr(0, "INFRA_RTT for", &now->addr, now->addrlen);
        log_info("INFRA_RTT(%s roundtrip %d): rto of %d", now->variable,
                atoi(now->string), rto);
        if(rto == 0) fatal_exit("infra_rtt_update failed");
-       ldns_rdf_deep_free(dp);
+       free(dp);
 }
 
 /** perform exponential backoff on the timout */
@@ -712,7 +717,7 @@ run_scenario(struct replay_runtime* runtime)
                struct fake_pending* p;
                log_err("testbound: there are still messages pending.");
                for(p = runtime->pending_list; p; p=p->next) {
-                       log_pkt("pending msg", p->pkt);
+                       log_pkt("pending msg", p->pkt, p->pkt_len);
                        log_addr(0, "pending to", &p->addr, p->addrlen);
                }
                fatal_exit("testbound: there are still messages pending.");
@@ -856,7 +861,6 @@ comm_point_send_reply(struct comm_reply* repinfo)
 {
        struct replay_answer* ans = (struct replay_answer*)calloc(1,
                sizeof(struct replay_answer));
-       ldns_status status;
        struct replay_runtime* runtime = (struct replay_runtime*)repinfo->c->ev;
        log_info("testbound: comm_point_send_reply fake");
        /* dump it into the todo list */
@@ -869,13 +873,11 @@ comm_point_send_reply(struct comm_reply* repinfo)
        runtime->answer_last = ans;
 
        /* try to parse packet */
-       status = ldns_buffer2pkt_wire(&ans->pkt, ans->repinfo.c->buffer);
-       if(status != LDNS_STATUS_OK) {
-               log_err("ldns error parsing packet: %s",
-                       ldns_get_errorstr_by_id(status));
-               fatal_exit("Sending unparseable DNS replies to clients!");
-       }
-       log_pkt("reply pkt: ", ans->pkt);
+       ans->pkt = memdup(ldns_buffer_begin(ans->repinfo.c->buffer),
+               ldns_buffer_limit(ans->repinfo.c->buffer));
+       ans->pkt_len = ldns_buffer_limit(ans->repinfo.c->buffer);
+       if(!ans->pkt) fatal_exit("out of memory");
+       log_pkt("reply pkt: ", ans->pkt, ans->pkt_len);
 }
 
 void 
@@ -938,7 +940,6 @@ pending_udp_query(struct outside_network* outnet, ldns_buffer* packet,
        struct replay_runtime* runtime = (struct replay_runtime*)outnet->base;
        struct fake_pending* pend = (struct fake_pending*)calloc(1,
                sizeof(struct fake_pending));
-       ldns_status status;
        log_assert(pend);
        pend->buffer = ldns_buffer_new(ldns_buffer_capacity(packet));
        log_assert(pend->buffer);
@@ -955,20 +956,18 @@ pending_udp_query(struct outside_network* outnet, ldns_buffer* packet,
        pend->zone = NULL;
        pend->serviced = 0;
        pend->runtime = runtime;
-       status = ldns_buffer2pkt_wire(&pend->pkt, packet);
-       if(status != LDNS_STATUS_OK) {
-               log_err("ldns error parsing udp output packet: %s",
-                       ldns_get_errorstr_by_id(status));
-               fatal_exit("Sending unparseable DNS packets to servers!");
-       }
-       log_pkt("pending udp pkt: ", pend->pkt);
+       pend->pkt_len = ldns_buffer_limit(packet);
+       pend->pkt = memdup(ldns_buffer_begin(packet), pend->pkt_len);
+       if(!pend->pkt) fatal_exit("out of memory");
+       log_pkt("pending udp pkt: ", pend->pkt, pend->pkt_len);
 
        /* see if it matches the current moment */
        if(runtime->now && runtime->now->evt_type == repevt_back_query &&
                (runtime->now->addrlen == 0 || sockaddr_cmp(
                        &runtime->now->addr, runtime->now->addrlen,
                        &pend->addr, pend->addrlen) == 0) &&
-               find_match(runtime->now->match, pend->pkt, pend->transport)) {
+               find_match(runtime->now->match, pend->pkt, pend->pkt_len,
+                       pend->transport)) {
                log_info("testbound: matched pending to event. "
                        "advance time between events.");
                log_info("testbound: do STEP %d %s", runtime->now->time_step,
@@ -992,7 +991,6 @@ pending_tcp_query(struct outside_network* outnet, ldns_buffer* packet,
        struct replay_runtime* runtime = (struct replay_runtime*)outnet->base;
        struct fake_pending* pend = (struct fake_pending*)calloc(1,
                sizeof(struct fake_pending));
-       ldns_status status;
        log_assert(pend);
        pend->buffer = ldns_buffer_new(ldns_buffer_capacity(packet));
        log_assert(pend->buffer);
@@ -1009,20 +1007,18 @@ pending_tcp_query(struct outside_network* outnet, ldns_buffer* packet,
        pend->zone = NULL;
        pend->runtime = runtime;
        pend->serviced = 0;
-       status = ldns_buffer2pkt_wire(&pend->pkt, packet);
-       if(status != LDNS_STATUS_OK) {
-               log_err("ldns error parsing tcp output packet: %s",
-                       ldns_get_errorstr_by_id(status));
-               fatal_exit("Sending unparseable DNS packets to servers!");
-       }
-       log_pkt("pending tcp pkt: ", pend->pkt);
+       pend->pkt_len = ldns_buffer_limit(packet);
+       pend->pkt = memdup(ldns_buffer_begin(packet), pend->pkt_len);
+       if(!pend->pkt) fatal_exit("out of memory");
+       log_pkt("pending tcp pkt: ", pend->pkt, pend->pkt_len);
 
        /* see if it matches the current moment */
        if(runtime->now && runtime->now->evt_type == repevt_back_query &&
                (runtime->now->addrlen == 0 || sockaddr_cmp(
                        &runtime->now->addr, runtime->now->addrlen,
                        &pend->addr, pend->addrlen) == 0) &&
-               find_match(runtime->now->match, pend->pkt, pend->transport)) {
+               find_match(runtime->now->match, pend->pkt, pend->pkt_len,
+                       pend->transport)) {
                log_info("testbound: matched pending to event. "
                        "advance time between events.");
                log_info("testbound: do STEP %d %s", runtime->now->time_step,
@@ -1049,7 +1045,6 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
        struct fake_pending* pend = (struct fake_pending*)calloc(1,
                sizeof(struct fake_pending));
        char z[256];
-       ldns_status status;
        log_assert(pend);
        log_nametypeclass(VERB_OPS, "pending serviced query", 
                qname, qtype, qclass);
@@ -1096,20 +1091,18 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
        pend->pkt = NULL;
        pend->runtime = runtime;
        pend->serviced = 1;
-       status = ldns_buffer2pkt_wire(&pend->pkt, pend->buffer);
-       if(status != LDNS_STATUS_OK) {
-               log_err("ldns error parsing serviced output packet: %s",
-                       ldns_get_errorstr_by_id(status));
-               fatal_exit("internal error");
-       }
-       /*log_pkt("pending serviced query: ", pend->pkt);*/
+       pend->pkt_len = ldns_buffer_limit(pend->buffer);
+       pend->pkt = memdup(ldns_buffer_begin(pend->buffer), pend->pkt_len);
+       if(!pend->pkt) fatal_exit("out of memory");
+       /*log_pkt("pending serviced query: ", pend->pkt, pend->pkt_len);*/
 
        /* see if it matches the current moment */
        if(runtime->now && runtime->now->evt_type == repevt_back_query &&
                (runtime->now->addrlen == 0 || sockaddr_cmp(
                        &runtime->now->addr, runtime->now->addrlen,
                        &pend->addr, pend->addrlen) == 0) &&
-               find_match(runtime->now->match, pend->pkt, pend->transport)) {
+               find_match(runtime->now->match, pend->pkt, pend->pkt_len,
+                       pend->transport)) {
                log_info("testbound: matched pending to event. "
                        "advance time between events.");
                log_info("testbound: do STEP %d %s", runtime->now->time_step,
@@ -1138,7 +1131,7 @@ void outnet_serviced_query_stop(struct serviced_query* sq, void* cb_arg)
                                prev->next = p->next;
                        else    runtime->pending_list = p->next;
                        ldns_buffer_free(p->buffer);
-                       ldns_pkt_free(p->pkt);
+                       free(p->pkt);
                        free(p->zone);
                        free(p);
                        return;
diff --git a/testcode/harvest.c b/testcode/harvest.c
deleted file mode 100644 (file)
index 1952dc2..0000000
+++ /dev/null
@@ -1,857 +0,0 @@
-/*
- * testcode/harvest.c - debug program to get relevant data to a set of queries.
- *
- * Copyright (c) 2008, NLnet Labs. All rights reserved.
- *
- * This software is open source.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 
- * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 
- * Neither the name of the NLNET LABS nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * \file
- *
- * This program downloads relevant DNS data to a set of queries.
- * This means that the queries are asked to root, TLD, SLD servers and
- * the results stored per zone.
- * The following data is pertinent:
- *
- * At each label:
- *     SOA
- *     NS
- *     DNSKEY
- *     DS
- * For the whole query:
- *     the result.
- * For NS-records:
- *     their label data
- *     and the A and AAAA records for it.
- *     (as if the name, with A and AAAA query type is in the list,
- *      referred to as recursion depth+1)
- * Any NSEC, NSEC3, SOA records or additional data found in answers.
- *
- * All of this is data that would be encountered during an iterative lookup
- * for the queries in the list. It is saved to enable a replay of iterative
- * lookups for performance testing.
- *
- * A number of assumptions are made.
- * 1) configuration is correct.
- *    The parent has the same NS records as the child.
- *    All nameservers carry the same data.
- * 2) EDNS/nonEDNS responses and other behaviour is ignored.
- *    Only the data is saved.
- * This creates a snapshot that represents the data as this resolver saw it.
- */
-
-#include "config.h"
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
-#include <ldns/ldns.h>
-#include <signal.h>
-#include "libunbound/unbound.h"
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-#ifdef UNBOUND_ALLOC_LITE
-#undef malloc
-#undef calloc
-#undef realloc
-#undef free
-#undef strdup
-#define unbound_lite_wrapstr(s) s
-#endif
-struct todo_item;
-struct labdata;
-
-/** this represents the data that has been collected 
- * as well as a todo list and some settings */
-struct harvest_data {
-       /** the unbound context */
-       struct ub_ctx* ctx;
-
-       /** a tree per label; thus this first one is one root entry,
-        * that has a tree of TLD labels. Those have trees of SLD labels. */
-       struct labdata* root;
-       /** the original query list */
-       struct todo_item* orig_list;
-       /** the query list todo */
-       struct todo_item* todo_list;
-       /** last item in todo list */
-       struct todo_item* todo_last;
-       /** number of todo items */
-       int numtodo;
-
-       /** where to store the results */
-       char* resultdir;
-       /** maximum recursion depth */
-       int maxdepth;
-       /** current recursion depth */
-       int curdepth;
-
-       /** max depth of labels */
-       int maxlabels;
-       /** number of RRs stored */
-       int num_rrs;
-       /** number of zones written */
-       int num_zones;
-};
-
-/**
- * Todo item
- */
-struct todo_item {
-       /** the next item */
-       struct todo_item* next;
-
-       /** query as rdf */
-       ldns_rdf* qname;
-       /** the query type */
-       int qtype;
-       /** query class */
-       int qclass;
-
-       /** recursion depth of todo item (orig list is 0) */
-       int depth;
-       /** the label associated with the query */
-       struct labdata* lab;
-};
-
-/** 
- * Every label has a sest of sublabels, that have sets of sublabels ...
- * Per label is stored also a set of data items, and todo information
- */
-struct labdata {
-       /** node in ldns rbtree */
-       ldns_rbnode_t node;
-       /** the name of this label */
-       ldns_rdf* label;
-       /** full name of point in domain tree */
-       ldns_rdf* name;
-
-       /** parent in label tree (NULL for root) */
-       struct labdata* parent;
-       /** tree of sublabels (if any) */
-       ldns_rbtree_t* sublabels;
-
-       /** list of RRs for this label */
-       ldns_rr_list* rrlist;
-       /** have queries for this label been queued */
-       int done;
-};
-
-/** usage information for harvest */
-static void usage(char* nm) 
-{
-       printf("usage: %s [options]\n", nm);
-       printf("-f fnm  query list to read from file\n");
-       printf("        every line has format: qname qclass qtype\n");
-       printf("-v      verbose (-v -v even more)\n");
-       printf("-C cfg  config file with resolver options\n");
-       exit(1);
-}
-
-/** verbosity for harvest */
-static int hverb = 0;
-
-/** exit with error */
-static void error_exit(const char* str)
-{
-       printf("error: %s\n", str);
-       exit(1);
-}
-
-/** read a query file */
-static void
-qlist_read_file(struct harvest_data* data, char* fname)
-{
-       char buf[1024];
-       char nm[1024], cl[1024], tp[1024];
-       int r;
-       int num = 0;
-       FILE* in = fopen(fname, "r");
-       struct todo_item* t;
-       if(!in) {
-               perror(fname);
-               error_exit("could not open file");
-       }
-       while(fgets(buf, (int)sizeof(buf), in)) {
-               if(buf[0] == 0) continue;
-               if(buf[0] == '\n') continue;
-               /* allow some comments */
-               if(buf[0] == ';') continue;
-               if(buf[0] == '#') continue;
-               nm[0] = 0; cl[0] = 0; tp[0] = 0;
-               r = sscanf(buf, " %1023s %1023s %1023s", nm, cl, tp);
-               if(r == 0) continue;
-               t = (struct todo_item*)calloc(1, sizeof(*t));
-               if(!t) error_exit("out of memory");
-               t->qname = ldns_dname_new_frm_str(nm);
-               if(!t->qname) {
-                       printf("parse error: %s\n", nm);
-                       error_exit("bad qname");
-               }
-               t->depth = 0;
-               t->qtype = LDNS_RR_TYPE_A;
-               t->qclass = LDNS_RR_CLASS_IN;
-               if(r >= 2) {
-                       if(strcmp(cl, "IN") == 0 || strcmp(cl, "CH") == 0)
-                               t->qclass = ldns_get_rr_class_by_name(cl);
-                       else    t->qtype = ldns_get_rr_type_by_name(cl);
-               }
-               if(r >= 3) {
-                       if(strcmp(tp, "IN") == 0 || strcmp(tp, "CH") == 0)
-                               t->qclass = ldns_get_rr_class_by_name(tp);
-                       else    t->qtype = ldns_get_rr_type_by_name(tp);
-               }
-               num++;
-
-               t->next = data->orig_list;
-               data->orig_list = t;
-       }
-       printf("read %s: %d queries\n", fname, num);
-       fclose(in);
-}
-
-/** compare two labels */
-static int
-lab_cmp(const void *x, const void *y)
-{
-       return ldns_dname_compare((const ldns_rdf*)x, (const ldns_rdf*)y);
-}
-
-/** create label entry */
-static struct labdata*
-lab_create(const char* name)
-{
-       struct labdata* lab = (struct labdata*)calloc(1, sizeof(*lab));
-       if(!lab) error_exit("out of memory");
-       lab->label = ldns_dname_new_frm_str(name);
-       if(!lab->label) error_exit("out of memory");
-       lab->name = ldns_dname_new_frm_str(name);
-       if(!lab->name) error_exit("out of memory");
-       lab->node.key = lab->label;
-       lab->node.data = lab;
-       lab->sublabels = ldns_rbtree_create(lab_cmp);
-       if(!lab->sublabels) error_exit("out of memory");
-       lab->rrlist = ldns_rr_list_new();
-       if(!lab->rrlist) error_exit("out of memory");
-
-       return lab;
-}
-
-/** for this name, lookup the label, create if does not exist */
-static struct labdata*
-find_create_lab(struct harvest_data* data, ldns_rdf* name)
-{
-       struct labdata* lab = data->root;
-       struct labdata* nextlab;
-       ldns_rdf* next;
-       uint8_t numlab = ldns_dname_label_count(name);
-       if((int)numlab > data->maxlabels)
-               data->maxlabels = (int)numlab;
-       while(numlab--) {
-               next = ldns_dname_label(name, numlab);
-               if(!next) error_exit("ldns_dname_label");
-               
-               nextlab = (struct labdata*)
-                       ldns_rbtree_search(lab->sublabels, next);
-               if(!nextlab) {
-                       /* create it */
-                       nextlab = (struct labdata*)calloc(1, sizeof(*lab));
-                       if(!nextlab) error_exit("out of memory");
-                       nextlab->label = ldns_rdf_clone(next);
-                       if(!nextlab->label) error_exit("out of memory");
-                       nextlab->node.key = nextlab->label;
-                       nextlab->node.data = nextlab;
-                       nextlab->sublabels = ldns_rbtree_create(lab_cmp);
-                       if(!nextlab->sublabels) error_exit("out of memory");
-                       nextlab->parent = lab;
-                       nextlab->name = ldns_rdf_clone(next);
-                       if(!nextlab->name) error_exit("out of memory");
-                       if(ldns_dname_cat(nextlab->name, lab->name) 
-                               != LDNS_STATUS_OK) error_exit("outofmem");
-                       nextlab->rrlist = ldns_rr_list_new();
-                       if(!nextlab->rrlist) error_exit("out of memory");
-                       (void)ldns_rbtree_insert(lab->sublabels, 
-                               &nextlab->node);
-                       if(hverb) {
-                               printf("new label: ");
-                               ldns_rdf_print(stdout, nextlab->name);
-                               printf("\n");
-                       }
-               }
-               lab = nextlab;
-               ldns_rdf_deep_free(next);
-       }
-       return lab;
-}
-
-/** for given query, create todo items, and labels if needed */
-static void
-new_todo_item(struct harvest_data* data, ldns_rdf* qname, int qtype, 
-       int qclass, int depth)
-{
-       struct labdata* lab = find_create_lab(data, qname);
-       struct todo_item* it;
-       if(!lab) error_exit("out of memory creating new label");
-       it = (struct todo_item*)calloc(1, sizeof(*it));
-       it->qname = ldns_rdf_clone(qname);
-       it->qtype = qtype;
-       it->qclass = qclass;
-       it->depth = depth;
-       it->lab = lab;
-       it->next = NULL;
-       if(data->todo_last)
-               data->todo_last->next = it;
-       else data->todo_list = it;
-       data->todo_last = it;
-       data->numtodo ++;
-       if(hverb >= 2) {
-               printf("new todo: ");
-               ldns_rdf_print(stdout, it->qname);
-               if(ldns_rr_descript((uint16_t)it->qtype) && 
-                       ldns_rr_descript((uint16_t)it->qtype)->_name)
-                       printf(" %s", ldns_rr_descript((uint16_t)
-                       it->qtype)->_name);
-               if(ldns_lookup_by_id(ldns_rr_classes, it->qclass) && 
-                       ldns_lookup_by_id(ldns_rr_classes, it->qclass)->name) 
-                       printf(" %s", ldns_lookup_by_id(ldns_rr_classes, 
-                               it->qclass)->name);
-               printf("\n");
-       }
-}
-
-/** add infra todo items for this query */
-static void
-new_todo_infra(struct harvest_data* data, struct labdata* startlab, int depth)
-{
-       struct labdata* lab;
-       for(lab = startlab; lab; lab = lab->parent) {
-               if(lab->done)
-                       return;
-               new_todo_item(data, lab->name, LDNS_RR_TYPE_NS, 
-                       LDNS_RR_CLASS_IN, depth);
-               new_todo_item(data, lab->name, LDNS_RR_TYPE_SOA, 
-                       LDNS_RR_CLASS_IN, depth);
-               new_todo_item(data, lab->name, LDNS_RR_TYPE_DNSKEY, 
-                       LDNS_RR_CLASS_IN, depth);
-               new_todo_item(data, lab->name, LDNS_RR_TYPE_DS, 
-                       LDNS_RR_CLASS_IN, depth);
-               new_todo_item(data, lab->name, LDNS_RR_TYPE_A, 
-                       LDNS_RR_CLASS_IN, depth);
-               new_todo_item(data, lab->name, LDNS_RR_TYPE_AAAA, 
-                       LDNS_RR_CLASS_IN, depth);
-               lab->done = 1;
-       }
-}
-
-/** make todo items for initial data */
-static void
-make_todo(struct harvest_data* data)
-{
-       struct todo_item* it;
-       for(it=data->orig_list; it; it = it->next) {
-               /* create todo item for this query itself */
-               new_todo_item(data, it->qname, it->qtype, it->qclass, 0);
-               /* create todo items for infra queries to support it */
-               new_todo_infra(data, data->todo_list->lab, 
-                       data->todo_list->depth);
-       }
-}
-
-/** store RR and make new work items for it if needed */
-static void
-process_rr(struct harvest_data* data, ldns_rr* rr, int depth)
-{
-       /* must free or store rr */
-       struct labdata* lab = find_create_lab(data, ldns_rr_owner(rr));
-       if(!lab) error_exit("cannot find/create label");
-       /* generate extra queries */
-       if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_NS) {
-               new_todo_infra(data, find_create_lab(data, 
-                       ldns_rr_ns_nsdname(rr)), depth+1);
-       } else if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_MX) {
-               new_todo_infra(data, find_create_lab(data, 
-                       ldns_rr_mx_exchange(rr)), depth+1);
-       } else if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA) {
-               new_todo_infra(data, find_create_lab(data, 
-                       ldns_rr_rdf(rr, 0)), depth+1);
-       } else if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_CNAME) {
-               int t = ldns_rr_get_type(rr);
-               if(t!=LDNS_RR_TYPE_A && t!=LDNS_RR_TYPE_AAAA &&
-                       t!=LDNS_RR_TYPE_SOA && t!=LDNS_RR_TYPE_NS &&
-                       t!=LDNS_RR_TYPE_DS && t!=LDNS_RR_TYPE_DNSKEY)
-                       new_todo_item(data, ldns_rr_rdf(rr, 0), t,
-                               ldns_rr_get_class(rr), depth+1);
-                       /* can get caught in CNAME loop, but depth will
-                        * catch that; unbound cache helps too(servfails on
-                        * a cname loop) */
-               new_todo_infra(data, find_create_lab(data, 
-                       ldns_rr_rdf(rr, 0)), depth+1);
-       }
-       /* store it */
-       if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_NSEC) {
-               /* find correct zone to store NSEC in (for delegation zones) */
-               if(ldns_dname_compare(ldns_rr_rdf(rr, 0), ldns_rr_owner(rr))
-                       == 0) {
-                       /* store at the single name = apex */
-               } else if(!ldns_dname_is_subdomain(ldns_rr_rdf(rr, 0), 
-                       ldns_rr_owner(rr)) && lab->parent) {
-                       /* if   owner NSEC subdomain-of-owner then
-                        * store at owner (owner is apex or empty nonterminal).
-                        * Otherwise at owner parent. */
-                       lab = lab->parent;
-               }
-       } else if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_DS) {
-               /* store DSes in parent zone */
-               if(lab->parent)
-                       lab = lab->parent;
-       } else if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_NSEC3) {
-               /* store NSEC3s one label up at zone apex */
-               if(lab->parent)
-                       lab = lab->parent;
-       }
-       /* we assume NS set is equal across parent-child border. */
-
-       if(!ldns_rr_list_contains_rr(lab->rrlist, rr)) {
-               if(hverb >= 2) {
-                       printf("store RR ");
-                       ldns_rr_print(stdout, rr);
-                       printf("\n");
-               }
-               if(!ldns_rr_list_push_rr(lab->rrlist, rr))
-                       error_exit("outofmem ldns_rr_list_push_rr");
-               data->num_rrs++;
-       } else {
-               if(hverb >= 2) {
-                       printf("duplicate RR ");
-                       ldns_rr_print(stdout, rr);
-                       printf("\n");
-               }
-               ldns_rr_free(rr);
-       }
-}
-
-/** store RRs and make new work items if needed */
-static void
-process_pkt(struct harvest_data* data, ldns_pkt* pkt, int depth)
-{
-       size_t i;
-       ldns_rr_list* list;
-       list = ldns_pkt_get_section_clone(pkt, LDNS_SECTION_ANY_NOQUESTION);
-       if(!list) error_exit("outofmemory");
-       for(i=0; i<ldns_rr_list_rr_count(list); i++) {
-               process_rr(data, ldns_rr_list_rr(list, i), depth);
-       }
-       ldns_rr_list_free(list);
-}
-
-/** process a todo item */
-static void
-process(struct harvest_data* data, struct todo_item* it)
-{
-       int r;
-       char* nm;
-       struct ub_result* result = NULL;
-       ldns_pkt* pkt = NULL;
-       ldns_status s;
-       if(hverb) {
-               printf("process: ");
-               ldns_rdf_print(stdout, it->qname);
-               if(ldns_rr_descript((uint16_t)it->qtype) && 
-                       ldns_rr_descript((uint16_t)it->qtype)->_name)
-                       printf(" %s", ldns_rr_descript((uint16_t)
-                       it->qtype)->_name);
-               if(ldns_lookup_by_id(ldns_rr_classes, it->qclass) && 
-                       ldns_lookup_by_id(ldns_rr_classes, it->qclass)->name) 
-                       printf(" %s", ldns_lookup_by_id(ldns_rr_classes, 
-                               it->qclass)->name);
-               printf("\n");
-       }
-       /* do lookup */
-       nm = ldns_rdf2str(it->qname);
-       if(!nm) error_exit("ldns_rdf2str");
-       r = ub_resolve(data->ctx, nm, it->qtype, it->qclass, &result);
-       if(r != 0) {
-               printf("ub_resolve(%s, %d, %d): %s\n", nm, it->qtype, 
-                       it->qclass, ub_strerror(r));
-               free(nm);
-               return;
-       }
-       if(result->rcode == LDNS_RCODE_SERVFAIL) {
-               free(nm);
-               return;
-       }
-       /* even if result is a negative, try to store resulting SOA/NSEC */
-
-       /* create ldns pkt */
-       s = ldns_wire2pkt(&pkt, result->answer_packet, 
-               (size_t)result->answer_len);
-       if(s != LDNS_STATUS_OK) {
-               printf("ldns_wire2pkt failed! %s %d %d %s %d\n", nm, 
-                       it->qtype, it->qclass, ldns_get_errorstr_by_id(s),
-                       result->answer_len);
-               free(nm);
-               return;
-       }
-       if(hverb >= 2) {
-               printf("answer: ");
-               ldns_pkt_print(stdout, pkt);
-               printf("\n");
-       }
-       /* process results */
-       process_pkt(data, pkt, it->depth);
-
-       ldns_pkt_free(pkt);
-       free(nm);
-       ub_resolve_free(result);
-}
-
-/** perform main harvesting */
-static void
-harvest_main(struct harvest_data* data)
-{
-       struct todo_item* it;
-       int numdone = 0;
-       /* register todo queries for all original queries */
-       make_todo(data);
-       printf("depth 0: done %d todo %d\n", 0, data->numtodo);
-       /* pick up a todo item and process it */
-       while(data->todo_list) {
-               numdone++;
-               it = data->todo_list;
-               data->todo_list = it->next;
-               if(!data->todo_list) data->todo_last = NULL;
-               if(numdone%1000==0 || it->depth > data->curdepth) {
-                       data->curdepth = it->depth;
-                       printf("depth %d: done %d todo %d, %d rrs\n", 
-                               it->depth, numdone, data->numtodo, 
-                               data->num_rrs);
-               }
-               if(it->depth >= data->maxdepth) {
-                       printf("obtained %d rrs to a max of %d labels.\n",
-                               data->num_rrs, data->maxlabels);
-                       return;
-               }
-               data->numtodo--;
-               process(data, it);
-               usleep(1000000/100);
-       }
-}
-
-/** create directory if it does not exist */
-static void
-hv_mkdir(char* dir)
-{
-#ifdef MKDIR_HAS_ONE_ARG
-       if(mkdir(dir) == -1) {
-#else
-       if(mkdir(dir, 0755) == -1) {
-#endif
-               if(errno == EEXIST)
-                       return;
-               perror(dir);
-               error_exit("mkdir failed");
-       }
-}
-
-
-/** see if rrlist contains a SOA record */
-static ldns_rr*
-has_SOA(ldns_rr_list* list)
-{
-       size_t i;
-       for(i=0; i<ldns_rr_list_rr_count(list); i++) {
-               if(ldns_rr_get_type(ldns_rr_list_rr(list, i)) 
-                       == LDNS_RR_TYPE_SOA)
-                       return ldns_rr_list_rr(list, i);
-       }
-       return NULL;
-}
-
-/** write moredata for a zone*/
-static void
-write_moredata(struct harvest_data* data, struct labdata* zone,
-       FILE *f, struct labdata* thislab, ldns_rr* nslist)
-{
-       struct labdata* lab;
-       size_t i;
-       ldns_rr* ns;
-       LDNS_RBTREE_FOR(lab, struct labdata*, thislab->sublabels) {
-               if(has_SOA(lab->rrlist)) {
-                       /* copy only NS glue */
-                       for(i=0; i<ldns_rr_list_rr_count(lab->rrlist); i++) {
-                               ns = ldns_rr_list_rr(lab->rrlist, i);
-                               if(ldns_rr_get_type(ns) == LDNS_RR_TYPE_NS) {
-                                       ldns_rr_print(f, ns);
-                                       if(ldns_dname_is_subdomain(
-                                               ldns_rr_ns_nsdname(ns), 
-                                               lab->name)) {
-                                               ldns_rr_push_rdf(nslist, 
-                                                       ldns_rdf_clone(
-                                                       ldns_rr_ns_nsdname(ns)));
-                                       }
-                               }
-                       }
-               } else {
-                       /* copy all, recurse */
-                       for(i=0; i<ldns_rr_list_rr_count(lab->rrlist); i++) {
-                               ldns_rr_print(f, 
-                                       ldns_rr_list_rr(lab->rrlist, i));
-                       }
-                       write_moredata(data, zone, f, lab, nslist);
-               }
-       }
-}
-
-/** find and write glue into zone file */
-static void
-write_glue(struct harvest_data* data, struct labdata* thislab, FILE* f, 
-       ldns_rdf* name, int dep)
-{
-       size_t i;
-       struct labdata* lab;
-       ldns_rr* rr;
-       if(ldns_dname_compare(name, thislab->name) == 0) {
-               /* this is it! Did we go outside the zone? */
-               if(dep == 0)
-                       return;
-               /* find A and AAAA */
-               for(i=0; i<ldns_rr_list_rr_count(thislab->rrlist); i++) {
-                       rr = ldns_rr_list_rr(thislab->rrlist, i);
-                       if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_A ||
-                          ldns_rr_get_type(rr) == LDNS_RR_TYPE_AAAA) {
-                               ldns_rr_print(f, rr);
-                       }
-               }
-               return;
-       }
-       /* recurse deeper */
-       LDNS_RBTREE_FOR(lab, struct labdata*, thislab->sublabels) {
-               if(has_SOA(lab->rrlist)) {
-                       write_glue(data, lab, f, name, dep+1);
-               } else {
-                       write_glue(data, lab, f, name, dep);
-               }
-       }
-}
-
-/** write zonefile for zone at this apex */
-static void
-write_zonefile(struct harvest_data* data, int dep, FILE* zlist, 
-       struct labdata* apex, ldns_rr* soa)
-{
-       FILE *f;
-       char fname[1024];
-       char* zname = ldns_rdf2str(apex->name);
-       time_t tm = time(NULL);
-       size_t i;
-       ldns_rr* nslist;
-       if(!zname) error_exit("out of mem ldns_rdf2str");
-       if(strcmp(zname, ".") == 0)
-               snprintf(fname, sizeof(fname), "l%d/root.zone", dep);
-       else    snprintf(fname, sizeof(fname), "l%d/%szone", dep, zname);
-
-       fprintf(zlist, "zone: name: \"%s\" %s%szonefile: \"%s\"\n",
-               zname, 
-               strlen(zname)/8<1?"\t":"",
-               strlen(zname)/8<2?"\t":"",
-               fname);
-
-       if(hverb) printf("writing %s\n", fname);
-       f = fopen(fname, "w");
-       if(!f) {
-               perror(fname);
-               error_exit("cannot open zone file");
-       }
-       fprintf(f, "; %s - generated by harvest program.\n", fname);
-       fprintf(f, "; zone name %s - this is a partial snapshot of "
-               "data relevant to the query list.\n", zname);
-       fprintf(f, "; created %u - date %s\n", (unsigned)tm, ctime(&tm));
-       ldns_rr_print(f, soa);
-       fprintf(f, "\n");
-       for(i=0; i<ldns_rr_list_rr_count(apex->rrlist); i++) {
-               if(ldns_rr_get_type(ldns_rr_list_rr(apex->rrlist, i))
-                       == LDNS_RR_TYPE_SOA) continue;
-               ldns_rr_print(f, ldns_rr_list_rr(apex->rrlist, i));
-       }
-       /* search for more data - subdomains inside the zone, NS glue */
-       nslist = ldns_rr_new();
-       if(!nslist) error_exit("out of memory");
-       fprintf(f, "; end of apex, more data follows\n");
-       write_moredata(data, apex, f, apex, nslist);
-
-       /* add NS from apex that need glue too */
-       for(i=0; i<ldns_rr_list_rr_count(apex->rrlist); i++) {
-               if(ldns_rr_get_type(ldns_rr_list_rr(apex->rrlist, i)) !=
-                       LDNS_RR_TYPE_NS)
-                       continue;
-               /* these are only added again if in a subzone */
-               if(ldns_dname_is_subdomain(ldns_rr_ns_nsdname(
-                       ldns_rr_list_rr(apex->rrlist, i)), apex->name)) {
-                       ldns_rr_push_rdf(nslist, ldns_rdf_clone(
-                               ldns_rr_ns_nsdname(ldns_rr_list_rr(
-                               apex->rrlist, i))));
-               }
-       }
-
-       fprintf(f, "; glue data follows\n");
-       /* lookup and add glue (if not already in zone) */
-       for(i=0; i<ldns_rr_rd_count(nslist); i++) {
-               write_glue(data, apex, f, ldns_rr_rdf(nslist, i), 0);
-       }
-
-       fclose(f);
-       ldns_rr_free(nslist);
-       free(zname);
-}
-
-/** create zones at depth d in label tree */
-static void
-create_zones(struct harvest_data* data, int dep, FILE* zlist, 
-       struct labdata* labnow, int depnow)
-{
-       struct labdata* s;
-       ldns_rr* soa;
-       if(depnow == dep) {
-               /* see if this is a zone start - a SOA */
-               if((soa=has_SOA(labnow->rrlist))) {
-                       write_zonefile(data, dep, zlist, labnow, soa);
-                       data->num_zones++;
-               }
-               return;
-       }
-       /* recurse */
-       LDNS_RBTREE_FOR(s, struct labdata*, labnow->sublabels) {
-               create_zones(data, dep, zlist, s, depnow+1);
-       }
-}
-
-/** sort rrlists */
-static void
-harvest_sort(struct labdata* lab)
-{
-       struct labdata* s;
-       /* prettier output if sorted here */
-       ldns_rr_list_sort(lab->rrlist);
-       /* and recurse */
-       LDNS_RBTREE_FOR(s, struct labdata*, lab->sublabels) {
-               harvest_sort(s);
-       }
-}
-
-/** output harvested results */
-static void
-harvest_output(struct harvest_data* data)
-{
-       int d;
-       char buf[20];
-       FILE* zlist;
-       int lastzones;
-       hv_mkdir(data->resultdir);
-       if(chdir(data->resultdir) == -1) {
-               perror(data->resultdir);
-               error_exit("cannot chdir");
-       }
-       harvest_sort(data->root);
-       /* create zones */
-       for(d = 0; d<data->maxlabels; d++) {
-               lastzones = data->num_zones;
-               printf("creating zones %d\n", d);       
-               snprintf(buf, sizeof(buf), "l%d", d);
-               hv_mkdir(buf);
-               snprintf(buf, sizeof(buf), "l%d.zones", d);
-               zlist = fopen(buf, "w");
-               if(!zlist) {
-                       perror(buf);
-                       error_exit("cannot write zonelist file");
-               }
-               fprintf(zlist, "# partial zones at depth %d\n", d);
-               create_zones(data, d, zlist, data->root, 0);
-               fclose(zlist);
-               printf("creating zones %d - %d zones written\n", d,
-                       data->num_zones - lastzones);   
-       }
-}
-
-/** getopt global, in case header files fail to declare it. */
-extern int optind;
-/** getopt global, in case header files fail to declare it. */
-extern char* optarg;
-
-/** main program for harvest */
-int main(int argc, char* argv[]) 
-{
-       struct harvest_data data;
-       char* nm = argv[0];
-       int c;
-
-       /* defaults */
-       memset(&data, 0, sizeof(data));
-       data.ctx = ub_ctx_create();
-       data.resultdir = strdup("harvested_zones");
-       if(!data.resultdir) error_exit("out of memory");
-       data.maxdepth = 2;
-
-       /* parse the options */
-       while( (c=getopt(argc, argv, "hf:vC:")) != -1) {
-               switch(c) {
-               case 'C':
-                       if(ub_ctx_config(data.ctx, optarg) != 0)
-                               error_exit("config read failed");
-                       break;
-               case 'f':
-                       qlist_read_file(&data, optarg);
-                       break;
-               case 'v':
-                       hverb++;
-                       break;
-               case '?':
-               case 'h':
-               default:
-                       usage(nm);
-               }
-       }
-       argc -= optind;
-       argv += optind;
-       if(argc != 0)
-               usage(nm);
-       if(data.orig_list == NULL)
-               error_exit("No queries to make, use -f (help with -h).");
-       data.root = lab_create(".");
-       if(!data.root) error_exit("out of memory");
-       
-       /* harvest the data */
-       harvest_main(&data);
-       harvest_output(&data);
-
-       /* no cleanup except the context (to close open sockets) */
-       ub_ctx_delete(data.ctx);
-       return 0;
-}
diff --git a/testcode/ldns-testpkts.c b/testcode/ldns-testpkts.c
deleted file mode 100644 (file)
index be94eb2..0000000
+++ /dev/null
@@ -1,898 +0,0 @@
-/*
- * ldns-testpkts. Data file parse for test packets, and query matching.
- *
- * Data storage for specially crafted replies for testing purposes.
- *
- * (c) NLnet Labs, 2005, 2006, 2007, 2008
- * See the file LICENSE for the license
- */
-
-/**
- * \file
- * This is a debugging aid. It is not efficient, especially
- * with a long config file, but it can give any reply to any query.
- * This can help the developer pre-script replies for queries.
- *
- * You can specify a packet RR by RR with header flags to return.
- *
- * Missing features:
- *             - matching content different from reply content.
- *             - find way to adjust mangled packets?
- */
-
-#include "config.h"
-struct sockaddr_storage;
-#include <ldns/ldns.h>
-#include <errno.h>
-#include "ldns-testpkts.h"
-
-/** max line length */
-#define MAX_LINE   10240       
-/** string to show in warnings and errors */
-static const char* prog_name = "ldns-testpkts";
-
-#ifndef UTIL_LOG_H
-/** verbosity definition for compat */
-enum verbosity_value { NO_VERBOSE=0 };
-#endif
-/** logging routine, provided by caller */
-void verbose(enum verbosity_value lvl, const char* msg, ...) ATTR_FORMAT(printf, 2, 3);
-
-/** print error and exit */
-static void error(const char* msg, ...)
-{
-       va_list args;
-       va_start(args, msg);
-       fprintf(stderr, "%s error: ", prog_name);
-       vfprintf(stderr, msg, args);
-       fprintf(stderr, "\n");
-       fflush(stderr);
-       va_end(args);
-       exit(EXIT_FAILURE);
-}
-
-/** return if string is empty or comment */
-static bool isendline(char c)
-{
-       if(c == ';' || c == '#' 
-               || c == '\n' || c == 0)
-               return true;
-       return false;
-}
-
-/** true if the string starts with the keyword given. Moves the str ahead. 
- * @param str: before keyword, afterwards after keyword and spaces.
- * @param keyword: the keyword to match
- * @return: true if keyword present. False otherwise, and str unchanged.
-*/
-static bool str_keyword(char** str, const char* keyword)
-{
-       size_t len = strlen(keyword);
-       assert(str && keyword);
-       if(strncmp(*str, keyword, len) != 0)
-               return false;
-       *str += len;
-       while(isspace((int)**str))
-               (*str)++;
-       return true;
-}
-
-/** Add reply packet to entry */
-static struct reply_packet*
-entry_add_reply(struct entry* entry) 
-{
-       struct reply_packet* pkt = (struct reply_packet*)malloc(
-               sizeof(struct reply_packet));
-       struct reply_packet ** p = &entry->reply_list;
-       pkt->next = NULL;
-       pkt->packet_sleep = 0;
-       pkt->reply = ldns_pkt_new();
-       pkt->reply_from_hex = NULL;
-       /* link at end */
-       while(*p)
-               p = &((*p)->next);
-       *p = pkt;
-       return pkt;
-}
-
-/** parse MATCH line */
-static void matchline(char* line, struct entry* e)
-{
-       char* parse = line;
-       while(*parse) {
-               if(isendline(*parse)) 
-                       return;
-               if(str_keyword(&parse, "opcode")) {
-                       e->match_opcode = true;
-               } else if(str_keyword(&parse, "qtype")) {
-                       e->match_qtype = true;
-               } else if(str_keyword(&parse, "qname")) {
-                       e->match_qname = true;
-               } else if(str_keyword(&parse, "subdomain")) {
-                       e->match_subdomain = true;
-               } else if(str_keyword(&parse, "all")) {
-                       e->match_all = true;
-               } else if(str_keyword(&parse, "ttl")) {
-                       e->match_ttl = true;
-               } else if(str_keyword(&parse, "DO")) {
-                       e->match_do = true;
-               } else if(str_keyword(&parse, "noedns")) {
-                       e->match_noedns = true;
-               } else if(str_keyword(&parse, "UDP")) {
-                       e->match_transport = transport_udp;
-               } else if(str_keyword(&parse, "TCP")) {
-                       e->match_transport = transport_tcp;
-               } else if(str_keyword(&parse, "serial")) {
-                       e->match_serial = true;
-                       if(*parse != '=' && *parse != ':')
-                               error("expected = or : in MATCH: %s", line);
-                       parse++;
-                       e->ixfr_soa_serial = (uint32_t)strtol(parse, (char**)&parse, 10);
-                       while(isspace((int)*parse)) 
-                               parse++;
-               } else {
-                       error("could not parse MATCH: '%s'", parse);
-               }
-       }
-}
-
-/** parse REPLY line */
-static void replyline(char* line, ldns_pkt *reply)
-{
-       char* parse = line;
-       while(*parse) {
-               if(isendline(*parse)) 
-                       return;
-                       /* opcodes */
-               if(str_keyword(&parse, "QUERY")) {
-                       ldns_pkt_set_opcode(reply, LDNS_PACKET_QUERY);
-               } else if(str_keyword(&parse, "IQUERY")) {
-                       ldns_pkt_set_opcode(reply, LDNS_PACKET_IQUERY);
-               } else if(str_keyword(&parse, "STATUS")) {
-                       ldns_pkt_set_opcode(reply, LDNS_PACKET_STATUS);
-               } else if(str_keyword(&parse, "NOTIFY")) {
-                       ldns_pkt_set_opcode(reply, LDNS_PACKET_NOTIFY);
-               } else if(str_keyword(&parse, "UPDATE")) {
-                       ldns_pkt_set_opcode(reply, LDNS_PACKET_UPDATE);
-                       /* rcodes */
-               } else if(str_keyword(&parse, "NOERROR")) {
-                       ldns_pkt_set_rcode(reply, LDNS_RCODE_NOERROR);
-               } else if(str_keyword(&parse, "FORMERR")) {
-                       ldns_pkt_set_rcode(reply, LDNS_RCODE_FORMERR);
-               } else if(str_keyword(&parse, "SERVFAIL")) {
-                       ldns_pkt_set_rcode(reply, LDNS_RCODE_SERVFAIL);
-               } else if(str_keyword(&parse, "NXDOMAIN")) {
-                       ldns_pkt_set_rcode(reply, LDNS_RCODE_NXDOMAIN);
-               } else if(str_keyword(&parse, "NOTIMPL")) {
-                       ldns_pkt_set_rcode(reply, LDNS_RCODE_NOTIMPL);
-               } else if(str_keyword(&parse, "REFUSED")) {
-                       ldns_pkt_set_rcode(reply, LDNS_RCODE_REFUSED);
-               } else if(str_keyword(&parse, "YXDOMAIN")) {
-                       ldns_pkt_set_rcode(reply, LDNS_RCODE_YXDOMAIN);
-               } else if(str_keyword(&parse, "YXRRSET")) {
-                       ldns_pkt_set_rcode(reply, LDNS_RCODE_YXRRSET);
-               } else if(str_keyword(&parse, "NXRRSET")) {
-                       ldns_pkt_set_rcode(reply, LDNS_RCODE_NXRRSET);
-               } else if(str_keyword(&parse, "NOTAUTH")) {
-                       ldns_pkt_set_rcode(reply, LDNS_RCODE_NOTAUTH);
-               } else if(str_keyword(&parse, "NOTZONE")) {
-                       ldns_pkt_set_rcode(reply, LDNS_RCODE_NOTZONE);
-                       /* flags */
-               } else if(str_keyword(&parse, "QR")) {
-                       ldns_pkt_set_qr(reply, true);
-               } else if(str_keyword(&parse, "AA")) {
-                       ldns_pkt_set_aa(reply, true);
-               } else if(str_keyword(&parse, "TC")) {
-                       ldns_pkt_set_tc(reply, true);
-               } else if(str_keyword(&parse, "RD")) {
-                       ldns_pkt_set_rd(reply, true);
-               } else if(str_keyword(&parse, "CD")) {
-                       ldns_pkt_set_cd(reply, true);
-               } else if(str_keyword(&parse, "RA")) {
-                       ldns_pkt_set_ra(reply, true);
-               } else if(str_keyword(&parse, "AD")) {
-                       ldns_pkt_set_ad(reply, true);
-               } else if(str_keyword(&parse, "DO")) {
-                       ldns_pkt_set_edns_udp_size(reply, 4096);
-                       ldns_pkt_set_edns_do(reply, true);
-               } else {
-                       error("could not parse REPLY: '%s'", parse);
-               }
-       }
-}
-
-/** parse ADJUST line */
-static void adjustline(char* line, struct entry* e, 
-       struct reply_packet* pkt)
-{
-       char* parse = line;
-       while(*parse) {
-               if(isendline(*parse)) 
-                       return;
-               if(str_keyword(&parse, "copy_id")) {
-                       e->copy_id = true;
-               } else if(str_keyword(&parse, "copy_query")) {
-                       e->copy_query = true;
-               } else if(str_keyword(&parse, "sleep=")) {
-                       e->sleeptime = (unsigned int) strtol(parse, (char**)&parse, 10);
-                       while(isspace((int)*parse)) 
-                               parse++;
-               } else if(str_keyword(&parse, "packet_sleep=")) {
-                       pkt->packet_sleep = (unsigned int) strtol(parse, (char**)&parse, 10);
-                       while(isspace((int)*parse)) 
-                               parse++;
-               } else {
-                       error("could not parse ADJUST: '%s'", parse);
-               }
-       }
-}
-
-/** create new entry */
-static struct entry* new_entry()
-{
-       struct entry* e = LDNS_MALLOC(struct entry);
-       memset(e, 0, sizeof(*e));
-       e->match_opcode = false;
-       e->match_qtype = false;
-       e->match_qname = false;
-       e->match_subdomain = false;
-       e->match_all = false;
-       e->match_ttl = false;
-       e->match_do = false;
-       e->match_noedns = false;
-       e->match_serial = false;
-       e->ixfr_soa_serial = 0;
-       e->match_transport = transport_any;
-       e->reply_list = NULL;
-       e->copy_id = false;
-       e->copy_query = false;
-       e->sleeptime = 0;
-       e->next = NULL;
-       return e;
-}
-
-/**
- * Converts a hex string to binary data
- * @param hexstr: string of hex.
- * @param len: is the length of the string
- * @param buf: is the buffer to store the result in
- * @param offset: is the starting position in the result buffer
- * @param buf_len: is the length of buf.
- * @return This function returns the length of the result
- */
-static size_t
-hexstr2bin(char *hexstr, int len, uint8_t *buf, size_t offset, size_t buf_len)
-{
-       char c;
-       int i; 
-       uint8_t int8 = 0;
-       int sec = 0;
-       size_t bufpos = 0;
-       
-       if (len % 2 != 0) {
-               return 0;
-       }
-
-       for (i=0; i<len; i++) {
-               c = hexstr[i];
-
-               /* case insensitive, skip spaces */
-               if (c != ' ') {
-                       if (c >= '0' && c <= '9') {
-                               int8 += c & 0x0f;  
-                       } else if (c >= 'a' && c <= 'z') {
-                               int8 += (c & 0x0f) + 9;   
-                       } else if (c >= 'A' && c <= 'Z') {
-                               int8 += (c & 0x0f) + 9;   
-                       } else {
-                               return 0;
-                       }
-                        
-                       if (sec == 0) {
-                               int8 = int8 << 4;
-                               sec = 1;
-                       } else {
-                               if (bufpos + offset + 1 <= buf_len) {
-                                       buf[bufpos+offset] = int8;
-                                       int8 = 0;
-                                       sec = 0; 
-                                       bufpos++;
-                               } else {
-                                       fprintf(stderr, "Buffer too small in hexstr2bin");
-                               }
-                       }
-               }
-        }
-        return bufpos;
-}
-
-/** convert hex buffer to binary buffer */
-static ldns_buffer *
-data_buffer2wire(ldns_buffer *data_buffer)
-{
-       ldns_buffer *wire_buffer = NULL;
-       int c;
-       
-       /* stat hack
-        * 0 = normal
-        * 1 = comment (skip to end of line)
-        * 2 = unprintable character found, read binary data directly
-        */
-       size_t data_buf_pos = 0;
-       int state = 0;
-       uint8_t *hexbuf;
-       int hexbufpos = 0;
-       size_t wirelen;
-       uint8_t *data_wire = (uint8_t *) ldns_buffer_begin(data_buffer);
-       uint8_t *wire = LDNS_XMALLOC(uint8_t, LDNS_MAX_PACKETLEN);
-       
-       hexbuf = LDNS_XMALLOC(uint8_t, LDNS_MAX_PACKETLEN);
-       for (data_buf_pos = 0; data_buf_pos < ldns_buffer_position(data_buffer); data_buf_pos++) {
-               c = (int) data_wire[data_buf_pos];
-               
-               if (state < 2 && !isascii(c)) {
-                       /*verbose("non ascii character found in file: (%d) switching to raw mode\n", c);*/
-                       state = 2;
-               }
-               switch (state) {
-                       case 0:
-                               if (    (c >= '0' && c <= '9') ||
-                                       (c >= 'a' && c <= 'f') ||
-                                       (c >= 'A' && c <= 'F') )
-                               {
-                                       if (hexbufpos >= LDNS_MAX_PACKETLEN) {
-                                               error("buffer overflow");
-                                               LDNS_FREE(hexbuf);
-                                               return 0;
-
-                                       }
-                                       hexbuf[hexbufpos] = (uint8_t) c;
-                                       hexbufpos++;
-                               } else if (c == ';') {
-                                       state = 1;
-                               } else if (c == ' ' || c == '\t' || c == '\n') {
-                                       /* skip whitespace */
-                               } 
-                               break;
-                       case 1:
-                               if (c == '\n' || c == EOF) {
-                                       state = 0;
-                               }
-                               break;
-                       case 2:
-                               if (hexbufpos >= LDNS_MAX_PACKETLEN) {
-                                       error("buffer overflow");
-                                       LDNS_FREE(hexbuf);
-                                       return 0;
-                               }
-                               hexbuf[hexbufpos] = (uint8_t) c;
-                               hexbufpos++;
-                               break;
-               }
-       }
-
-       if (hexbufpos >= LDNS_MAX_PACKETLEN) {
-               /*verbose("packet size reached\n");*/
-       }
-       
-       /* lenient mode: length must be multiple of 2 */
-       if (hexbufpos % 2 != 0) {
-               if (hexbufpos >= LDNS_MAX_PACKETLEN) {
-                       error("buffer overflow");
-                       LDNS_FREE(hexbuf);
-                       return 0;
-               }
-               hexbuf[hexbufpos] = (uint8_t) '0';
-               hexbufpos++;
-       }
-
-       if (state < 2) {
-               wirelen = hexstr2bin((char *) hexbuf, hexbufpos, wire, 0, LDNS_MAX_PACKETLEN);
-               wire_buffer = ldns_buffer_new(wirelen);
-               ldns_buffer_new_frm_data(wire_buffer, wire, wirelen);
-       } else {
-               error("Incomplete hex data, not at byte boundary\n");
-       }
-       LDNS_FREE(wire);
-       LDNS_FREE(hexbuf);
-       return wire_buffer;
-}      
-
-/** parse ORIGIN */
-static void 
-get_origin(const char* name, int lineno, ldns_rdf** origin, char* parse)
-{
-       /* snip off rest of the text so as to make the parse work in ldns */
-       char* end;
-       char store;
-       ldns_status status;
-
-       ldns_rdf_free(*origin);
-       *origin = NULL;
-
-       end=parse;
-       while(!isspace((int)*end) && !isendline(*end))
-               end++;
-       store = *end;
-       *end = 0;
-       verbose(3, "parsing '%s'\n", parse);
-       status = ldns_str2rdf_dname(origin, parse);
-       *end = store;
-       if (status != LDNS_STATUS_OK)
-               error("%s line %d:\n\t%s: %s", name, lineno,
-               ldns_get_errorstr_by_id(status), parse);
-}
-
-/* Reads one entry from file. Returns entry or NULL on error. */
-struct entry*
-read_entry(FILE* in, const char* name, int *lineno, uint32_t* default_ttl, 
-       ldns_rdf** origin, ldns_rdf** prev_rr, int skip_whitespace)
-{
-       struct entry* current = NULL;
-       char line[MAX_LINE];
-       char* parse;
-       ldns_pkt_section add_section = LDNS_SECTION_QUESTION;
-       struct reply_packet *cur_reply = NULL;
-       bool reading_hex = false;
-       ldns_buffer* hex_data_buffer = NULL;
-
-       while(fgets(line, (int)sizeof(line), in) != NULL) {
-               line[MAX_LINE-1] = 0;
-               parse = line;
-               (*lineno) ++;
-               
-               while(isspace((int)*parse))
-                       parse++;
-               /* test for keywords */
-               if(isendline(*parse))
-                       continue; /* skip comment and empty lines */
-               if(str_keyword(&parse, "ENTRY_BEGIN")) {
-                       if(current) {
-                               error("%s line %d: previous entry does not ENTRY_END", 
-                                       name, *lineno);
-                       }
-                       current = new_entry();
-                       current->lineno = *lineno;
-                       cur_reply = entry_add_reply(current);
-                       continue;
-               } else if(str_keyword(&parse, "$ORIGIN")) {
-                       get_origin(name, *lineno, origin, parse);
-                       continue;
-               } else if(str_keyword(&parse, "$TTL")) {
-                       *default_ttl = (uint32_t)atoi(parse);
-                       continue;
-               }
-
-               /* working inside an entry */
-               if(!current) {
-                       error("%s line %d: expected ENTRY_BEGIN but got %s", 
-                               name, *lineno, line);
-               }
-               if(str_keyword(&parse, "MATCH")) {
-                       matchline(parse, current);
-               } else if(str_keyword(&parse, "REPLY")) {
-                       replyline(parse, cur_reply->reply);
-               } else if(str_keyword(&parse, "ADJUST")) {
-                       adjustline(parse, current, cur_reply);
-               } else if(str_keyword(&parse, "EXTRA_PACKET")) {
-                       cur_reply = entry_add_reply(current);
-               } else if(str_keyword(&parse, "SECTION")) {
-                       if(str_keyword(&parse, "QUESTION"))
-                               add_section = LDNS_SECTION_QUESTION;
-                       else if(str_keyword(&parse, "ANSWER"))
-                               add_section = LDNS_SECTION_ANSWER;
-                       else if(str_keyword(&parse, "AUTHORITY"))
-                               add_section = LDNS_SECTION_AUTHORITY;
-                       else if(str_keyword(&parse, "ADDITIONAL"))
-                               add_section = LDNS_SECTION_ADDITIONAL;
-                       else error("%s line %d: bad section %s", name, *lineno, parse);
-               } else if(str_keyword(&parse, "HEX_ANSWER_BEGIN")) {
-                       hex_data_buffer = ldns_buffer_new(LDNS_MAX_PACKETLEN);
-                       reading_hex = true;
-               } else if(str_keyword(&parse, "HEX_ANSWER_END")) {
-                       if (!reading_hex) {
-                               error("%s line %d: HEX_ANSWER_END read but no HEX_ANSWER_BEGIN keyword seen", name, *lineno);
-                       }
-                       reading_hex = false;
-                       cur_reply->reply_from_hex = data_buffer2wire(hex_data_buffer);
-                       ldns_buffer_free(hex_data_buffer);
-                       hex_data_buffer = NULL;
-               } else if(str_keyword(&parse, "ENTRY_END")) {
-                       if (hex_data_buffer)
-                               ldns_buffer_free(hex_data_buffer);
-                       return current;
-               } else if(reading_hex) {
-                       ldns_buffer_printf(hex_data_buffer, line);
-               } else {
-                       /* it must be a RR, parse and add to packet. */
-                       ldns_rr* n = NULL;
-                       ldns_status status;
-                       char* rrstr = line;
-                       if (skip_whitespace)
-                               rrstr = parse;
-                       if(add_section == LDNS_SECTION_QUESTION)
-                               status = ldns_rr_new_question_frm_str(
-                                       &n, rrstr, *origin, prev_rr);
-                       else status = ldns_rr_new_frm_str(&n, rrstr,
-                               *default_ttl, *origin, prev_rr);
-                       if(status != LDNS_STATUS_OK)
-                               error("%s line %d:\n\t%s: %s", name, *lineno,
-                                       ldns_get_errorstr_by_id(status), rrstr);
-                       ldns_pkt_push_rr(cur_reply->reply, add_section, n);
-               }
-
-       }
-       if (reading_hex) {
-               error("%s: End of file reached while still reading hex, "
-                       "missing HEX_ANSWER_END\n", name);
-       }
-       if(current) {
-               error("%s: End of file reached while reading entry. "
-                       "missing ENTRY_END\n", name);
-       }
-       return 0;
-}
-
-/* reads the canned reply file and returns a list of structs */
-struct entry* 
-read_datafile(const char* name, int skip_whitespace)
-{
-       struct entry* list = NULL;
-       struct entry* last = NULL;
-       struct entry* current = NULL;
-       FILE *in;
-       int lineno = 0;
-       uint32_t default_ttl = 0;
-       ldns_rdf* origin = NULL;
-       ldns_rdf* prev_rr = NULL;
-       int entry_num = 0;
-
-       if((in=fopen(name, "r")) == NULL) {
-               error("could not open file %s: %s", name, strerror(errno));
-       }
-
-       while((current = read_entry(in, name, &lineno, &default_ttl, 
-               &origin, &prev_rr, skip_whitespace)))
-       {
-               if(last)
-                       last->next = current;
-               else    list = current;
-               last = current;
-               entry_num ++;
-       }
-       verbose(1, "%s: Read %d entries\n", prog_name, entry_num);
-
-       fclose(in);
-       ldns_rdf_deep_free(origin);
-       ldns_rdf_deep_free(prev_rr);
-       return list;
-}
-
-/** get qtype from rr */
-static ldns_rr_type get_qtype(ldns_pkt* p)
-{
-       if(!ldns_rr_list_rr(ldns_pkt_question(p), 0))
-               return 0;
-       return ldns_rr_get_type(ldns_rr_list_rr(ldns_pkt_question(p), 0));
-}
-
-/** returns owner from rr */
-static ldns_rdf* get_owner(ldns_pkt* p)
-{
-       if(!ldns_rr_list_rr(ldns_pkt_question(p), 0))
-               return NULL;
-       return ldns_rr_owner(ldns_rr_list_rr(ldns_pkt_question(p), 0));
-}
-
-/** get authority section SOA serial value */
-static uint32_t get_serial(ldns_pkt* p)
-{
-       ldns_rr *rr = ldns_rr_list_rr(ldns_pkt_authority(p), 0);
-       ldns_rdf *rdf;
-       uint32_t val;
-       if(!rr) return 0;
-       rdf = ldns_rr_rdf(rr, 2);
-       if(!rdf) return 0;
-       val = ldns_rdf2native_int32(rdf);
-       verbose(3, "found serial %u in msg. ", (int)val);
-       return val;
-}
-
-/** match two rr lists */
-static int
-match_list(ldns_rr_list* q, ldns_rr_list *p, bool mttl)
-{
-       size_t i;
-       if(ldns_rr_list_rr_count(q) != ldns_rr_list_rr_count(p))
-               return 0;
-       for(i=0; i<ldns_rr_list_rr_count(q); i++)
-       {
-               if(ldns_rr_compare(ldns_rr_list_rr(q, i), 
-                       ldns_rr_list_rr(p, i)) != 0) {
-                       verbose(3, "rr %d different", (int)i);
-                       return 0;
-               }
-               if(mttl && ldns_rr_ttl(ldns_rr_list_rr(q, i)) !=
-                       ldns_rr_ttl(ldns_rr_list_rr(p, i))) {
-                       verbose(3, "rr %d ttl different", (int)i);
-                       return 0;
-               }
-       }
-       return 1;
-}
-
-/** compare two booleans */
-static int
-cmp_bool(int x, int y)
-{
-       if(!x && !y) return 0;
-       if(x && y) return 0;
-       if(!x) return -1;
-       return 1;
-}
-
-/** match all of the packet */
-static int
-match_all(ldns_pkt* q, ldns_pkt* p, bool mttl)
-{
-       if(ldns_pkt_get_opcode(q) != ldns_pkt_get_opcode(p)) 
-       { verbose(3, "allmatch: opcode different"); return 0;}
-       if(ldns_pkt_get_rcode(q) != ldns_pkt_get_rcode(p))
-       { verbose(3, "allmatch: rcode different"); return 0;}
-       if(ldns_pkt_id(q) != ldns_pkt_id(p))
-       { verbose(3, "allmatch: id different"); return 0;}
-       if(cmp_bool(ldns_pkt_qr(q), ldns_pkt_qr(p)) != 0)
-       { verbose(3, "allmatch: qr different"); return 0;}
-       if(cmp_bool(ldns_pkt_aa(q), ldns_pkt_aa(p)) != 0)
-       { verbose(3, "allmatch: aa different"); return 0;}
-       if(cmp_bool(ldns_pkt_tc(q), ldns_pkt_tc(p)) != 0)
-       { verbose(3, "allmatch: tc different"); return 0;}
-       if(cmp_bool(ldns_pkt_rd(q), ldns_pkt_rd(p)) != 0)
-       { verbose(3, "allmatch: rd different"); return 0;}
-       if(cmp_bool(ldns_pkt_cd(q), ldns_pkt_cd(p)) != 0)
-       { verbose(3, "allmatch: cd different"); return 0;}
-       if(cmp_bool(ldns_pkt_ra(q), ldns_pkt_ra(p)) != 0)
-       { verbose(3, "allmatch: ra different"); return 0;}
-       if(cmp_bool(ldns_pkt_ad(q), ldns_pkt_ad(p)) != 0)
-       { verbose(3, "allmatch: ad different"); return 0;}
-       if(ldns_pkt_qdcount(q) != ldns_pkt_qdcount(p))
-       { verbose(3, "allmatch: qdcount different"); return 0;}
-       if(ldns_pkt_ancount(q) != ldns_pkt_ancount(p))
-       { verbose(3, "allmatch: ancount different"); return 0;}
-       if(ldns_pkt_nscount(q) != ldns_pkt_nscount(p))
-       { verbose(3, "allmatch: nscount different"); return 0;}
-       if(ldns_pkt_arcount(q) != ldns_pkt_arcount(p))
-       { verbose(3, "allmatch: arcount different"); return 0;}
-       if(!match_list(ldns_pkt_question(q), ldns_pkt_question(p), 0))
-       { verbose(3, "allmatch: qd section different"); return 0;}
-       if(!match_list(ldns_pkt_answer(q), ldns_pkt_answer(p), mttl))
-       { verbose(3, "allmatch: an section different"); return 0;}
-       if(!match_list(ldns_pkt_authority(q), ldns_pkt_authority(p), mttl))
-       { verbose(3, "allmatch: ar section different"); return 0;}
-       if(!match_list(ldns_pkt_additional(q), ldns_pkt_additional(p), mttl)) 
-       { verbose(3, "allmatch: ns section different"); return 0;}
-       return 1;
-}
-
-/* finds entry in list, or returns NULL */
-struct entry* 
-find_match(struct entry* entries, ldns_pkt* query_pkt,
-       enum transport_type transport)
-{
-       struct entry* p = entries;
-       ldns_pkt* reply = NULL;
-       for(p=entries; p; p=p->next) {
-               verbose(3, "comparepkt: ");
-               reply = p->reply_list->reply;
-               if(p->match_opcode && ldns_pkt_get_opcode(query_pkt) != 
-                       ldns_pkt_get_opcode(reply)) {
-                       verbose(3, "bad opcode\n");
-                       continue;
-               }
-               if(p->match_qtype && get_qtype(query_pkt) != get_qtype(reply)) {
-                       verbose(3, "bad qtype\n");
-                       continue;
-               }
-               if(p->match_qname) {
-                       if(!get_owner(query_pkt) || !get_owner(reply) ||
-                               ldns_dname_compare(
-                               get_owner(query_pkt), get_owner(reply)) != 0) {
-                               verbose(3, "bad qname\n");
-                               continue;
-                       }
-               }
-               if(p->match_subdomain) {
-                       if(!get_owner(query_pkt) || !get_owner(reply) ||
-                               (ldns_dname_compare(get_owner(query_pkt), 
-                               get_owner(reply)) != 0 &&
-                               !ldns_dname_is_subdomain(
-                               get_owner(query_pkt), get_owner(reply))))
-                       {
-                               verbose(3, "bad subdomain\n");
-                               continue;
-                       }
-               }
-               if(p->match_serial && get_serial(query_pkt) != p->ixfr_soa_serial) {
-                               verbose(3, "bad serial\n");
-                               continue;
-               }
-               if(p->match_do && !ldns_pkt_edns_do(query_pkt)) {
-                       verbose(3, "no DO bit set\n");
-                       continue;
-               }
-               if(p->match_noedns && ldns_pkt_edns(query_pkt)) {
-                       verbose(3, "bad; EDNS OPT present\n");
-                       continue;
-               }
-               if(p->match_transport != transport_any && p->match_transport != transport) {
-                       verbose(3, "bad transport\n");
-                       continue;
-               }
-               if(p->match_all && !match_all(query_pkt, reply, p->match_ttl)) {
-                       verbose(3, "bad allmatch\n");
-                       continue;
-               }
-               verbose(3, "match!\n");
-               return p;
-       }
-       return NULL;
-}
-
-void
-adjust_packet(struct entry* match, ldns_pkt* answer_pkt, ldns_pkt* query_pkt)
-{
-       /* copy & adjust packet */
-       if(match->copy_id)
-               ldns_pkt_set_id(answer_pkt, ldns_pkt_id(query_pkt));
-       if(match->copy_query) {
-               ldns_rr_list* list = ldns_pkt_get_section_clone(query_pkt,
-                       LDNS_SECTION_QUESTION);
-               ldns_rr_list_deep_free(ldns_pkt_question(answer_pkt));
-               ldns_pkt_set_question(answer_pkt, list);
-       }
-       if(match->sleeptime > 0) {
-               verbose(3, "sleeping for %d seconds\n", match->sleeptime);
-#ifdef HAVE_SLEEP
-               sleep(match->sleeptime);
-#else
-               Sleep(match->sleeptime * 1000);
-#endif
-       }
-}
-
-/*
- * Parses data buffer to a query, finds the correct answer 
- * and calls the given function for every packet to send.
- */
-void
-handle_query(uint8_t* inbuf, ssize_t inlen, struct entry* entries, int* count,
-       enum transport_type transport, void (*sendfunc)(uint8_t*, size_t, void*),
-       void* userdata, FILE* verbose_out)
-{
-       ldns_status status;
-       ldns_pkt *query_pkt = NULL;
-       ldns_pkt *answer_pkt = NULL;
-       struct reply_packet *p;
-       ldns_rr *query_rr = NULL;
-       uint8_t *outbuf = NULL;
-       size_t answer_size = 0;
-       struct entry* entry = NULL;
-       ldns_rdf *stop_command = ldns_dname_new_frm_str("server.stop.");
-
-       status = ldns_wire2pkt(&query_pkt, inbuf, (size_t)inlen);
-       if (status != LDNS_STATUS_OK) {
-               verbose(1, "Got bad packet: %s\n", ldns_get_errorstr_by_id(status));
-               ldns_rdf_free(stop_command);
-               return;
-       }
-       
-       query_rr = ldns_rr_list_rr(ldns_pkt_question(query_pkt), 0);
-       verbose(1, "query %d: id %d: %s %d bytes: ", ++(*count), (int)ldns_pkt_id(query_pkt), 
-               (transport==transport_tcp)?"TCP":"UDP", (int)inlen);
-       if(verbose_out) ldns_rr_print(verbose_out, query_rr);
-       if(verbose_out) ldns_pkt_print(verbose_out, query_pkt);
-
-       if (ldns_rr_get_type(query_rr) == LDNS_RR_TYPE_TXT &&
-           ldns_rr_get_class(query_rr) == LDNS_RR_CLASS_CH &&
-           ldns_dname_compare(ldns_rr_owner(query_rr), stop_command) == 0) {
-               exit(0);
-        }
-       
-       /* fill up answer packet */
-       entry = find_match(entries, query_pkt, transport);
-       if(!entry || !entry->reply_list) {
-               verbose(1, "no answer packet for this query, no reply.\n");
-               ldns_pkt_free(query_pkt);
-               ldns_rdf_free(stop_command);
-               return;
-       }
-       for(p = entry->reply_list; p; p = p->next)
-       {
-               verbose(3, "Answer pkt:\n");
-               if (p->reply_from_hex) {
-                       /* try to parse the hex packet, if it can be
-                        * parsed, we can use adjust rules. if not,
-                        * send packet literally */
-                       status = ldns_buffer2pkt_wire(&answer_pkt, p->reply_from_hex);
-                       if (status == LDNS_STATUS_OK) {
-                               adjust_packet(entry, answer_pkt, query_pkt);
-                               if(verbose_out) ldns_pkt_print(verbose_out, answer_pkt);
-                               status = ldns_pkt2wire(&outbuf, answer_pkt, &answer_size);
-                               verbose(2, "Answer packet size: %u bytes.\n", (unsigned int)answer_size);
-                               if (status != LDNS_STATUS_OK) {
-                                       verbose(1, "Error creating answer: %s\n", ldns_get_errorstr_by_id(status));
-                                       ldns_pkt_free(query_pkt);
-                                       ldns_rdf_free(stop_command);
-                                       return;
-                               }
-                               ldns_pkt_free(answer_pkt);
-                               answer_pkt = NULL;
-                       } else {
-                               verbose(3, "Could not parse hex data (%s), sending hex data directly.\n", ldns_get_errorstr_by_id(status));
-                               /* still try to adjust ID */
-                               answer_size = ldns_buffer_capacity(p->reply_from_hex);
-                               outbuf = LDNS_XMALLOC(uint8_t, answer_size);
-                               memcpy(outbuf, ldns_buffer_begin(p->reply_from_hex), answer_size);
-                               if(entry->copy_id) {
-                                       ldns_write_uint16(outbuf, 
-                                               ldns_pkt_id(query_pkt));
-                               }
-                       }
-               } else {
-                       answer_pkt = ldns_pkt_clone(p->reply);
-                       adjust_packet(entry, answer_pkt, query_pkt);
-                       if(verbose_out) ldns_pkt_print(verbose_out, answer_pkt);
-                       status = ldns_pkt2wire(&outbuf, answer_pkt, &answer_size);
-                       verbose(1, "Answer packet size: %u bytes.\n", (unsigned int)answer_size);
-                       if (status != LDNS_STATUS_OK) {
-                               verbose(1, "Error creating answer: %s\n", ldns_get_errorstr_by_id(status));
-                               ldns_pkt_free(query_pkt);
-                               ldns_rdf_free(stop_command);
-                               return;
-                       }
-                       ldns_pkt_free(answer_pkt);
-                       answer_pkt = NULL;
-               }
-               if(p->packet_sleep) {
-                       verbose(3, "sleeping for next packet %d secs\n", 
-                               p->packet_sleep);
-#ifdef HAVE_SLEEP
-                       sleep(p->packet_sleep);
-#else
-                       Sleep(p->packet_sleep * 1000);
-#endif
-                       verbose(3, "wakeup for next packet "
-                               "(slept %d secs)\n", p->packet_sleep);
-               }
-               sendfunc(outbuf, answer_size, userdata);
-               LDNS_FREE(outbuf);
-               outbuf = NULL;
-               answer_size = 0;
-       }
-       ldns_pkt_free(query_pkt);
-       ldns_rdf_free(stop_command);
-}
-
-/** delete the list of reply packets */
-void delete_replylist(struct reply_packet* replist)
-{
-       struct reply_packet *p=replist, *np;
-       while(p) {
-               np = p->next;
-               ldns_pkt_free(p->reply);
-               ldns_buffer_free(p->reply_from_hex);
-               free(p);
-               p=np;
-       }
-}
-
-void delete_entry(struct entry* list)
-{
-       struct entry *p=list, *np;
-       while(p) {
-               np = p->next;
-               delete_replylist(p->reply_list);
-               free(p);
-               p = np;
-       }
-}
index cc892efa99fa74a8a5924a7f9e3292b2fb1cf3e1..19ce205093afd29fca9b7116cf279047a38b55a7 100644 (file)
@@ -43,7 +43,6 @@
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #endif
-#include <ldns/ldns.h>
 #include <signal.h>
 #include "util/log.h"
 #include "util/locks.h"
 #include "util/data/msgencode.h"
 #include "util/data/msgreply.h"
 #include "util/data/msgparse.h"
+#include "ldns/sbuffer.h"
+#include "ldns/wire2str.h"
+#include "ldns/str2wire.h"
+#include <sys/time.h>
 
 /** usage information for perf */
 static void usage(char* nm) 
@@ -434,11 +437,10 @@ perfendstats(struct perfinfo* info)
                for(i=0; i<(int)(sizeof(info->by_rcode)/sizeof(size_t)); i++)
                {
                        if(info->by_rcode[i] > 0) {
+                               char rc[16];
+                               ldns_wire2str_rcode_buf(i, rc, sizeof(rc));
                                printf("%d(%5s):        %u replies\n",
-                                       i, ldns_lookup_by_id(ldns_rcodes, i)?
-                                       ldns_lookup_by_id(ldns_rcodes, 
-                                       i)->name:"??", 
-                                       (unsigned)info->by_rcode[i]);
+                                       i, rc, (unsigned)info->by_rcode[i]);
                        }
                }
        }
@@ -465,7 +467,6 @@ qlist_parse_line(ldns_buffer* buf, char* p)
        int r; 
        int rec = 1, edns = 0;
        struct query_info qinfo;
-       ldns_rdf* rdf;
        nm[0] = 0; cl[0] = 0; tp[0] = 0; fl[0] = 0;
        r = sscanf(p, " %1023s %1023s %1023s %1023s", nm, cl, tp, fl);
        if(r != 3 && r != 4)
@@ -483,11 +484,9 @@ qlist_parse_line(ldns_buffer* buf, char* p)
        else if(fl[0] == 'E') edns = 1;
        if((fl[0] == '+' || fl[0] == '-') && fl[1] == 'E')
                edns = 1;
-       rdf = ldns_dname_new_frm_str(nm);
-       if(!rdf)
+       qinfo.qname = ldns_str2wire_dname(nm, &qinfo.qname_len);
+       if(!qinfo.qname)
                return 0;
-       qinfo.qname = ldns_rdf_data(rdf);
-       qinfo.qname_len = ldns_rdf_size(rdf);
        qinfo_query_encode(buf, &qinfo);
        ldns_buffer_write_u16_at(buf, 0, 0); /* zero ID */
        if(rec) LDNS_RD_SET(ldns_buffer_begin(buf));
@@ -500,7 +499,7 @@ qlist_parse_line(ldns_buffer* buf, char* p)
                ed.bits = EDNS_DO;
                attach_edns_record(buf, &ed);
        }
-       ldns_rdf_deep_free(rdf);
+       free(qinfo.qname);
        return 1;
 }
 
index 3cbdfc39581057e0acc7ff4cbc4e31b93b0eefe2..d9895856d93f6f14d6f1faa801f91b08b4db2da2 100644 (file)
  */
 
 #include "config.h"
-#include <ldns/ldns.h>
 #include "util/log.h"
 #include "util/data/dname.h"
 #include "util/data/msgparse.h"
 #include "testcode/unitmain.h"
 #include "testcode/readhex.h"
+#include "ldns/sbuffer.h"
+#include "ldns/parseutil.h"
 
 /** usage information for pktview */
 static void usage(char* argv[])
index f212ddd747c846770a38247037c121a365859f4a..886920a912e5d370363e374f606718de36b79bad 100644 (file)
@@ -41,6 +41,8 @@
 #include <ctype.h>
 #include "testcode/readhex.h"
 #include "util/log.h"
+#include "ldns/sbuffer.h"
+#include "ldns/parseutil.h"
 
 /** skip whitespace */
 static void
index 5ae3f4dbd510e1652765b758dafd0033fde6fbaa..eb053d26f82bb06aa3b563975ba5b6966f6ebec9 100644 (file)
 
 #ifndef TESTCODE_READHEX_H
 #define TESTCODE_READHEX_H
-#include <ldns/buffer.h>
+struct ldns_buffer;
 
 /** 
  * Helper to convert hex string to packet buffer.
  * @param pkt: buffer to put result in.
  * @param hex: string of hex data. Spaces and ';...' comments are skipped.
  */
-void hex_to_buf(ldns_buffer* pkt, const char* hex);
+void hex_to_buf(struct ldns_buffer* pkt, const char* hex);
 
 #endif /* TESTCODE_READHEX_H */
index ce050ed0ad15cbb993a113b094aca613c43b856a..b589e1347618bf292cebf329bd9ecf1c625e397a 100644 (file)
 #include "config.h"
 /* for strtod prototype */
 #include <math.h>
+#include <ctype.h>
+#include <time.h>
 #include "util/log.h"
 #include "util/net_help.h"
 #include "util/config_file.h"
 #include "testcode/replay.h"
-#include "testcode/ldns-testpkts.h"
+#include "testcode/testpkts.h"
 #include "testcode/fake_event.h"
+#include "ldns/str2wire.h"
 
 /** max length of lines in file */
 #define MAX_LINE_LEN 10240
@@ -138,16 +141,15 @@ strip_end_white(char* p)
  * @param remain: Rest of line (after RANGE keyword).
  * @param in: file to read from.
  * @param name: name to print in errors.
- * @param lineno: incremented as lines are read.
+ * @param pstate: read state structure with
+ *     with lineno : incremented as lines are read.
+ *     ttl, origin, prev for readentry.
  * @param line: line buffer.
- * @param ttl: for readentry
- * @param or: for readentry
- * @param prev: for readentry
  * @return: range object to add to list, or NULL on error.
  */
 static struct replay_range*
-replay_range_read(char* remain, FILE* in, const char* name, int* lineno, 
-       char* line, uint32_t* ttl, ldns_rdf** or, ldns_rdf** prev)
+replay_range_read(char* remain, FILE* in, const char* name,
+       struct ldns_file_parse_state* pstate, char* line)
 {
        struct replay_range* rng = (struct replay_range*)malloc(
                sizeof(struct replay_range));
@@ -166,7 +168,7 @@ replay_range_read(char* remain, FILE* in, const char* name, int* lineno,
        /* read entries */
        pos = ftello(in);
        while(fgets(line, MAX_LINE_LEN-1, in)) {
-               (*lineno)++;
+               pstate->lineno++;
                parse = line;
                while(isspace((int)*parse))
                        parse++;
@@ -180,7 +182,7 @@ replay_range_read(char* remain, FILE* in, const char* name, int* lineno,
                        strip_end_white(parse);
                        if(!extstrtoaddr(parse, &rng->addr, &rng->addrlen)) {
                                log_err("Line %d: could not read ADDRESS: %s", 
-                                       *lineno, parse);
+                                       pstate->lineno, parse);
                                free(rng);
                                return NULL;
                        }
@@ -191,11 +193,11 @@ replay_range_read(char* remain, FILE* in, const char* name, int* lineno,
                        return rng;
                }
                /* set position before line; read entry */
-               (*lineno)--;
+               pstate->lineno--;
                fseeko(in, pos, SEEK_SET);
-               entry = read_entry(in, name, lineno, ttl, or, prev, 1);
+               entry = read_entry(in, name, pstate, 1);
                if(!entry)
-                       fatal_exit("%d: bad entry", *lineno);
+                       fatal_exit("%d: bad entry", pstate->lineno);
                entry->next = NULL;
                if(last)
                        last->next = entry;
@@ -258,15 +260,13 @@ read_assign_step(char* remain, struct replay_moment* mom)
  * @param remain: Rest of line (after STEP keyword).
  * @param in: file to read from.
  * @param name: name to print in errors.
- * @param lineno: incremented as lines are read.
- * @param ttl: for readentry
- * @param or: for readentry
- * @param prev: for readentry
+ * @param pstate: with lineno, ttl, origin, prev for parse state.
+ *     lineno is incremented.
  * @return: range object to add to list, or NULL on error.
  */
 static struct replay_moment*
-replay_moment_read(char* remain, FILE* in, const char* name, int* lineno, 
-       uint32_t* ttl, ldns_rdf** or, ldns_rdf** prev)
+replay_moment_read(char* remain, FILE* in, const char* name,
+       struct ldns_file_parse_state* pstate)
 {
        struct replay_moment* mom = (struct replay_moment*)malloc(
                sizeof(struct replay_moment));
@@ -276,7 +276,7 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
                return NULL;
        memset(mom, 0, sizeof(*mom));
        if(sscanf(remain, " %d%n", &mom->time_step, &skip) != 1) {
-               log_err("%d: cannot read number: %s", *lineno, remain);
+               log_err("%d: cannot read number: %s", pstate->lineno, remain);
                free(mom);
                return NULL;
        }
@@ -322,7 +322,7 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
                        remain[strlen(remain)-1] = 0;
                mom->autotrust_id = strdup(remain);
                if(!mom->autotrust_id) fatal_exit("out of memory");
-               read_file_content(in, lineno, mom);
+               read_file_content(in, &pstate->lineno, mom);
        } else if(parse_keyword(&remain, "ERROR")) {
                mom->evt_type = repevt_error;
        } else if(parse_keyword(&remain, "TRAFFIC")) {
@@ -357,7 +357,7 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
                if(!mom->string) fatal_exit("out of memory");
                if(!mom->variable) fatal_exit("out of memory");
        } else {
-               log_err("%d: unknown event type %s", *lineno, remain);
+               log_err("%d: unknown event type %s", pstate->lineno, remain);
                free(mom);
                return NULL;
        }
@@ -370,7 +370,7 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
                        remain[strlen(remain)-1] = 0;
                if(!extstrtoaddr(remain, &mom->addr, &mom->addrlen)) {
                        log_err("line %d: could not parse ADDRESS: %s", 
-                               *lineno, remain);
+                               pstate->lineno, remain);
                        free(mom);
                        return NULL;
                }
@@ -381,7 +381,7 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
                sec = strtod(remain, &remain);
                if(sec == 0. && errno != 0) {
                        log_err("line %d: could not parse ELAPSE: %s (%s)", 
-                               *lineno, remain, strerror(errno));
+                               pstate->lineno, remain, strerror(errno));
                        free(mom);
                        return NULL;
                }
@@ -393,7 +393,7 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
        } 
 
        if(readentry) {
-               mom->match = read_entry(in, name, lineno, ttl, or, prev, 1);
+               mom->match = read_entry(in, name, pstate, 1);
                if(!mom->match) {
                        free(mom);
                        return NULL;
@@ -432,13 +432,15 @@ replay_scenario_read(FILE* in, const char* name, int* lineno)
        char line[MAX_LINE_LEN];
        char *parse;
        struct replay_scenario* scen = NULL;
-       uint32_t ttl = 3600;
-       ldns_rdf* or = NULL;
-       ldns_rdf* prev = NULL;
+       struct ldns_file_parse_state pstate;
        line[MAX_LINE_LEN-1]=0;
+       memset(&pstate, 0, sizeof(pstate));
+       pstate.default_ttl = 3600;
+       pstate.lineno = *lineno;
 
        while(fgets(line, MAX_LINE_LEN-1, in)) {
                parse=line;
+               pstate.lineno++;
                (*lineno)++;
                while(isspace((int)*parse))
                        parse++;
@@ -456,16 +458,18 @@ replay_scenario_read(FILE* in, const char* name, int* lineno)
                        fatal_exit("%d: expected SCENARIO", *lineno);
                if(parse_keyword(&parse, "RANGE_BEGIN")) {
                        struct replay_range* newr = replay_range_read(parse, 
-                               in, name, lineno, line, &ttl, &or, &prev);
+                               in, name, &pstate, line);
                        if(!newr)
-                               fatal_exit("%d: bad range", *lineno);
+                               fatal_exit("%d: bad range", pstate.lineno);
+                       *lineno = pstate.lineno;
                        newr->next_range = scen->range_list;
                        scen->range_list = newr;
                } else if(parse_keyword(&parse, "STEP")) {
                        struct replay_moment* mom = replay_moment_read(parse, 
-                               in, name, lineno, &ttl, &or, &prev);
+                               in, name, &pstate);
                        if(!mom)
-                               fatal_exit("%d: bad moment", *lineno);
+                               fatal_exit("%d: bad moment", pstate.lineno);
+                       *lineno = pstate.lineno;
                        if(scen->mom_last && 
                                scen->mom_last->time_step >= mom->time_step)
                                fatal_exit("%d: time goes backwards", *lineno);
@@ -481,13 +485,9 @@ replay_scenario_read(FILE* in, const char* name, int* lineno)
                                p = p->mom_next;
                        }
                        log_info("Scenario has %d steps", num);
-                       ldns_rdf_deep_free(or);
-                       ldns_rdf_deep_free(prev);
                        return scen;
                }
        }
-       ldns_rdf_deep_free(or);
-       ldns_rdf_deep_free(prev);
        replay_scenario_delete(scen);
        return NULL;
 }
index beac3ce839d2a20f07fdc8921b5d90dbc69726af..09ec9a6e1e19ab6bafb52597bebce5f269f9c2d5 100644 (file)
 #ifndef TESTCODE_REPLAY_H
 #define TESTCODE_REPLAY_H
 #include "util/netevent.h"
-#include "testcode/ldns-testpkts.h"
+#include "testcode/testpkts.h"
 #include "util/rbtree.h"
 struct replay_answer;
 struct replay_moment;
@@ -138,6 +138,7 @@ struct fake_pending;
 struct fake_timer;
 struct replay_var;
 struct infra_cache;
+struct ldns_buffer;
 
 /**
  * A replay scenario.
@@ -217,12 +218,6 @@ struct replay_moment {
        /** length of addr, if 0, then any address will do */
        socklen_t addrlen;
 
-       /** what pending query should timeout or is answered. or 
-        * NULL for last sent query. 
-        * Unused at this time.
-        */
-       ldns_rr* qname;
-
        /** macro name, for assign. */
        char* variable;
        /** string argument, for assign. */
@@ -318,7 +313,7 @@ struct replay_runtime {
  */
 struct fake_pending {
        /** what is important only that we remember the query, copied here. */
-       ldns_buffer* buffer;
+       struct ldns_buffer* buffer;
        /** and to what address this is sent to. */
        struct sockaddr_storage addr;
        /** len of addr */
@@ -339,7 +334,8 @@ struct fake_pending {
        /** next in pending list */
        struct fake_pending* next;
        /** the buffer parsed into a ldns_pkt */
-       ldns_pkt* pkt;
+       uint8_t* pkt;
+       size_t pkt_len;
        /** by what transport was the query sent out */
        enum transport_type transport;
        /** if this is a serviced query */
@@ -357,7 +353,8 @@ struct replay_answer {
        /** reply information */
        struct comm_reply repinfo;
        /** the answer preparsed as ldns pkt */
-       ldns_pkt* pkt;
+       uint8_t* pkt;
+       size_t pkt_len;
 };
 
 /**
index 49256e707d316b280b99a09714e2e5e83d3bac4b..7b40bb46c642e6329441dfded06f84d715091bd1 100644 (file)
@@ -41,9 +41,9 @@
  */
 #include "config.h"
 #include <ldns/ldns.h>
-#include "util/log.h"
-#include "util/config_file.h"
-#include "util/net_help.h"
+#include <assert.h>
+
+#define DNSKEY_BIT_ZSK 0x0100
 
 /**
  * Key settings
@@ -74,12 +74,47 @@ usage()
        exit(1);
 }
 
+static time_t 
+convert_timeval(const char* str)
+{
+       time_t t;
+       struct tm tm;
+       memset(&tm, 0, sizeof(tm));
+       if(strlen(str) < 14)
+               return 0;
+       if(sscanf(str, "%4d%2d%2d%2d%2d%2d", &tm.tm_year, &tm.tm_mon, 
+               &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6)
+               return 0;
+       tm.tm_year -= 1900;
+       tm.tm_mon--;
+       /* Check values */
+       if (tm.tm_year < 70)    return 0;
+       if (tm.tm_mon < 0 || tm.tm_mon > 11)    return 0;
+       if (tm.tm_mday < 1 || tm.tm_mday > 31)  return 0;
+       if (tm.tm_hour < 0 || tm.tm_hour > 23)  return 0;
+       if (tm.tm_min < 0 || tm.tm_min > 59)    return 0;
+       if (tm.tm_sec < 0 || tm.tm_sec > 59)    return 0;
+       /* call ldns conversion function */
+       t = ldns_mktime_from_utc(&tm);
+       return t;
+}
+
+static void fatal_exit(const char* format, ...)
+{
+       va_list args;
+       va_start(args, format);
+       printf("fatal exit: ");
+       vprintf(format, args);
+       va_end(args);
+       exit(1);
+}
+
 /** read expi ince keytag owner from cmdline */
 static void
 parse_cmdline(char *argv[], struct keysets* s)
 {
-       s->expi = cfg_convert_timeval(argv[1]);
-       s->incep = cfg_convert_timeval(argv[2]);
+       s->expi = convert_timeval(argv[1]);
+       s->incep = convert_timeval(argv[2]);
        s->keytag = (uint16_t)atoi(argv[3]);
        s->owner = argv[4];
        s->flags = DNSKEY_BIT_ZSK; /* to enforce signing */
@@ -118,7 +153,7 @@ read_keys(int num, char* names[], struct keysets* set)
                ldns_key_set_flags(k, set->flags);
                ldns_key_set_keytag(k, set->keytag);
                b = ldns_key_list_push_key(keys, k);
-               log_assert(b);
+               assert(b);
        }
        return keys;
 }
@@ -151,7 +186,7 @@ read_rrs(FILE* in)
                        fatal_exit("parse error in line %d: %s", line_nr,
                                ldns_get_errorstr_by_id(s));
                b = ldns_rr_list_push_rr(list, rr);
-               log_assert(b);
+               assert(b);
        }
        printf("read %d lines\n", line_nr);
 
@@ -185,7 +220,7 @@ process_keys(int argc, char* argv[])
        ldns_rr_list* rrs;
        ldns_key_list* keys;
        struct keysets settings;
-       log_assert(argc == 6);
+       assert(argc == 6);
 
        parse_cmdline(argv, &settings);
        keys = read_keys(1, argv+5, &settings);
@@ -208,7 +243,7 @@ process_nsec3(int argc, char* argv[])
        if(status != LDNS_STATUS_OK)
                fatal_exit("Could not parse salt %s: %s", argv[5],
                        ldns_get_errorstr_by_id(status));
-       log_assert(argc == 6);
+       assert(argc == 6);
        while(fgets(line, (int)sizeof(line), stdin)) {
                if(strlen(line) > 0)
                        line[strlen(line)-1] = 0; /* remove trailing newline */
@@ -237,7 +272,6 @@ process_nsec3(int argc, char* argv[])
 /** main program */
 int main(int argc, char* argv[])
 {
-       log_init(NULL, 0, NULL);
        if(argc != 6) {
                usage();
        }
index 06a18e4cfafb01d2469ca19bc3144bc4ef4a025b..7d4bd8cb8092da35441d31ce1439204664b31048 100644 (file)
@@ -43,7 +43,6 @@
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #endif
-#include <ldns/ldns.h>
 #include <signal.h>
 #include "util/locks.h"
 #include "util/log.h"
 #include "util/data/msgparse.h"
 #include "util/data/msgreply.h"
 #include "util/data/dname.h"
+#include "ldns/sbuffer.h"
+#include "ldns/str2wire.h"
+#include "ldns/wire2str.h"
+#include <openssl/ssl.h>
+#include <openssl/rand.h>
 #include <openssl/err.h>
 
 #ifndef PF_INET6
@@ -112,18 +116,13 @@ write_q(int fd, int udp, SSL* ssl, ldns_buffer* buf, uint16_t id,
        const char* strname, const char* strtype, const char* strclass)
 {
        struct query_info qinfo;
-       ldns_rdf* rdf;
        uint16_t len;
        /* qname */
-       rdf = ldns_dname_new_frm_str(strname);
-       if(!rdf) {
+       qinfo.qname = ldns_str2wire_dname(strname, &qinfo.qname_len);
+       if(!qinfo.qname) {
                printf("cannot parse query name: '%s'\n", strname);
                exit(1);
        }
-       qinfo.qname = memdup(ldns_rdf_data(rdf), ldns_rdf_size(rdf));
-       if(!qinfo.qname) fatal_exit("out of memory");
-       (void)dname_count_size_labels(qinfo.qname, &qinfo.qname_len);
-       ldns_rdf_deep_free(rdf);
 
        /* qtype and qclass */
        qinfo.qtype = ldns_get_rr_type_by_name(strtype);
@@ -192,9 +191,8 @@ write_q(int fd, int udp, SSL* ssl, ldns_buffer* buf, uint16_t id,
 static void
 recv_one(int fd, int udp, SSL* ssl, ldns_buffer* buf)
 {
+       char* pktstr;
        uint16_t len;
-       ldns_pkt* pkt;
-       ldns_status status;
        if(!udp) {
                if(ssl) {
                        if(SSL_read(ssl, (void*)&len, (int)sizeof(len)) <= 0) {
@@ -256,15 +254,18 @@ recv_one(int fd, int udp, SSL* ssl, ldns_buffer* buf)
        printf("\nnext received packet\n");
        log_buf(0, "data", buf);
 
-       status = ldns_wire2pkt(&pkt, ldns_buffer_begin(buf), len);
-       if(status != LDNS_STATUS_OK) {
-               printf("could not parse incoming packet: %s\n",
-                       ldns_get_errorstr_by_id(status));
-               log_buf(0, "data was", buf);
-               exit(1);
+       pktstr = ldns_wire2str_pkt(ldns_buffer_begin(buf), len);
+       printf("%s", pktstr);
+       free(pktstr);
+}
+
+static int get_random(void)
+{
+       int r;
+       if (RAND_bytes((unsigned char*)&r, (int)sizeof(r)) == 1) {
+               return r;
        }
-       ldns_pkt_print(stdout, pkt);
-       ldns_pkt_free(pkt);
+       return (int)random();
 }
 
 /** send the TCP queries and print answers */
@@ -305,7 +306,7 @@ send_em(const char* svr, int udp, int usessl, int noanswer, int num, char** qs)
        }
        for(i=0; i<num; i+=3) {
                printf("\nNext query is %s %s %s\n", qs[i], qs[i+1], qs[i+2]);
-               write_q(fd, udp, ssl, buf, ldns_get_random(), qs[i],
+               write_q(fd, udp, ssl, buf, (uint16_t)get_random(), qs[i],
                        qs[i+1], qs[i+2]);
                /* print at least one result */
                if(!noanswer)
index 6e88edf22e625a9cd7c4d3dd32dabda02b3fafdb..9a53fe1184852006642ae72d2766a2458a2632c1 100644 (file)
  */
 
 #include "config.h"
-#include "testcode/ldns-testpkts.h"
+#include "testcode/testpkts.h"
 #include "testcode/replay.h"
 #include "testcode/fake_event.h"
 #include "daemon/remote.h"
 #include "util/config_file.h"
+#include "ldns/keyraw.h"
+#include <ctype.h>
 
 /** signal that this is a testbound compile */
 #define unbound_testbound 1
diff --git a/testcode/testpkts.c b/testcode/testpkts.c
new file mode 100644 (file)
index 0000000..7701404
--- /dev/null
@@ -0,0 +1,1427 @@
+/*
+ * testpkts. Data file parse for test packets, and query matching.
+ *
+ * Data storage for specially crafted replies for testing purposes.
+ *
+ * (c) NLnet Labs, 2005, 2006, 2007, 2008
+ * See the file LICENSE for the license
+ */
+
+/**
+ * \file
+ * This is a debugging aid. It is not efficient, especially
+ * with a long config file, but it can give any reply to any query.
+ * This can help the developer pre-script replies for queries.
+ *
+ * You can specify a packet RR by RR with header flags to return.
+ *
+ * Missing features:
+ *             - matching content different from reply content.
+ *             - find way to adjust mangled packets?
+ */
+
+#include "config.h"
+struct sockaddr_storage;
+#include <errno.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include "testcode/testpkts.h"
+#include "util/net_help.h"
+#include "ldns/sbuffer.h"
+#include "ldns/rrdef.h"
+#include "ldns/pkthdr.h"
+#include "ldns/str2wire.h"
+#include "ldns/wire2str.h"
+
+/** max size of a packet */
+#define MAX_PACKETLEN 65536
+/** max line length */
+#define MAX_LINE   10240       
+/** string to show in warnings and errors */
+static const char* prog_name = "testpkts";
+
+#ifndef UTIL_LOG_H
+/** verbosity definition for compat */
+enum verbosity_value { NO_VERBOSE=0 };
+#endif
+/** logging routine, provided by caller */
+void verbose(enum verbosity_value lvl, const char* msg, ...) ATTR_FORMAT(printf, 2, 3);
+
+/** print error and exit */
+static void error(const char* msg, ...)
+{
+       va_list args;
+       va_start(args, msg);
+       fprintf(stderr, "%s error: ", prog_name);
+       vfprintf(stderr, msg, args);
+       fprintf(stderr, "\n");
+       fflush(stderr);
+       va_end(args);
+       exit(EXIT_FAILURE);
+}
+
+/** return if string is empty or comment */
+static int isendline(char c)
+{
+       if(c == ';' || c == '#' 
+               || c == '\n' || c == 0)
+               return 1;
+       return 0;
+}
+
+/** true if the string starts with the keyword given. Moves the str ahead. 
+ * @param str: before keyword, afterwards after keyword and spaces.
+ * @param keyword: the keyword to match
+ * @return: true if keyword present. False otherwise, and str unchanged.
+*/
+static int str_keyword(char** str, const char* keyword)
+{
+       size_t len = strlen(keyword);
+       assert(str && keyword);
+       if(strncmp(*str, keyword, len) != 0)
+               return 0;
+       *str += len;
+       while(isspace((int)**str))
+               (*str)++;
+       return 1;
+}
+
+/** Add reply packet to entry */
+static struct reply_packet*
+entry_add_reply(struct entry* entry) 
+{
+       struct reply_packet* pkt = (struct reply_packet*)malloc(
+               sizeof(struct reply_packet));
+       struct reply_packet ** p = &entry->reply_list;
+       if(!pkt) error("out of memory");
+       pkt->next = NULL;
+       pkt->packet_sleep = 0;
+       pkt->reply_pkt = NULL;
+       pkt->reply_from_hex = NULL;
+       /* link at end */
+       while(*p)
+               p = &((*p)->next);
+       *p = pkt;
+       return pkt;
+}
+
+/** parse MATCH line */
+static void matchline(char* line, struct entry* e)
+{
+       char* parse = line;
+       while(*parse) {
+               if(isendline(*parse)) 
+                       return;
+               if(str_keyword(&parse, "opcode")) {
+                       e->match_opcode = 1;
+               } else if(str_keyword(&parse, "qtype")) {
+                       e->match_qtype = 1;
+               } else if(str_keyword(&parse, "qname")) {
+                       e->match_qname = 1;
+               } else if(str_keyword(&parse, "subdomain")) {
+                       e->match_subdomain = 1;
+               } else if(str_keyword(&parse, "all")) {
+                       e->match_all = 1;
+               } else if(str_keyword(&parse, "ttl")) {
+                       e->match_ttl = 1;
+               } else if(str_keyword(&parse, "DO")) {
+                       e->match_do = 1;
+               } else if(str_keyword(&parse, "noedns")) {
+                       e->match_noedns = 1;
+               } else if(str_keyword(&parse, "UDP")) {
+                       e->match_transport = transport_udp;
+               } else if(str_keyword(&parse, "TCP")) {
+                       e->match_transport = transport_tcp;
+               } else if(str_keyword(&parse, "serial")) {
+                       e->match_serial = 1;
+                       if(*parse != '=' && *parse != ':')
+                               error("expected = or : in MATCH: %s", line);
+                       parse++;
+                       e->ixfr_soa_serial = (uint32_t)strtol(parse, (char**)&parse, 10);
+                       while(isspace((int)*parse)) 
+                               parse++;
+               } else {
+                       error("could not parse MATCH: '%s'", parse);
+               }
+       }
+}
+
+/** parse REPLY line */
+static void replyline(char* line, uint8_t* reply, size_t reply_len,
+       int* do_flag)
+{
+       char* parse = line;
+       if(reply_len < LDNS_HEADER_SIZE) error("packet too short for header");
+       while(*parse) {
+               if(isendline(*parse)) 
+                       return;
+                       /* opcodes */
+               if(str_keyword(&parse, "QUERY")) {
+                       LDNS_OPCODE_SET(reply, LDNS_PACKET_QUERY);
+               } else if(str_keyword(&parse, "IQUERY")) {
+                       LDNS_OPCODE_SET(reply, LDNS_PACKET_IQUERY);
+               } else if(str_keyword(&parse, "STATUS")) {
+                       LDNS_OPCODE_SET(reply, LDNS_PACKET_STATUS);
+               } else if(str_keyword(&parse, "NOTIFY")) {
+                       LDNS_OPCODE_SET(reply, LDNS_PACKET_NOTIFY);
+               } else if(str_keyword(&parse, "UPDATE")) {
+                       LDNS_OPCODE_SET(reply, LDNS_PACKET_UPDATE);
+                       /* rcodes */
+               } else if(str_keyword(&parse, "NOERROR")) {
+                       LDNS_RCODE_SET(reply, LDNS_RCODE_NOERROR);
+               } else if(str_keyword(&parse, "FORMERR")) {
+                       LDNS_RCODE_SET(reply, LDNS_RCODE_FORMERR);
+               } else if(str_keyword(&parse, "SERVFAIL")) {
+                       LDNS_RCODE_SET(reply, LDNS_RCODE_SERVFAIL);
+               } else if(str_keyword(&parse, "NXDOMAIN")) {
+                       LDNS_RCODE_SET(reply, LDNS_RCODE_NXDOMAIN);
+               } else if(str_keyword(&parse, "NOTIMPL")) {
+                       LDNS_RCODE_SET(reply, LDNS_RCODE_NOTIMPL);
+               } else if(str_keyword(&parse, "REFUSED")) {
+                       LDNS_RCODE_SET(reply, LDNS_RCODE_REFUSED);
+               } else if(str_keyword(&parse, "YXDOMAIN")) {
+                       LDNS_RCODE_SET(reply, LDNS_RCODE_YXDOMAIN);
+               } else if(str_keyword(&parse, "YXRRSET")) {
+                       LDNS_RCODE_SET(reply, LDNS_RCODE_YXRRSET);
+               } else if(str_keyword(&parse, "NXRRSET")) {
+                       LDNS_RCODE_SET(reply, LDNS_RCODE_NXRRSET);
+               } else if(str_keyword(&parse, "NOTAUTH")) {
+                       LDNS_RCODE_SET(reply, LDNS_RCODE_NOTAUTH);
+               } else if(str_keyword(&parse, "NOTZONE")) {
+                       LDNS_RCODE_SET(reply, LDNS_RCODE_NOTZONE);
+                       /* flags */
+               } else if(str_keyword(&parse, "QR")) {
+                       LDNS_QR_SET(reply);
+               } else if(str_keyword(&parse, "AA")) {
+                       LDNS_AA_SET(reply);
+               } else if(str_keyword(&parse, "TC")) {
+                       LDNS_TC_SET(reply);
+               } else if(str_keyword(&parse, "RD")) {
+                       LDNS_RD_SET(reply);
+               } else if(str_keyword(&parse, "CD")) {
+                       LDNS_CD_SET(reply);
+               } else if(str_keyword(&parse, "RA")) {
+                       LDNS_RA_SET(reply);
+               } else if(str_keyword(&parse, "AD")) {
+                       LDNS_AD_SET(reply);
+               } else if(str_keyword(&parse, "DO")) {
+                       *do_flag = 1;
+               } else {
+                       error("could not parse REPLY: '%s'", parse);
+               }
+       }
+}
+
+/** parse ADJUST line */
+static void adjustline(char* line, struct entry* e, 
+       struct reply_packet* pkt)
+{
+       char* parse = line;
+       while(*parse) {
+               if(isendline(*parse)) 
+                       return;
+               if(str_keyword(&parse, "copy_id")) {
+                       e->copy_id = 1;
+               } else if(str_keyword(&parse, "copy_query")) {
+                       e->copy_query = 1;
+               } else if(str_keyword(&parse, "sleep=")) {
+                       e->sleeptime = (unsigned int) strtol(parse, (char**)&parse, 10);
+                       while(isspace((int)*parse)) 
+                               parse++;
+               } else if(str_keyword(&parse, "packet_sleep=")) {
+                       pkt->packet_sleep = (unsigned int) strtol(parse, (char**)&parse, 10);
+                       while(isspace((int)*parse)) 
+                               parse++;
+               } else {
+                       error("could not parse ADJUST: '%s'", parse);
+               }
+       }
+}
+
+/** create new entry */
+static struct entry* new_entry()
+{
+       struct entry* e = (struct entry*)malloc(sizeof(struct entry));
+       if(!e) error("out of memory");
+       memset(e, 0, sizeof(*e));
+       e->match_opcode = 0;
+       e->match_qtype = 0;
+       e->match_qname = 0;
+       e->match_subdomain = 0;
+       e->match_all = 0;
+       e->match_ttl = 0;
+       e->match_do = 0;
+       e->match_noedns = 0;
+       e->match_serial = 0;
+       e->ixfr_soa_serial = 0;
+       e->match_transport = transport_any;
+       e->reply_list = NULL;
+       e->copy_id = 0;
+       e->copy_query = 0;
+       e->sleeptime = 0;
+       e->next = NULL;
+       return e;
+}
+
+/**
+ * Converts a hex string to binary data
+ * @param hexstr: string of hex.
+ * @param len: is the length of the string
+ * @param buf: is the buffer to store the result in
+ * @param offset: is the starting position in the result buffer
+ * @param buf_len: is the length of buf.
+ * @return This function returns the length of the result
+ */
+static size_t
+hexstr2bin(char *hexstr, int len, uint8_t *buf, size_t offset, size_t buf_len)
+{
+       char c;
+       int i; 
+       uint8_t int8 = 0;
+       int sec = 0;
+       size_t bufpos = 0;
+       
+       if (len % 2 != 0) {
+               return 0;
+       }
+
+       for (i=0; i<len; i++) {
+               c = hexstr[i];
+
+               /* case insensitive, skip spaces */
+               if (c != ' ') {
+                       if (c >= '0' && c <= '9') {
+                               int8 += c & 0x0f;  
+                       } else if (c >= 'a' && c <= 'z') {
+                               int8 += (c & 0x0f) + 9;   
+                       } else if (c >= 'A' && c <= 'Z') {
+                               int8 += (c & 0x0f) + 9;   
+                       } else {
+                               return 0;
+                       }
+                        
+                       if (sec == 0) {
+                               int8 = int8 << 4;
+                               sec = 1;
+                       } else {
+                               if (bufpos + offset + 1 <= buf_len) {
+                                       buf[bufpos+offset] = int8;
+                                       int8 = 0;
+                                       sec = 0; 
+                                       bufpos++;
+                               } else {
+                                       fprintf(stderr, "Buffer too small in hexstr2bin");
+                               }
+                       }
+               }
+        }
+        return bufpos;
+}
+
+/** convert hex buffer to binary buffer */
+static ldns_buffer *
+hex_buffer2wire(ldns_buffer *data_buffer)
+{
+       ldns_buffer *wire_buffer = NULL;
+       int c;
+       
+       /* stat hack
+        * 0 = normal
+        * 1 = comment (skip to end of line)
+        * 2 = unprintable character found, read binary data directly
+        */
+       size_t data_buf_pos = 0;
+       int state = 0;
+       uint8_t *hexbuf;
+       int hexbufpos = 0;
+       size_t wirelen;
+       uint8_t *data_wire = (uint8_t *) ldns_buffer_begin(data_buffer);
+       uint8_t *wire = (uint8_t*)malloc(MAX_PACKETLEN);
+       if(!wire) error("out of memory");
+       
+       hexbuf = (uint8_t*)malloc(MAX_PACKETLEN);
+       if(!hexbuf) error("out of memory");
+       for (data_buf_pos = 0; data_buf_pos < ldns_buffer_position(data_buffer); data_buf_pos++) {
+               c = (int) data_wire[data_buf_pos];
+               
+               if (state < 2 && !isascii(c)) {
+                       /*verbose("non ascii character found in file: (%d) switching to raw mode\n", c);*/
+                       state = 2;
+               }
+               switch (state) {
+                       case 0:
+                               if (    (c >= '0' && c <= '9') ||
+                                       (c >= 'a' && c <= 'f') ||
+                                       (c >= 'A' && c <= 'F') )
+                               {
+                                       if (hexbufpos >= MAX_PACKETLEN) {
+                                               error("buffer overflow");
+                                               free(hexbuf);
+                                               return 0;
+
+                                       }
+                                       hexbuf[hexbufpos] = (uint8_t) c;
+                                       hexbufpos++;
+                               } else if (c == ';') {
+                                       state = 1;
+                               } else if (c == ' ' || c == '\t' || c == '\n') {
+                                       /* skip whitespace */
+                               } 
+                               break;
+                       case 1:
+                               if (c == '\n' || c == EOF) {
+                                       state = 0;
+                               }
+                               break;
+                       case 2:
+                               if (hexbufpos >= MAX_PACKETLEN) {
+                                       error("buffer overflow");
+                                       free(hexbuf);
+                                       return 0;
+                               }
+                               hexbuf[hexbufpos] = (uint8_t) c;
+                               hexbufpos++;
+                               break;
+               }
+       }
+
+       if (hexbufpos >= MAX_PACKETLEN) {
+               /*verbose("packet size reached\n");*/
+       }
+       
+       /* lenient mode: length must be multiple of 2 */
+       if (hexbufpos % 2 != 0) {
+               if (hexbufpos >= MAX_PACKETLEN) {
+                       error("buffer overflow");
+                       free(hexbuf);
+                       return 0;
+               }
+               hexbuf[hexbufpos] = (uint8_t) '0';
+               hexbufpos++;
+       }
+
+       if (state < 2) {
+               wirelen = hexstr2bin((char *) hexbuf, hexbufpos, wire, 0, MAX_PACKETLEN);
+               wire_buffer = ldns_buffer_new(wirelen);
+               ldns_buffer_new_frm_data(wire_buffer, wire, wirelen);
+       } else {
+               error("Incomplete hex data, not at byte boundary\n");
+       }
+       free(wire);
+       free(hexbuf);
+       return wire_buffer;
+}      
+
+/** parse ORIGIN */
+static void 
+get_origin(const char* name, struct ldns_file_parse_state* pstate, char* parse)
+{
+       /* snip off rest of the text so as to make the parse work in ldns */
+       char* end;
+       char store;
+       int status;
+
+       end=parse;
+       while(!isspace((int)*end) && !isendline(*end))
+               end++;
+       store = *end;
+       *end = 0;
+       verbose(3, "parsing '%s'\n", parse);
+       status = ldns_str2wire_dname_buf(parse, pstate->origin,
+               &pstate->origin_len);
+       *end = store;
+       if(status != 0)
+               error("%s line %d:\n\t%s: %s", name, pstate->lineno,
+                       ldns_get_errorstr_parse(status), parse);
+}
+
+/** add RR to packet */
+static void add_rr(char* rrstr, uint8_t* pktbuf, size_t pktsize,
+       size_t* pktlen, struct ldns_file_parse_state* pstate,
+       ldns_pkt_section add_section, const char* fname)
+{
+       /* it must be a RR, parse and add to packet. */
+       size_t rr_len = pktsize - *pktlen;
+       size_t dname_len = 0;
+       int status;
+       uint8_t* origin = pstate->origin_len?pstate->origin:0;
+       uint8_t* prev = pstate->prev_rr_len?pstate->prev_rr:0;
+       if(*pktlen > pktsize || *pktlen < LDNS_HEADER_SIZE)
+               error("packet overflow");
+
+       /* parse RR */
+       if(add_section == LDNS_SECTION_QUESTION)
+               status = ldns_str2wire_rr_question_buf(rrstr, pktbuf+*pktlen,
+                       &rr_len, &dname_len, origin, pstate->origin_len,
+                       prev, pstate->prev_rr_len);
+       else status = ldns_str2wire_rr_buf(rrstr, pktbuf+*pktlen, &rr_len,
+                       &dname_len, pstate->default_ttl, origin,
+                       pstate->origin_len, prev, pstate->prev_rr_len);
+       if(status != 0)
+               error("%s line %d:%d %s\n\t%s", fname, pstate->lineno,
+                       LDNS_WIREPARSE_OFFSET(status),
+                       ldns_get_errorstr_parse(status), rrstr);
+       *pktlen += rr_len;
+
+       /* increase RR count */
+       if(add_section == LDNS_SECTION_QUESTION)
+               ldns_write_uint16(pktbuf+4, LDNS_QDCOUNT(pktbuf)+1);
+       else if(add_section == LDNS_SECTION_ANSWER)
+               ldns_write_uint16(pktbuf+6, LDNS_ANCOUNT(pktbuf)+1);
+       else if(add_section == LDNS_SECTION_AUTHORITY)
+               ldns_write_uint16(pktbuf+8, LDNS_NSCOUNT(pktbuf)+1);
+       else if(add_section == LDNS_SECTION_ADDITIONAL)
+               ldns_write_uint16(pktbuf+10, LDNS_ARCOUNT(pktbuf)+1);
+       else error("internal error bad section %d", (int)add_section);
+}
+
+/* add EDNS 4096 DO opt record */
+static void
+add_do_flag(uint8_t* pktbuf, size_t pktsize, size_t* pktlen)
+{
+       uint8_t edns[] = {0x00, /* root label */
+               0x00, LDNS_RR_TYPE_OPT, /* type */
+               0x10, 0x00, /* class is UDPSIZE 4096 */
+               0x00, /* TTL[0] is ext rcode */
+               0x00, /* TTL[1] is edns version */
+               0x80, 0x00, /* TTL[2-3] is edns flags, DO */
+               0x00, 0x00 /* rdatalength (0 options) */
+       };
+       if(*pktlen < LDNS_HEADER_SIZE)
+               return;
+       if(*pktlen + sizeof(edns) > pktsize)
+               error("not enough space for EDNS OPT record");
+       memmove(pktbuf+*pktlen, edns, sizeof(edns));
+       ldns_write_uint16(pktbuf+10, LDNS_ARCOUNT(pktbuf)+1);
+       *pktlen += sizeof(edns);
+}
+
+/* Reads one entry from file. Returns entry or NULL on error. */
+struct entry*
+read_entry(FILE* in, const char* name, struct ldns_file_parse_state* pstate,
+       int skip_whitespace)
+{
+       struct entry* current = NULL;
+       char line[MAX_LINE];
+       char* parse;
+       ldns_pkt_section add_section = LDNS_SECTION_QUESTION;
+       struct reply_packet *cur_reply = NULL;
+       int reading_hex = 0;
+       ldns_buffer* hex_data_buffer = NULL;
+       uint8_t pktbuf[MAX_PACKETLEN];
+       size_t pktlen = LDNS_HEADER_SIZE;
+       int do_flag = 0; /* DO flag in EDNS */
+       memset(pktbuf, 0, pktlen); /* ID = 0, FLAGS="", and rr counts 0 */
+
+       while(fgets(line, (int)sizeof(line), in) != NULL) {
+               line[MAX_LINE-1] = 0;
+               parse = line;
+               pstate->lineno++;
+
+               while(isspace((int)*parse))
+                       parse++;
+               /* test for keywords */
+               if(isendline(*parse))
+                       continue; /* skip comment and empty lines */
+               if(str_keyword(&parse, "ENTRY_BEGIN")) {
+                       if(current) {
+                               error("%s line %d: previous entry does not ENTRY_END", 
+                                       name, pstate->lineno);
+                       }
+                       current = new_entry();
+                       current->lineno = pstate->lineno;
+                       cur_reply = entry_add_reply(current);
+                       continue;
+               } else if(str_keyword(&parse, "$ORIGIN")) {
+                       get_origin(name, pstate, parse);
+                       continue;
+               } else if(str_keyword(&parse, "$TTL")) {
+                       pstate->default_ttl = (uint32_t)atoi(parse);
+                       continue;
+               }
+
+               /* working inside an entry */
+               if(!current) {
+                       error("%s line %d: expected ENTRY_BEGIN but got %s", 
+                               name, pstate->lineno, line);
+               }
+               if(str_keyword(&parse, "MATCH")) {
+                       matchline(parse, current);
+               } else if(str_keyword(&parse, "REPLY")) {
+                       replyline(parse, pktbuf, pktlen, &do_flag);
+               } else if(str_keyword(&parse, "ADJUST")) {
+                       adjustline(parse, current, cur_reply);
+               } else if(str_keyword(&parse, "EXTRA_PACKET")) {
+                       cur_reply = entry_add_reply(current);
+               } else if(str_keyword(&parse, "SECTION")) {
+                       if(str_keyword(&parse, "QUESTION"))
+                               add_section = LDNS_SECTION_QUESTION;
+                       else if(str_keyword(&parse, "ANSWER"))
+                               add_section = LDNS_SECTION_ANSWER;
+                       else if(str_keyword(&parse, "AUTHORITY"))
+                               add_section = LDNS_SECTION_AUTHORITY;
+                       else if(str_keyword(&parse, "ADDITIONAL"))
+                               add_section = LDNS_SECTION_ADDITIONAL;
+                       else error("%s line %d: bad section %s", name, pstate->lineno, parse);
+               } else if(str_keyword(&parse, "HEX_ANSWER_BEGIN")) {
+                       hex_data_buffer = ldns_buffer_new(MAX_PACKETLEN);
+                       reading_hex = 1;
+               } else if(str_keyword(&parse, "HEX_ANSWER_END")) {
+                       if(!reading_hex) {
+                               error("%s line %d: HEX_ANSWER_END read but no HEX_ANSWER_BEGIN keyword seen", name, pstate->lineno);
+                       }
+                       reading_hex = 0;
+                       cur_reply->reply_from_hex = hex_buffer2wire(hex_data_buffer);
+                       ldns_buffer_free(hex_data_buffer);
+                       hex_data_buffer = NULL;
+               } else if(str_keyword(&parse, "ENTRY_END")) {
+                       if(hex_data_buffer)
+                               ldns_buffer_free(hex_data_buffer);
+                       if(pktlen != 0) {
+                               if(do_flag)
+                                       add_do_flag(pktbuf, sizeof(pktbuf),
+                                               &pktlen);
+                               cur_reply->reply_pkt = memdup(pktbuf, pktlen);
+                               cur_reply->reply_len = pktlen;
+                               if(!cur_reply->reply_pkt)
+                                       error("out of memory");
+                       }
+                       return current;
+               } else if(reading_hex) {
+                       ldns_buffer_printf(hex_data_buffer, line);
+               } else {
+                       add_rr(skip_whitespace?parse:line, pktbuf,
+                               sizeof(pktbuf), &pktlen, pstate, add_section,
+                               name);
+               }
+
+       }
+       if (reading_hex) {
+               error("%s: End of file reached while still reading hex, "
+                       "missing HEX_ANSWER_END\n", name);
+       }
+       if(current) {
+               error("%s: End of file reached while reading entry. "
+                       "missing ENTRY_END\n", name);
+       }
+       return 0;
+}
+
+/* reads the canned reply file and returns a list of structs */
+struct entry* 
+read_datafile(const char* name, int skip_whitespace)
+{
+       struct entry* list = NULL;
+       struct entry* last = NULL;
+       struct entry* current = NULL;
+       FILE *in;
+       struct ldns_file_parse_state pstate;
+       int entry_num = 0;
+       memset(&pstate, 0, sizeof(pstate));
+
+       if((in=fopen(name, "r")) == NULL) {
+               error("could not open file %s: %s", name, strerror(errno));
+       }
+
+       while((current = read_entry(in, name, &pstate, skip_whitespace)))
+       {
+               if(last)
+                       last->next = current;
+               else    list = current;
+               last = current;
+               entry_num ++;
+       }
+       verbose(1, "%s: Read %d entries\n", prog_name, entry_num);
+
+       fclose(in);
+       return list;
+}
+
+/** get qtype from packet */
+static ldns_rr_type get_qtype(uint8_t* pkt, size_t pktlen)
+{
+       uint8_t* d;
+       size_t dl, sl=0;
+       char* snull = NULL;
+       if(pktlen < LDNS_HEADER_SIZE)
+               return 0;
+       if(LDNS_QDCOUNT(pkt) == 0)
+               return 0;
+       /* skip over dname with dname-scan routine */
+       d = pkt+LDNS_HEADER_SIZE;
+       dl = pktlen-LDNS_HEADER_SIZE;
+       (void)ldns_wire2str_dname_scan(&d, &dl, &snull, &sl, pkt, pktlen);
+       if(dl < 2)
+               return 0;
+       return ldns_read_uint16(d);
+}
+
+/** get qtype from packet */
+static size_t get_qname_len(uint8_t* pkt, size_t pktlen)
+{
+       uint8_t* d;
+       size_t dl, sl=0;
+       char* snull = NULL;
+       if(pktlen < LDNS_HEADER_SIZE)
+               return 0;
+       if(LDNS_QDCOUNT(pkt) == 0)
+               return 0;
+       /* skip over dname with dname-scan routine */
+       d = pkt+LDNS_HEADER_SIZE;
+       dl = pktlen-LDNS_HEADER_SIZE;
+       (void)ldns_wire2str_dname_scan(&d, &dl, &snull, &sl, pkt, pktlen);
+       return pktlen-dl-LDNS_HEADER_SIZE;
+}
+
+/** returns owner from packet */
+static uint8_t* get_qname(uint8_t* pkt, size_t pktlen)
+{
+       if(pktlen < LDNS_HEADER_SIZE)
+               return NULL;
+       if(LDNS_QDCOUNT(pkt) == 0)
+               return NULL;
+       return pkt+LDNS_HEADER_SIZE;
+}
+
+/** returns opcode from packet */
+static int get_opcode(uint8_t* pkt, size_t pktlen)
+{
+       if(pktlen < LDNS_HEADER_SIZE)
+               return 0;
+       return (int)LDNS_OPCODE_WIRE(pkt);
+}
+
+/** get authority section SOA serial value */
+static uint32_t get_serial(uint8_t* p, size_t plen)
+{
+       uint8_t* walk = p;
+       size_t walk_len = plen, sl=0;
+       char* snull = NULL;
+       uint16_t i;
+
+       if(walk_len < LDNS_HEADER_SIZE)
+               return 0;
+       walk += LDNS_HEADER_SIZE;
+       walk_len -= LDNS_HEADER_SIZE;
+
+       /* skip other records with wire2str_scan */
+       for(i=0; i < LDNS_QDCOUNT(p); i++)
+               (void)ldns_wire2str_rrquestion_scan(&walk, &walk_len,
+                       &snull, &sl, p, plen);
+       for(i=0; i < LDNS_ANCOUNT(p); i++)
+               (void)ldns_wire2str_rr_scan(&walk, &walk_len, &snull, &sl,
+                       p, plen);
+
+       /* walk through authority section */
+       for(i=0; i < LDNS_NSCOUNT(p); i++) {
+               /* if this is SOA then get serial, skip compressed dname */
+               uint8_t* dstart = walk;
+               size_t dlen = walk_len;
+               (void)ldns_wire2str_dname_scan(&dstart, &dlen, &snull, &sl,
+                       p, plen);
+               if(dlen >= 2 && ldns_read_uint16(dstart) == LDNS_RR_TYPE_SOA) {
+                       /* skip type, class, TTL, rdatalen */
+                       if(dlen < 10)
+                               return 0;
+                       if(dlen < 10 + (size_t)ldns_read_uint16(dstart+8))
+                               return 0;
+                       dstart += 10;
+                       dlen -= 10;
+                       /* check third rdf */
+                       (void)ldns_wire2str_dname_scan(&dstart, &dlen, &snull,
+                               &sl, p, plen);
+                       (void)ldns_wire2str_dname_scan(&dstart, &dlen, &snull,
+                               &sl, p, plen);
+                       if(dlen < 4)
+                               return 0;
+                       verbose(3, "found serial %u in msg. ",
+                               (int)ldns_read_uint32(dstart));
+                       return ldns_read_uint32(dstart);
+               }
+               /* move to next RR */
+               (void)ldns_wire2str_rr_scan(&walk, &walk_len, &snull, &sl,
+                       p, plen);
+       }
+       return 0;
+}
+
+/** get ptr to EDNS OPT record (and remaining length); behind the type u16 */
+static int
+pkt_find_edns_opt(uint8_t** p, size_t* plen)
+{
+       /* walk over the packet with scan routines */
+       uint8_t* w = *p;
+       size_t wlen = *plen, sl=0;
+       char* snull = NULL;
+       uint16_t i;
+
+       if(wlen < LDNS_HEADER_SIZE)
+               return 0;
+       w += LDNS_HEADER_SIZE;
+       wlen -= LDNS_HEADER_SIZE;
+
+       /* skip other records with wire2str_scan */
+       for(i=0; i < LDNS_QDCOUNT(p); i++)
+               (void)ldns_wire2str_rrquestion_scan(&w, &wlen, &snull, &sl,
+                       *p, *plen);
+       for(i=0; i < LDNS_ANCOUNT(p); i++)
+               (void)ldns_wire2str_rr_scan(&w, &wlen, &snull, &sl, *p, *plen);
+       for(i=0; i < LDNS_NSCOUNT(p); i++)
+               (void)ldns_wire2str_rr_scan(&w, &wlen, &snull, &sl, *p, *plen);
+
+       /* walk through additional section */
+       for(i=0; i < LDNS_ARCOUNT(p); i++) {
+               /* if this is OPT then done */
+               uint8_t* dstart = w;
+               size_t dlen = wlen;
+               (void)ldns_wire2str_dname_scan(&dstart, &dlen, &snull, &sl,
+                       *p, *plen);
+               if(dlen >= 2 && ldns_read_uint16(dstart) == LDNS_RR_TYPE_OPT) {
+                       *p = dstart+2;
+                       *plen = dlen-2;
+                       return 1;
+               }
+               /* move to next RR */
+               (void)ldns_wire2str_rr_scan(&w, &wlen, &snull, &sl, *p, *plen);
+       }
+       return 0;
+}
+
+/** return true if the packet has EDNS OPT record */
+static int
+get_has_edns(uint8_t* pkt, size_t len)
+{
+       /* use arguments as temporary variables */
+       return pkt_find_edns_opt(&pkt, &len);
+}
+
+/** return true if the DO flag is set */
+static int
+get_do_flag(uint8_t* pkt, size_t len)
+{
+       uint16_t edns_bits;
+       uint8_t* walk = pkt;
+       size_t walk_len = len;
+       if(pkt_find_edns_opt(&walk, &walk_len)) {
+               return 1;
+       }
+       if(walk_len < 6)
+               return 0; /* malformed */
+       edns_bits = ldns_read_uint16(walk+4);
+       return (int)(edns_bits&LDNS_EDNS_MASK_DO_BIT);
+}
+
+/** zero TTLs in packet */
+static void
+zerottls(uint8_t* pkt, size_t pktlen)
+{
+       uint8_t* walk = pkt;
+       size_t walk_len = pktlen, sl=0;
+       char* snull = NULL;
+       uint16_t i;
+       uint16_t num = LDNS_ANCOUNT(pkt)+LDNS_NSCOUNT(pkt)+LDNS_ARCOUNT(pkt);
+       if(walk_len < LDNS_HEADER_SIZE)
+               return;
+       walk += LDNS_HEADER_SIZE;
+       walk_len -= LDNS_HEADER_SIZE;
+       for(i=0; i < LDNS_QDCOUNT(pkt); i++)
+               (void)ldns_wire2str_rrquestion_scan(&walk, &walk_len,
+                       &snull, &sl, pkt, pktlen);
+       for(i=0; i < num; i++) {
+               /* wipe TTL */
+               uint8_t* dstart = walk;
+               size_t dlen = walk_len;
+               (void)ldns_wire2str_dname_scan(&dstart, &dlen, &snull, &sl,
+                       pkt, pktlen);
+               if(dlen < 8)
+                       return;
+               ldns_write_uint32(dstart+4, 0);
+               /* go to next RR */
+               (void)ldns_wire2str_rr_scan(&walk, &walk_len, &snull, &sl,
+                       pkt, pktlen);
+       }
+}
+
+/** get one line (\n) from a string, move next to after the \n, zero \n */
+static int
+get_line(char** s, char** n)
+{
+       /* at end of string? end */
+       if(*n == NULL || **n == 0)
+               return 0;
+       /* result starts at next string */
+       *s = *n;
+       /* find \n after that */
+       *n = strchr(*s, '\n');
+       if(*n && **n != 0) {
+               /* terminate line */
+               (*n)[0] = 0;
+               (*n)++;
+       }
+       return 1;
+}
+
+/** match two RR sections without ordering */
+static int
+match_noloc_section(char** q, char** nq, char** p, char** np, uint16_t num)
+{
+       /* for max number of RRs in packet */
+       const uint16_t numarray = 3000;
+       char* qlines[numarray], *plines[numarray];
+       uint16_t i, j, numq=0, nump=0;
+       if(num > numarray) fatal_exit("too many RRs");
+       /* gather lines */
+       for(i=0; i<num; i++) {
+               get_line(q, nq);
+               get_line(p, np);
+               qlines[numq++] = *q;
+               plines[nump++] = *p;
+       }
+       /* see if they are all present in the other */
+       for(i=0; i<num; i++) {
+               int found = 0;
+               for(j=0; j<num; j++) {
+                       if(strcmp(qlines[i], plines[j]) == 0) {
+                               found = 1;
+                               break;
+                       }
+               }
+               if(!found) {
+                       verbose(3, "comparenoloc: failed for %s", qlines[i]);
+                       return 0;
+               }
+       }
+       return 1;
+}
+
+/** match two strings for unordered equality of RRs and everything else */
+static int
+match_noloc(char* q, char* p, uint8_t* q_pkt, size_t q_pkt_len,
+       uint8_t* p_pkt, size_t p_pkt_len)
+{
+       char* nq = q, *np = p;
+       /* if no header, compare bytes */
+       if(p_pkt_len < LDNS_HEADER_SIZE || q_pkt_len < LDNS_HEADER_SIZE) {
+               if(p_pkt_len != q_pkt_len) return 0;
+               return memcmp(p, q, p_pkt_len);
+       }
+       /* compare RR counts */
+       if(LDNS_QDCOUNT(p_pkt) != LDNS_QDCOUNT(q_pkt))
+               return 0;
+       if(LDNS_ANCOUNT(p_pkt) != LDNS_ANCOUNT(q_pkt))
+               return 0;
+       if(LDNS_NSCOUNT(p_pkt) != LDNS_NSCOUNT(q_pkt))
+               return 0;
+       if(LDNS_ARCOUNT(p_pkt) != LDNS_ARCOUNT(q_pkt))
+               return 0;
+       /* get a line from both; compare; at sections do section */
+       get_line(&q, &nq);
+       get_line(&p, &np);
+       if(strcmp(q, p) != 0) {
+               /* header line opcode, rcode, id */
+               return 0;
+       }
+       get_line(&q, &nq);
+       get_line(&p, &np);
+       if(strcmp(q, p) != 0) {
+               /* header flags, rr counts */
+               return 0;
+       }
+       /* ;; QUESTION SECTION */
+       get_line(&q, &nq);
+       get_line(&p, &np);
+       if(strcmp(q, p) != 0) return 0;
+       if(!match_noloc_section(&q, &nq, &p, &np, LDNS_QDCOUNT(p_pkt)))
+               return 0;
+
+       /* empty line and ;; ANSWER SECTION */
+       get_line(&q, &nq);
+       get_line(&p, &np);
+       if(strcmp(q, p) != 0) return 0;
+       get_line(&q, &nq);
+       get_line(&p, &np);
+       if(strcmp(q, p) != 0) return 0;
+       if(!match_noloc_section(&q, &nq, &p, &np, LDNS_ANCOUNT(p_pkt)))
+               return 0;
+
+       /* empty line and ;; AUTHORITY SECTION */
+       get_line(&q, &nq);
+       get_line(&p, &np);
+       if(strcmp(q, p) != 0) return 0;
+       get_line(&q, &nq);
+       get_line(&p, &np);
+       if(strcmp(q, p) != 0) return 0;
+       if(!match_noloc_section(&q, &nq, &p, &np, LDNS_NSCOUNT(p_pkt)))
+               return 0;
+
+       /* empty line and ;; ADDITIONAL SECTION */
+       get_line(&q, &nq);
+       get_line(&p, &np);
+       if(strcmp(q, p) != 0) return 0;
+       get_line(&q, &nq);
+       get_line(&p, &np);
+       if(strcmp(q, p) != 0) return 0;
+       if(!match_noloc_section(&q, &nq, &p, &np, LDNS_ARCOUNT(p_pkt)))
+               return 0;
+
+       return 1;
+}
+
+/** lowercase domain name - does not follow compression pointers */
+static void lowercase_dname(uint8_t** p, size_t* remain)
+{
+       unsigned i, llen;
+       if(*remain == 0) return;
+       while(**p != 0) {
+               /* compressed? */
+               if((**p & 0xc0) == 0xc0) {
+                       *p += 2;
+                       *remain -= 2;
+                       return;
+               }
+               llen = (unsigned int)**p;
+               *p += 1;
+               *remain -= 1;
+               if(*remain < llen)
+                       llen = (unsigned int)*remain;
+               for(i=0; i<llen; i++) {
+                       (*p)[i] = (uint8_t)tolower((int)(*p)[i]);
+               }
+               *p += llen;
+               *remain -= llen;
+               if(*remain == 0) return;
+       }
+       /* skip root label */
+       *p += 1;
+       *remain -= 1;
+}
+
+/** lowercase rdata of type */
+static void lowercase_rdata(uint8_t** p, size_t* remain,
+       uint16_t rdatalen, uint16_t t)
+{
+       const ldns_rr_descriptor *desc = ldns_rr_descript(t);
+       uint8_t dname_count = 0;
+       size_t i = 0;
+       size_t rdataremain = rdatalen;
+       if(!desc) {
+               /* unknown type */
+               *p += rdatalen;
+               *remain -= rdatalen;
+               return;
+       }
+       while(dname_count < desc->_dname_count) {
+               ldns_rdf_type f = ldns_rr_descriptor_field_type(desc, i++);
+               if(f == LDNS_RDF_TYPE_DNAME) {
+                       lowercase_dname(p, &rdataremain);
+                       dname_count++;
+               } else if(f == LDNS_RDF_TYPE_STR) {
+                       uint8_t len;
+                       if(rdataremain == 0) return;
+                       len = **p;
+                       *p += len+1;
+                       rdataremain -= len+1;
+               } else {
+                       int len = 0;
+                       switch(f) {
+                       case LDNS_RDF_TYPE_CLASS:
+                       case LDNS_RDF_TYPE_ALG:
+                       case LDNS_RDF_TYPE_INT8:
+                               len = 1;
+                               break;
+                       case LDNS_RDF_TYPE_INT16:
+                       case LDNS_RDF_TYPE_TYPE:
+                       case LDNS_RDF_TYPE_CERT_ALG:
+                               len = 2;
+                               break;
+                       case LDNS_RDF_TYPE_INT32:
+                       case LDNS_RDF_TYPE_TIME:
+                       case LDNS_RDF_TYPE_A:
+                       case LDNS_RDF_TYPE_PERIOD:
+                               len = 4;
+                               break;
+                       case LDNS_RDF_TYPE_TSIGTIME:
+                               len = 6;
+                               break;
+                       case LDNS_RDF_TYPE_AAAA:
+                               len = 16;
+                               break;
+                       default: error("bad rdf type in lowercase %d", (int)f);
+                       }
+                       *p += len;
+                       rdataremain -= len;
+               }
+       }
+       /* skip remainder of rdata */
+       *p += rdataremain;
+       *remain -= rdatalen;
+}
+
+/** lowercase all names in the message */
+static void lowercase_pkt(uint8_t* pkt, size_t pktlen)
+{
+       uint16_t i;
+       uint8_t* p = pkt;
+       size_t remain = pktlen;
+       uint16_t t, rdatalen;
+       if(pktlen < LDNS_HEADER_SIZE)
+               return;
+       p += LDNS_HEADER_SIZE;
+       remain -= LDNS_HEADER_SIZE;
+       for(i=0; i<LDNS_QDCOUNT(pkt); i++) {
+               lowercase_dname(&p, &remain);
+               if(remain < 4) return;
+               p += 4;
+               remain -= 4;
+       }
+       for(i=0; i<LDNS_ANCOUNT(pkt)+LDNS_NSCOUNT(pkt)+LDNS_ARCOUNT(pkt); i++) {
+               lowercase_dname(&p, &remain);
+               if(remain < 10) return;
+               t = ldns_read_uint16(p);
+               rdatalen = ldns_read_uint16(p+8);
+               p += 10;
+               remain -= 10;
+               if(remain < rdatalen) return;
+               lowercase_rdata(&p, &remain, rdatalen, t);
+       }
+}
+
+/** match all of the packet */
+int
+match_all(uint8_t* q, size_t qlen, uint8_t* p, size_t plen, int mttl,
+       int noloc)
+{
+       char* qstr, *pstr;
+       uint8_t* qb = q, *pb = p;
+       int r;
+       /* zero TTLs */
+       qb = memdup(q, qlen);
+       pb = memdup(p, plen);
+       if(!qb || !pb) error("out of memory");
+       if(!mttl) {
+               zerottls(qb, qlen);
+               zerottls(pb, plen);
+       }
+       lowercase_pkt(qb, qlen);
+       lowercase_pkt(pb, plen);
+       qstr = ldns_wire2str_pkt(qb, qlen);
+       pstr = ldns_wire2str_pkt(pb, plen);
+       if(!qstr || !pstr) error("cannot pkt2string");
+       r = (strcmp(qstr, pstr) == 0);
+       if(!r) {
+               /* remove ;; MSG SIZE (at end of string) */
+               char* s = strstr(qstr, ";; MSG SIZE");
+               if(s) *s=0;
+               s = strstr(pstr, ";; MSG SIZE");
+               if(s) *s=0;
+               r = (strcmp(qstr, pstr) == 0);
+               if(!r && !noloc) {
+                       /* we are going to fail see if it is because of EDNS */
+                       char* a = strstr(qstr, "; EDNS");
+                       char* b = strstr(pstr, "; EDNS");
+                       if( (a&&!b) || (b&&!a) ) {
+                               verbose(3, "mismatch in EDNS\n");
+                       }
+               }
+       }
+       if(!r && noloc) {
+               /* check for reordered sections */
+               r = match_noloc(qstr, pstr, q, qlen, p, plen);
+       }
+       free(qstr);
+       free(pstr);
+       free(qb);
+       free(pb);
+       return r;
+}
+
+/** see if domain names are equal */
+static int equal_dname(uint8_t* q, size_t qlen, uint8_t* p, size_t plen)
+{
+       uint8_t* qn = get_qname(q, qlen);
+       uint8_t* pn = get_qname(p, plen);
+       char qs[512], ps[512];
+       size_t qslen = sizeof(qs), pslen = sizeof(ps);
+       char* qss = qs, *pss = ps;
+       if(!qn || !pn)
+               return 0;
+       (void)ldns_wire2str_dname_scan(&qn, &qlen, &qss, &qslen, q, qlen);
+       (void)ldns_wire2str_dname_scan(&pn, &plen, &pss, &pslen, p, plen);
+       return (strcmp(qs, ps) == 0);
+}
+
+/** see if domain names are subdomain q of p */
+static int subdomain_dname(uint8_t* q, size_t qlen, uint8_t* p, size_t plen)
+{
+       /* we use the tostring routines so as to test unbound's routines
+        * with something else */
+       uint8_t* qn = get_qname(q, qlen);
+       uint8_t* pn = get_qname(p, plen);
+       char qs[5120], ps[5120];
+       size_t qslen = sizeof(qs), pslen = sizeof(ps);
+       char* qss = qs, *pss = ps;
+       if(!qn || !pn)
+               return 0;
+       /* decompresses domain names */
+       (void)ldns_wire2str_dname_scan(&qn, &qlen, &qss, &qslen, q, qlen);
+       (void)ldns_wire2str_dname_scan(&pn, &plen, &pss, &pslen, p, plen);
+       /* same: false, (strict subdomain check)??? */
+       if(strcmp(qs, ps) == 0)
+               return 1;
+       /* qs must end in ps, at a dot, without \ in front */
+       qslen = strlen(qs);
+       pslen = strlen(ps);
+       if(qslen > pslen && strcmp(qs + (qslen-pslen), ps) == 0 &&
+               qslen + 2 >= pslen && /* space for label and dot */
+               qs[qslen-pslen-1] == '.') {
+               unsigned int slashcount = 0;
+               size_t i = qslen-pslen-2;
+               while(i>0 && qs[i]=='\\') {
+                       i++;
+                       slashcount++;
+               }
+               if(slashcount%1 == 1) return 0; /* . preceded by \ */
+               return 1;
+       }
+       return 0;
+}
+
+/* finds entry in list, or returns NULL */
+struct entry* 
+find_match(struct entry* entries, uint8_t* query_pkt, size_t len,
+       enum transport_type transport)
+{
+       struct entry* p = entries;
+       uint8_t* reply;
+       size_t rlen;
+       for(p=entries; p; p=p->next) {
+               verbose(3, "comparepkt: ");
+               reply = p->reply_list->reply_pkt;
+               rlen = p->reply_list->reply_len;
+               if(p->match_opcode && get_opcode(query_pkt, len) != 
+                       get_opcode(reply, rlen)) {
+                       verbose(3, "bad opcode\n");
+                       continue;
+               }
+               if(p->match_qtype && get_qtype(query_pkt, len) !=
+                       get_qtype(reply, rlen)) {
+                       verbose(3, "bad qtype %d %d\n", get_qtype(query_pkt, len), get_qtype(reply, rlen));
+                       continue;
+               }
+               if(p->match_qname) {
+                       if(!equal_dname(query_pkt, len, reply, rlen)) {
+                               verbose(3, "bad qname\n");
+                               continue;
+                       }
+               }
+               if(p->match_subdomain) {
+                       if(!subdomain_dname(query_pkt, len, reply, rlen)) {
+                               verbose(3, "bad subdomain\n");
+                               continue;
+                       }
+               }
+               if(p->match_serial && get_serial(query_pkt, len) != p->ixfr_soa_serial) {
+                               verbose(3, "bad serial\n");
+                               continue;
+               }
+               if(p->match_do && !get_do_flag(query_pkt, len)) {
+                       verbose(3, "no DO bit set\n");
+                       continue;
+               }
+               if(p->match_noedns && get_has_edns(query_pkt, len)) {
+                       verbose(3, "bad; EDNS OPT present\n");
+                       continue;
+               }
+               if(p->match_transport != transport_any && p->match_transport != transport) {
+                       verbose(3, "bad transport\n");
+                       continue;
+               }
+               if(p->match_all && !match_all(query_pkt, len, reply, rlen,
+                       (int)p->match_ttl, 0)) {
+                       verbose(3, "bad allmatch\n");
+                       continue;
+               }
+               verbose(3, "match!\n");
+               return p;
+       }
+       return NULL;
+}
+
+void
+adjust_packet(struct entry* match, uint8_t** answer_pkt, size_t *answer_len,
+       uint8_t* query_pkt, size_t query_len)
+{
+       uint8_t* orig = *answer_pkt;
+       size_t origlen = *answer_len;
+       uint8_t* res;
+       size_t reslen;
+
+       /* perform the copy; if possible; must be uncompressed */
+       if(match->copy_query && origlen >= LDNS_HEADER_SIZE &&
+               query_len >= LDNS_HEADER_SIZE && LDNS_QDCOUNT(query_pkt)!=0
+               && LDNS_QDCOUNT(orig)==0) {
+               /* no qname in output packet, insert it */
+               size_t dlen = get_qname_len(query_pkt, query_len);
+               reslen = origlen + dlen + 4;
+               res = (uint8_t*)malloc(reslen);
+               if(!res) {
+                       verbose(1, "out of memory; send without adjust\n");
+                       return;
+               }
+               /* copy the header, query, remainder */
+               memcpy(res, orig, LDNS_HEADER_SIZE);
+               memmove(res+LDNS_HEADER_SIZE, query_pkt+LDNS_HEADER_SIZE,
+                       dlen+4);
+               memmove(res+LDNS_HEADER_SIZE+dlen+4, orig+LDNS_HEADER_SIZE,
+                       reslen-(LDNS_HEADER_SIZE+dlen+4));
+               /* set QDCOUNT */
+               ldns_write_uint16(res+4, 1);
+       } else if(match->copy_query && origlen >= LDNS_HEADER_SIZE &&
+               query_len >= LDNS_HEADER_SIZE && LDNS_QDCOUNT(query_pkt)!=0
+               && get_qname_len(orig, origlen) == 0) {
+               /* QDCOUNT(orig)!=0 but qlen == 0, therefore, an error */
+               verbose(1, "error: malformed qname; send without adjust\n");
+               res = memdup(orig, origlen);
+               reslen = origlen;
+       } else if(match->copy_query && origlen >= LDNS_HEADER_SIZE &&
+               query_len >= LDNS_HEADER_SIZE && LDNS_QDCOUNT(query_pkt)!=0
+               && LDNS_QDCOUNT(orig)!=0) {
+               /* in this case olen != 0 and QDCOUNT(orig)!=0 */
+               /* copy query section */
+               size_t dlen = get_qname_len(query_pkt, query_len);
+               size_t olen = get_qname_len(orig, origlen);
+               reslen = origlen + dlen - olen;
+               res = (uint8_t*)malloc(reslen);
+               if(!res) {
+                       verbose(1, "out of memory; send without adjust\n");
+                       return;
+               }
+               /* copy the header, query, remainder */
+               memcpy(res, orig, LDNS_HEADER_SIZE);
+               memmove(res+LDNS_HEADER_SIZE, query_pkt+LDNS_HEADER_SIZE,
+                       dlen+4);
+               memmove(res+LDNS_HEADER_SIZE+dlen+4,
+                       orig+LDNS_HEADER_SIZE+olen+4,
+                       reslen-(LDNS_HEADER_SIZE+dlen+4));
+       } else {
+               res = memdup(orig, origlen);
+               reslen = origlen;
+       }
+       if(!res) {
+               verbose(1, "out of memory; send without adjust\n");
+               return;
+       }
+       /* copy the ID */
+       if(match->copy_id && reslen >= 2)
+               res[1] = orig[1];
+       if(match->copy_id && reslen >= 1)
+               res[0] = orig[0];
+
+       if(match->sleeptime > 0) {
+               verbose(3, "sleeping for %d seconds\n", match->sleeptime);
+#ifdef HAVE_SLEEP
+               sleep(match->sleeptime);
+#else
+               Sleep(match->sleeptime * 1000);
+#endif
+       }
+       *answer_pkt = res;
+       *answer_len = reslen;
+}
+
+/*
+ * Parses data buffer to a query, finds the correct answer 
+ * and calls the given function for every packet to send.
+ */
+void
+handle_query(uint8_t* inbuf, ssize_t inlen, struct entry* entries, int* count,
+       enum transport_type transport, void (*sendfunc)(uint8_t*, size_t, void*),
+       void* userdata, FILE* verbose_out)
+{
+       struct reply_packet *p;
+       uint8_t *outbuf = NULL;
+       size_t outlen = 0;
+       struct entry* entry = NULL;
+
+       verbose(1, "query %d: id %d: %s %d bytes: ", ++(*count),
+               (int)(inlen>=2?LDNS_ID_WIRE(inbuf):0), 
+               (transport==transport_tcp)?"TCP":"UDP", (int)inlen);
+       if(verbose_out) {
+               char* out = ldns_wire2str_pkt(inbuf, (size_t)inlen);
+               printf("%s\n", out);
+               free(out);
+       }
+
+       /* fill up answer packet */
+       entry = find_match(entries, inbuf, (size_t)inlen, transport);
+       if(!entry || !entry->reply_list) {
+               verbose(1, "no answer packet for this query, no reply.\n");
+               return;
+       }
+       for(p = entry->reply_list; p; p = p->next)
+       {
+               verbose(3, "Answer pkt:\n");
+               if (p->reply_from_hex) {
+                       /* try to adjust the hex packet, if it can be
+                        * parsed, we can use adjust rules. if not,
+                        * send packet literally */
+                       /* still try to adjust ID if others fail */
+                       outlen = ldns_buffer_limit(p->reply_from_hex);
+                       outbuf = ldns_buffer_begin(p->reply_from_hex);
+               } else {
+                       outbuf = p->reply_pkt;
+                       outlen = p->reply_len;
+               }
+               if(!outbuf) {
+                       verbose(1, "out of memory\n");
+                       return;
+               }
+               /* copies outbuf in memory allocation */
+               adjust_packet(entry, &outbuf, &outlen, inbuf, (size_t)inlen);
+               verbose(1, "Answer packet size: %u bytes.\n", (unsigned int)outlen);
+               if(verbose_out) {
+                       char* out = ldns_wire2str_pkt(outbuf, outlen);
+                       printf("%s\n", out);
+                       free(out);
+               }
+               if(p->packet_sleep) {
+                       verbose(3, "sleeping for next packet %d secs\n", 
+                               p->packet_sleep);
+#ifdef HAVE_SLEEP
+                       sleep(p->packet_sleep);
+#else
+                       Sleep(p->packet_sleep * 1000);
+#endif
+                       verbose(3, "wakeup for next packet "
+                               "(slept %d secs)\n", p->packet_sleep);
+               }
+               sendfunc(outbuf, outlen, userdata);
+               free(outbuf);
+               outbuf = NULL;
+               outlen = 0;
+       }
+}
+
+/** delete the list of reply packets */
+void delete_replylist(struct reply_packet* replist)
+{
+       struct reply_packet *p=replist, *np;
+       while(p) {
+               np = p->next;
+               free(p->reply_pkt);
+               ldns_buffer_free(p->reply_from_hex);
+               free(p);
+               p=np;
+       }
+}
+
+void delete_entry(struct entry* list)
+{
+       struct entry *p=list, *np;
+       while(p) {
+               np = p->next;
+               delete_replylist(p->reply_list);
+               free(p);
+               p = np;
+       }
+}
similarity index 82%
rename from testcode/ldns-testpkts.h
rename to testcode/testpkts.h
index 2431e2e1e17dce81cea9346eddb786befcde69d3..77293eedd90a284bc97f5c61ca22a00b6dbece46 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * ldns-testpkts. Data file parse for test packets, and query matching.
+ * testpkts. Data file parse for test packets, and query matching.
  *
  * Data storage for specially crafted replies for testing purposes.
  *
@@ -7,8 +7,10 @@
  * See the file LICENSE for the license
  */
 
-#ifndef LDNS_TESTPKTS_H
-#define LDNS_TESTPKTS_H
+#ifndef TESTPKTS_H
+#define TESTPKTS_H
+struct ldns_buffer;
+struct ldns_file_parse_state;
 
 /**
  * \file
@@ -131,8 +133,6 @@ ENTRY_END
    void verbose(int level, char* format, ...); output function.
 */
 
-#include <ldns/ldns.h>
-
 /** Type of transport, since some entries match based on UDP or TCP of query */
 enum transport_type {transport_any = 0, transport_udp, transport_tcp };
 
@@ -141,9 +141,11 @@ struct reply_packet {
        /** next in list of reply packets, for TCP multiple pkts on wire */
        struct reply_packet* next;
        /** the reply pkt */
-       ldns_pkt* reply;
+       uint8_t* reply_pkt;
+       /** length of reply pkt */
+       size_t reply_len;
        /** or reply pkt in hex if not parsable */
-       ldns_buffer* reply_from_hex;
+       struct ldns_buffer* reply_from_hex;
        /** seconds to sleep before giving packet */
        unsigned int packet_sleep; 
 };
@@ -154,23 +156,23 @@ struct entry {
        /* match */
        /* How to match an incoming query with this canned reply */
        /** match query opcode with answer opcode */
-       bool match_opcode; 
+       uint8_t match_opcode; 
        /** match qtype with answer qtype */
-       bool match_qtype;  
+       uint8_t match_qtype;  
        /** match qname with answer qname */
-       bool match_qname;  
+       uint8_t match_qname;  
        /** match qname as subdomain of answer qname */
-       bool match_subdomain;  
+       uint8_t match_subdomain;  
        /** match SOA serial number, from auth section */
-       bool match_serial; 
+       uint8_t match_serial; 
        /** match all of the packet */
-       bool match_all;
+       uint8_t match_all;
        /** match ttls in the packet */
-       bool match_ttl;
+       uint8_t match_ttl;
        /** match DO bit */
-       bool match_do;
+       uint8_t match_do;
        /** match absence of EDNS OPT record in query */
-       bool match_noedns;
+       uint8_t match_noedns;
        /** match query serial with this value. */
        uint32_t ixfr_soa_serial; 
        /** match on UDP/TCP */
@@ -181,9 +183,9 @@ struct entry {
 
        /** how to adjust the reply packet */
        /** copy over the ID from the query into the answer */
-       bool copy_id; 
+       uint8_t copy_id; 
        /** copy the query nametypeclass from query into the answer */
-       bool copy_query;
+       uint8_t copy_query;
        /** in seconds */
        unsigned int sleeptime; 
 
@@ -211,32 +213,39 @@ void delete_entry(struct entry* list);
  * Read one entry from the data file.
  * @param in: file to read from. Filepos must be at the start of a new line.
  * @param name: name of the file for prettier errors.
- * @param lineno: line number in file, incremented as lines are read.
- *     for prettier errors.
- * @param default_ttl: on first call set to default TTL for entries,
- *     later it stores the $TTL value last seen. Try 3600 first call.
- * @param origin: domain name for origin appending. Can be &NULL on first call.
- *     later it stores the $ORIGIN value last seen. Often &NULL or the zone
- *     name on first call.
- * @param prev_rr: previous rr name for correcter parsing. &NULL on first call.
+ * @param pstate: file parse state with lineno, default_ttl,
+ *     oirigin and prev_rr name.
  * @param skip_whitespace: skip leftside whitespace.
  * @return: The entry read (malloced) or NULL if no entry could be read.
  */
-struct entry* read_entry(FILE* in, const char* name, int *lineno, 
-       uint32_t* default_ttl, ldns_rdf** origin, ldns_rdf** prev_rr,
-       int skip_whitespace);
+struct entry* read_entry(FILE* in, const char* name, 
+       struct ldns_file_parse_state* pstate, int skip_whitespace);
 
 /**
  * finds entry in list, or returns NULL.
  */
-struct entry* find_match(struct entry* entries, ldns_pkt* query_pkt,
-       enum transport_type transport);
+struct entry* find_match(struct entry* entries, uint8_t* query_pkt,
+       size_t query_pkt_len, enum transport_type transport);
+
+/**
+ * match two packets, all must match
+ * @param q: packet 1
+ * @param qlen: length of q.
+ * @param p: packet 2
+ * @param plen: length of p.
+ * @param mttl: if true, ttls must match, if false, ttls do not need to match
+ * @param noloc: if true, rrs may be reordered in their packet-section.
+ *     rrs are then matches without location of the rr being important.
+ * @return true if matched.
+ */
+int match_all(uint8_t* q, size_t qlen, uint8_t* p, size_t plen, int mttl,
+       int noloc);
 
 /**
- * copy & adjust packet 
+ * copy & adjust packet, mallocs a copy.
  */
-void adjust_packet(struct entry* match, ldns_pkt* answer_pkt, 
-       ldns_pkt* query_pkt);
+void adjust_packet(struct entry* match, uint8_t** answer_pkt,
+       size_t* answer_pkt_len, uint8_t* query_pkt, size_t query_pkt_len);
 
 /**
  * Parses data buffer to a query, finds the correct answer 
@@ -256,4 +265,4 @@ void handle_query(uint8_t* inbuf, ssize_t inlen, struct entry* entries,
        void (*sendfunc)(uint8_t*, size_t, void*), void* userdata,
        FILE* verbose_out);
 
-#endif /* LDNS_TESTPKTS_H */
+#endif /* TESTPKTS_H */
index de4106a8081f0a4a164c67be5f930a1cef3940c2..e8ee0f7a8fdf525266c6f3a0f78568113ac00c71 100644 (file)
  */
 
 #include "config.h"
-#include <ldns/rr.h>
 #include "util/log.h"
 #include "util/data/dname.h"
 #include "testcode/unitmain.h"
 #include "validator/val_anchor.h"
+#include "ldns/sbuffer.h"
+#include "ldns/rrdef.h"
 
 /** test empty set */
 static void
index 3dcd8e43c207976548e45d8b34d741aa150b8324..50f082353e4ece315be06326d9ae2dd5d4411758 100644 (file)
  */
 
 #include "config.h"
-#include <ldns/dname.h>
-#include <ldns/host2wire.h>
 #include "util/log.h"
 #include "testcode/unitmain.h"
 #include "util/data/dname.h"
+#include "ldns/sbuffer.h"
+#include "ldns/str2wire.h"
 
 /** put dname into buffer */
 static ldns_buffer*
 dname_to_buf(ldns_buffer* b, const char* str)
 {
-       ldns_rdf* rdf;
-       ldns_status status;
+       int e;
+       size_t len = ldns_buffer_capacity(b);
        ldns_buffer_clear(b);
-       rdf = ldns_dname_new_frm_str(str);      
-       status = ldns_dname2buffer_wire(b, rdf);
-       if(status != LDNS_STATUS_OK)
+       e = ldns_str2wire_dname_buf(str, ldns_buffer_begin(b), &len);
+       if(e != 0)
                fatal_exit("%s ldns: %s", __func__, 
-                       ldns_get_errorstr_by_id(status));
-       ldns_rdf_deep_free(rdf);
+                       ldns_get_errorstr_parse(e));
+       ldns_buffer_set_position(b, len);
        ldns_buffer_flip(b);
        return b;
 }
index be4bed95eeb2b400063b5d5ba2f2859326f21821..40cf29623b08c1a4ad68384f8ac2d67904c4a4fd 100644 (file)
@@ -61,7 +61,8 @@
 #include "nss.h"
 #endif
 
-#include <ldns/ldns.h>
+#include "ldns/rrdef.h"
+#include "ldns/keyraw.h"
 #include "util/log.h"
 #include "testcode/unitmain.h"
 
index 72f9b63a6e09c09a74eaff9b9de02aeb8c45d890..9de6378970c57caa1783b4282b1235edd56ab59a 100644 (file)
@@ -39,7 +39,7 @@
  */
 
 #include "config.h"
-#include <ldns/ldns.h>
+#include <sys/time.h>
 #include "util/log.h"
 #include "testcode/unitmain.h"
 #include "util/data/msgparse.h"
 #include "util/regional.h"
 #include "util/net_help.h"
 #include "testcode/readhex.h"
+#include "testcode/testpkts.h"
+#include "ldns/sbuffer.h"
+#include "ldns/str2wire.h"
+#include "ldns/wire2str.h"
 
 /** verbose message parse unit test */
 static int vbmp = 0;
@@ -62,122 +66,10 @@ static int check_rrsigs = 0;
 /** do not check buffer sameness */
 static int check_nosameness = 0;
 
-/** match two rr lists */
-static int
-match_list(ldns_rr_list* q, ldns_rr_list *p)
-{
-       size_t i;
-       if(ldns_rr_list_rr_count(q) != ldns_rr_list_rr_count(p)) {
-               verbose(3, "rrlistcount different %d %d", 
-                       (int)ldns_rr_list_rr_count(q), 
-                       (int)ldns_rr_list_rr_count(p));
-               return 0;
-       }
-       for(i=0; i<ldns_rr_list_rr_count(q); i++)
-       {
-               if(matches_nolocation) {
-                       if(!ldns_rr_list_contains_rr(p, ldns_rr_list_rr(q, i)))
-                       {
-                               verbose(3, "rr %u not found", (unsigned)i);
-                               return 0;
-                       }
-               } else {
-                       if(ldns_rr_compare(ldns_rr_list_rr(q, i),
-                               ldns_rr_list_rr(p, i)) != 0) {
-                               verbose(3, "rr %u different", (unsigned)i);
-                               return 0;
-                       }
-                       /* and check the ttl */
-                       if(ldns_rr_ttl(ldns_rr_list_rr(q, i)) !=
-                               ldns_rr_ttl(ldns_rr_list_rr(p, i))) {
-                               verbose(3, "rr %u ttl different", (unsigned)i);
-                               return 0;
-                       }
-               }
-       }
-       return 1;
-}
-
-/** match edns sections */
-static int
-match_edns(ldns_pkt* q, ldns_pkt* p)
-{
-       if(ldns_pkt_edns_udp_size(q) != ldns_pkt_edns_udp_size(p))
-               return 0;
-       if(ldns_pkt_edns_extended_rcode(q) != ldns_pkt_edns_extended_rcode(p))
-               return 0;
-       if(ldns_pkt_edns_version(q) != ldns_pkt_edns_version(p))
-               return 0;
-       if(ldns_pkt_edns_do(q) != ldns_pkt_edns_do(p))
-               return 0;
-       if(ldns_pkt_edns_z(q) != ldns_pkt_edns_z(p))
-               return 0;
-       if(ldns_rdf_compare(ldns_pkt_edns_data(q), ldns_pkt_edns_data(p)) != 0)
-               return 0;
-       return 1;
-}
-
-/** compare two booleans */
-static int
-cmp_bool(int x, int y)
-{
-       if(!x && !y) return 0;
-       if(x && y) return 0;
-       if(!x) return -1;
-       return 1;
-}
-
-/** match all of the packet */
-static int
-match_all(ldns_pkt* q, ldns_pkt* p)
-{
-       if(ldns_pkt_get_opcode(q) != ldns_pkt_get_opcode(p))
-       { verbose(3, "allmatch: opcode different"); return 0;}
-       if(ldns_pkt_get_rcode(q) != ldns_pkt_get_rcode(p))
-       { verbose(3, "allmatch: rcode different"); return 0;}
-       if(ldns_pkt_id(q) != ldns_pkt_id(p))
-       { verbose(3, "allmatch: id different"); return 0;}
-       if(cmp_bool(ldns_pkt_qr(q), ldns_pkt_qr(p)) != 0)
-       { verbose(3, "allmatch: qr different"); return 0;}
-       if(cmp_bool(ldns_pkt_aa(q), ldns_pkt_aa(p)) != 0)
-       { verbose(3, "allmatch: aa different"); return 0;}
-       if(cmp_bool(ldns_pkt_tc(q), ldns_pkt_tc(p)) != 0)
-       { verbose(3, "allmatch: tc different"); return 0;}
-       if(cmp_bool(ldns_pkt_rd(q), ldns_pkt_rd(p)) != 0)
-       { verbose(3, "allmatch: rd different"); return 0;}
-       if(cmp_bool(ldns_pkt_cd(q), ldns_pkt_cd(p)) != 0)
-       { verbose(3, "allmatch: cd different"); return 0;}
-       if(cmp_bool(ldns_pkt_ra(q), ldns_pkt_ra(p)) != 0)
-       { verbose(3, "allmatch: ra different"); return 0;}
-       if(cmp_bool(ldns_pkt_ad(q), ldns_pkt_ad(p)) != 0)
-       { verbose(3, "allmatch: ad different"); return 0;}
-       if(ldns_pkt_qdcount(q) != ldns_pkt_qdcount(p))
-       { verbose(3, "allmatch: qdcount different"); return 0;}
-       if(ldns_pkt_ancount(q) != ldns_pkt_ancount(p))
-       { verbose(3, "allmatch: ancount different"); return 0;}
-       if(ldns_pkt_nscount(q) != ldns_pkt_nscount(p))
-       { verbose(3, "allmatch: nscount different"); return 0;}
-       if(ldns_pkt_arcount(q) != ldns_pkt_arcount(p))
-       { verbose(3, "allmatch: arcount different"); return 0;}
-       if(!match_list(ldns_pkt_question(q), ldns_pkt_question(p)))
-       { verbose(3, "allmatch: qd section different"); return 0;}
-       if(!match_list(ldns_pkt_answer(q), ldns_pkt_answer(p)))
-       { verbose(3, "allmatch: an section different"); return 0;}
-       if(!match_list(ldns_pkt_authority(q), ldns_pkt_authority(p)))
-       { verbose(3, "allmatch: ns section different"); return 0;}
-       if(!match_list(ldns_pkt_additional(q), ldns_pkt_additional(p)))
-       { verbose(3, "allmatch: ar section different"); return 0;}
-       if(!match_edns(q, p))
-       { verbose(3, "edns different."); return 0;}
-       return 1;
-}
-
 /** see if buffers contain the same packet */
 static int
 test_buffers(ldns_buffer* pkt, ldns_buffer* out)
 {
-       ldns_pkt* p1=0, *p2=0;
-       ldns_status s1, s2;
        /* check binary same */
        if(ldns_buffer_limit(pkt) == ldns_buffer_limit(out) &&
                memcmp(ldns_buffer_begin(pkt), ldns_buffer_begin(out),
@@ -210,32 +102,42 @@ test_buffers(ldns_buffer* pkt, ldns_buffer* out)
                        }
                }
        }
+
        /* check if it 'means the same' */
-       s1 = ldns_buffer2pkt_wire(&p1, pkt);
-       s2 = ldns_buffer2pkt_wire(&p2, out);
        if(vbmp) {
+               char* s1, *s2;
                log_buf(0, "orig in hex", pkt);
                log_buf(0, "unbound out in hex", out);
                printf("\npacket from unbound (%d):\n", 
                        (int)ldns_buffer_limit(out));
-               ldns_pkt_print(stdout, p2);
+               s1 = ldns_wire2str_pkt(ldns_buffer_begin(out),
+                       ldns_buffer_limit(out));
+               printf("%s\n", s1?s1:"null");
+               free(s1);
 
                printf("\npacket original (%d):\n", 
                        (int)ldns_buffer_limit(pkt));
-               ldns_pkt_print(stdout, p1);
+               s2 = ldns_wire2str_pkt(ldns_buffer_begin(pkt),
+                       ldns_buffer_limit(pkt));
+               printf("%s\n", s2?s2:"null");
+               free(s2);
                printf("\n");
        }
-       if(s1 != s2) {
-               /* oops! */
-               printf("input ldns parse: %s, output ldns parse: %s.\n",
-                       ldns_get_errorstr_by_id(s1), 
-                       ldns_get_errorstr_by_id(s2));
-               unit_assert(0);
+       /* if it had two EDNS sections, skip comparison */
+       if(1) {
+               char* s = ldns_wire2str_pkt(ldns_buffer_begin(pkt),
+                       ldns_buffer_limit(pkt));
+               char* e1 = strstr(s, "; EDNS:");
+               if(e1 && strstr(e1+4, "; EDNS:")) {
+                       free(s);
+                       return 0;
+               }
+               free(s);
        }
        /* compare packets */
-       unit_assert(match_all(p1, p2));
-       ldns_pkt_free(p1);
-       ldns_pkt_free(p2);
+       unit_assert(match_all(ldns_buffer_begin(pkt), ldns_buffer_limit(pkt),
+               ldns_buffer_begin(out), ldns_buffer_limit(out), 1,
+               matches_nolocation));
        return 0;
 }
 
@@ -243,16 +145,20 @@ test_buffers(ldns_buffer* pkt, ldns_buffer* out)
 static void
 checkformerr(ldns_buffer* pkt)
 {
-       ldns_pkt* p;
-       ldns_status status = ldns_buffer2pkt_wire(&p, pkt);
-       if(vbmp) printf("formerr, ldns parse is: %s\n",
-                       ldns_get_errorstr_by_id(status));
-       if(status == LDNS_STATUS_OK) {
+       int status = 0;
+       char* s = ldns_wire2str_pkt(ldns_buffer_begin(pkt),
+               ldns_buffer_limit(pkt));
+       if(!s) fatal_exit("out of memory");
+       if(strstr(s, "Error")) status = 1;
+       if(strstr(s, "error")) status = 1;
+       if(status == 0) {
                printf("Formerr, but ldns gives packet:\n");
-               ldns_pkt_print(stdout, p);
+               printf("%s\n", s);
+               free(s);
                exit(1);
        }
-       unit_assert(status != LDNS_STATUS_OK);
+       free(s);
+       unit_assert(status != 0);
 }
 
 /** performance test message encoding */
@@ -311,8 +217,9 @@ perftestpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
        flags = ntohs(flags);
        ret = reply_info_parse(pkt, alloc, &qi, &rep, region, &edns);
        if(ret != 0) {
-               if(vbmp) printf("parse code %d: %s\n", ret, 
-                       ldns_lookup_by_id(ldns_rcodes, ret)->name);
+               char rbuf[16];
+               ldns_wire2str_rcode_buf(ret, rbuf, sizeof(rbuf));
+               if(vbmp) printf("parse code %d: %s\n", ret, rbuf);
                if(ret == LDNS_RCODE_FORMERR)
                        checkformerr(pkt);
                unit_assert(ret != LDNS_RCODE_SERVFAIL);
@@ -325,37 +232,44 @@ perftestpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
        regional_destroy(region);
 }
 
+/** print packed rrset */
+static void
+print_rrset(struct ub_packed_rrset_key* rrset)
+{
+       struct packed_rrset_data* d = (struct packed_rrset_data*)rrset->
+                       entry.data;
+       char buf[65535];
+       size_t i;
+       for(i=0; i<d->count+d->rrsig_count; i++) {
+               if(!packed_rr_to_string(rrset, i, 0, buf, sizeof(buf)))
+                       printf("failedtoconvert %d\n", (int)i);
+               else
+                       printf("%s\n", buf);
+       }
+}
+
 /** debug print a packet that failed */
 static void
 print_packet_rrsets(struct query_info* qinfo, struct reply_info* rep)
 {
        size_t i;
-       ldns_rr_list* l;
-       ldns_buffer* buf = ldns_buffer_new(65536);
        log_query_info(0, "failed query", qinfo);
        printf(";; ANSWER SECTION (%d rrsets)\n", (int)rep->an_numrrsets);
        for(i=0; i<rep->an_numrrsets; i++) {
-               l = packed_rrset_to_rr_list(rep->rrsets[i], buf);
                printf("; rrset %d\n", (int)i);
-               ldns_rr_list_print(stdout, l);
-               ldns_rr_list_deep_free(l);
+               print_rrset(rep->rrsets[i]);
        }
        printf(";; AUTHORITY SECTION (%d rrsets)\n", (int)rep->ns_numrrsets);
        for(i=rep->an_numrrsets; i<rep->an_numrrsets+rep->ns_numrrsets; i++) {
-               l = packed_rrset_to_rr_list(rep->rrsets[i], buf);
                printf("; rrset %d\n", (int)i);
-               ldns_rr_list_print(stdout, l);
-               ldns_rr_list_deep_free(l);
+               print_rrset(rep->rrsets[i]);
        }
        printf(";; ADDITIONAL SECTION (%d rrsets)\n", (int)rep->ar_numrrsets);
        for(i=rep->an_numrrsets+rep->ns_numrrsets; i<rep->rrset_count; i++) {
-               l = packed_rrset_to_rr_list(rep->rrsets[i], buf);
                printf("; rrset %d\n", (int)i);
-               ldns_rr_list_print(stdout, l);
-               ldns_rr_list_deep_free(l);
+               print_rrset(rep->rrsets[i]);
        }
        printf(";; packet end\n");
-       ldns_buffer_free(buf);
 }
 
 /** check that there is no data element that matches the RRSIG */
@@ -417,8 +331,9 @@ testpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
        flags = ntohs(flags);
        ret = reply_info_parse(pkt, alloc, &qi, &rep, region, &edns);
        if(ret != 0) {
-               if(vbmp) printf("parse code %d: %s\n", ret, 
-                       ldns_lookup_by_id(ldns_rcodes, ret)->name);
+               char rbuf[16];
+               ldns_wire2str_rcode_buf(ret, rbuf, sizeof(rbuf));
+               if(vbmp) printf("parse code %d: %s\n", ret, rbuf);
                if(ret == LDNS_RCODE_FORMERR) {
                        unit_assert(!check_formerr_gone);
                        checkformerr(pkt);
index 686ad0086362eb2da1a346217652b9f3024d35c4..56900f59a1f74f4a3c884bf0991b9d9e5964d759 100644 (file)
@@ -45,6 +45,7 @@
 #include "util/data/dname.h"
 #include "testcode/unitmain.h"
 #include "validator/val_neg.h"
+#include "ldns/rrdef.h"
 
 /** verbose unit test for negative cache */
 static int negverbose = 0;
index d2d268dfdf2dc02f66ef7365379e4facfa6c8a27..a264975135fceb295ad1f929ba5f7ac971ee0335 100644 (file)
@@ -46,7 +46,7 @@
 #include "validator/val_nsec.h"
 #include "validator/val_nsec3.h"
 #include "validator/validator.h"
-#include "testcode/ldns-testpkts.h"
+#include "testcode/testpkts.h"
 #include "util/data/msgreply.h"
 #include "util/data/msgparse.h"
 #include "util/data/dname.h"
 #include "util/net_help.h"
 #include "util/module.h"
 #include "util/config_file.h"
+#include "ldns/sbuffer.h"
+#include "ldns/keyraw.h"
+#include "ldns/str2wire.h"
+#include "ldns/wire2str.h"
 
 /** verbose signature test */
 static int vsig = 0;
@@ -68,20 +72,10 @@ entry_to_buf(struct entry* e, ldns_buffer* pkt)
        if(e->reply_list->reply_from_hex) {
                ldns_buffer_copy(pkt, e->reply_list->reply_from_hex);
        } else {
-               ldns_status status;
-               size_t answer_size;
-               uint8_t* ans = NULL;
-               status = ldns_pkt2wire(&ans, e->reply_list->reply, 
-                       &answer_size);
-               if(status != LDNS_STATUS_OK) {
-                       log_err("could not create reply: %s",
-                               ldns_get_errorstr_by_id(status));
-                       fatal_exit("error in test");
-               }
                ldns_buffer_clear(pkt);
-               ldns_buffer_write(pkt, ans, answer_size);
+               ldns_buffer_write(pkt, e->reply_list->reply_pkt,
+                       e->reply_list->reply_len);
                ldns_buffer_flip(pkt);
-               free(ans);
        }
 }
 
@@ -102,8 +96,9 @@ entry_to_repinfo(struct entry* e, struct alloc_cache* alloc,
        ret = reply_info_parse(pkt, alloc, qi, rep, region, &edns);
        lock_quick_unlock(&alloc->lock);
        if(ret != 0) {
-               printf("parse code %d: %s\n", ret,
-                       ldns_lookup_by_id(ldns_rcodes, ret)->name);
+               char rcode[16];
+               ldns_wire2str_rcode_buf(ret, rcode, sizeof(rcode));
+               printf("parse code %d: %s\n", ret, rcode);
                unit_assert(ret != 0);
        }
 }
@@ -216,9 +211,10 @@ verifytest_entry(struct entry* e, struct alloc_cache* alloc,
 
        regional_free_all(region);
        if(vsig) {
-               printf("verifying pkt:\n");
-               ldns_pkt_print(stdout, e->reply_list->reply);
-               printf("\n");
+               char* s = ldns_wire2str_pkt(e->reply_list->reply_pkt,
+                       e->reply_list->reply_len);
+               printf("verifying pkt:\n%s\n", s?s:"outofmemory");
+               free(s);
        }
        entry_to_repinfo(e, alloc, region, pkt, &qinfo, &rep);
 
@@ -254,9 +250,10 @@ dstest_entry(struct entry* e, struct alloc_cache* alloc,
 
        regional_free_all(region);
        if(vsig) {
-               printf("verifying DS-DNSKEY match:\n");
-               ldns_pkt_print(stdout, e->reply_list->reply);
-               printf("\n");
+               char* s = ldns_wire2str_pkt(e->reply_list->reply_pkt,
+                       e->reply_list->reply_len);
+               printf("verifying DS-DNSKEY match:\n%s\n", s?s:"outofmemory");
+               free(s);
        }
        entry_to_repinfo(e, alloc, region, pkt, &qinfo, &rep);
        ds = find_rrset_type(rep, LDNS_RR_TYPE_DS);
@@ -427,9 +424,10 @@ nsec3_hash_test_entry(struct entry* e, rbtree_t* ct,
        uint8_t* qname;
 
        if(vsig) {
-               printf("verifying NSEC3 hash:\n");
-               ldns_pkt_print(stdout, e->reply_list->reply);
-               printf("\n");
+               char* s = ldns_wire2str_pkt(e->reply_list->reply_pkt,
+                       e->reply_list->reply_len);
+               printf("verifying NSEC3 hash:\n%s\n", s?s:"outofmemory");
+               free(s);
        }
        entry_to_repinfo(e, alloc, region, buf, &qinfo, &rep);
        nsec3 = find_rrset_type(rep, LDNS_RR_TYPE_NSEC3);
index 53698a1077f7111b8459d783c132d9b99b99228e..f7208c264280d81a84b6fe7dd4d1d1ee649f29b9 100644 (file)
@@ -129,7 +129,7 @@ ENTRY_END
 STEP 20 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index b6c620c730f5ec615130da128360e8df3695b834..6245a4addab78cf824370790cf06042605dc5fbe 100644 (file)
@@ -128,7 +128,7 @@ ENTRY_END
 STEP 20 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index f62e28539bf0f1c87a5f490b24ab6b1f1a7b1123..bd7098ea7d1505bb4cba59b25838ec6736287489 100644 (file)
@@ -149,7 +149,7 @@ ENTRY_END
 STEP 20 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index ad46bae8ca64df6bf302c0e3d986ea4d73c9f3ea..792ac9ead69eb6b061e13acc880c2253fcb1256f 100644 (file)
@@ -136,7 +136,7 @@ ENTRY_END
 STEP 20 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index ac8bde0e1da6fbffb23b800fea4d2091f578b957..050edf2a95f0b62ecef6e4750c3d0c0449bc87b9 100644 (file)
@@ -131,7 +131,7 @@ ENTRY_END
 STEP 20 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 16b0a0588ecae9e6ede102503538b8bc5d0e51e6..7ef09e45c5cbaa7779843dd177015b244fcecbad 100644 (file)
@@ -128,7 +128,7 @@ ENTRY_END
 STEP 20 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index b63613a9654d763958d4de4045fe98d78495f2c3..7b8429d8bdf703b19fc341bfd21e14f627dcf67a 100644 (file)
@@ -154,7 +154,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 110f23dd20addf51d8626d2a10add3815b31ee21..1b6e288a19d2f2608f1d4c719120ac48380db94b 100644 (file)
@@ -154,7 +154,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 26a4f309303826b7ac8bbdb45ab0b838b620325e..40075e731a4b617af8e4b73b009f8ddea06e712f 100644 (file)
@@ -138,7 +138,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index b7ea63a8ea44400896d9d2591f7f663526a6bfa8..80d505028322098d5c30fda81ea2abf4d0eeda9f 100644 (file)
@@ -99,7 +99,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index a6ff624ff5a7e7cb3bb238dbf2c9783a64e1ade6..37a097dcabb3a2dda76f24c1d86d94acda72855f 100644 (file)
@@ -120,7 +120,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index a6330b143fba03c4d7d83ca78f19d69f74a84f3b..d461da78a863976d1ad84adfd6386b73a62770a6 100644 (file)
@@ -299,7 +299,7 @@ ENTRY_END
 STEP 43 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 2ca757939737dc37f30c602dbc75ac04779c24e5..dd703f62b1889b7c3030db2c267e1fcc6ceac9ac 100644 (file)
@@ -265,7 +265,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
@@ -292,7 +292,7 @@ ENTRY_END
 STEP 40 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD CD RA NOERROR
+REPLY QR RD CD RA DO NOERROR
 SECTION QUESTION
 ns.blabla.com. IN AAAA
 SECTION ANSWER
index b75e46a7cc1107b71a5a3947447a69aced501b3f..0537757c0de4814f2be4a0c45585b6f47bd14e77 100644 (file)
@@ -475,7 +475,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
@@ -495,7 +495,7 @@ ENTRY_END
 STEP 40 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD CD RA NOERROR
+REPLY QR RD CD RA DO NOERROR
 SECTION QUESTION
 ns.blabla.com. IN AAAA
 SECTION ANSWER
index fd02a8806cd80121fd7bc3ebf7375e4d7c7e4ab3..7638c1b3f67bab811f18cd3dee8a74bc03fae95d 100644 (file)
@@ -385,7 +385,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
@@ -405,7 +405,7 @@ ENTRY_END
 STEP 40 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD CD RA NOERROR
+REPLY QR RD CD RA DO NOERROR
 SECTION QUESTION
 ns.blabla.com. IN AAAA
 SECTION ANSWER
index b0e2cd6b96d8191b01e649b48bfa98567e08a5c4..f77eecba423e59937d36444183f201c1e1e89129 100644 (file)
@@ -577,7 +577,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
@@ -594,7 +594,7 @@ ENTRY_END
 STEP 120 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 ftp.sub.example.com. IN A
 SECTION ANSWER
@@ -614,7 +614,7 @@ ENTRY_END
 STEP 220 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 8a6d3c12e84466168ed8419390899a5b5e4fd010..5aa3d3b04916af26d17c552c877c9466eb8f4fee 100644 (file)
@@ -418,7 +418,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.sub.example.com. IN A
 SECTION ANSWER
@@ -438,7 +438,7 @@ ENTRY_END
 STEP 40 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD CD RA NOERROR
+REPLY QR RD CD RA DO NOERROR
 SECTION QUESTION
 ns.blabla.com. IN AAAA
 SECTION ANSWER
index 1bc41859a331d5703009dcfd8ba42cddb6957962..6a644da1843b6763f5a4fa640a2350aabe99ca37 100644 (file)
@@ -559,7 +559,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
@@ -576,7 +576,7 @@ ENTRY_END
 STEP 120 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 ftp.sub.example.com. IN A
 SECTION ANSWER
@@ -596,7 +596,7 @@ ENTRY_END
 STEP 220 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index cdd0a8707c2de419546cdbba99e49e69558fbc52..bb89c39ac61793a1444c8121f4bedbfd379377e3 100644 (file)
@@ -265,7 +265,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
@@ -292,7 +292,7 @@ ENTRY_END
 STEP 40 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD CD RA NOERROR
+REPLY QR RD CD RA DO NOERROR
 SECTION QUESTION
 ns.blabla.com. IN AAAA
 SECTION ANSWER
index 8ccbb90a7bed00069ff84a00b98c9bd14f0abbdc..9bcb1857d65b2197b50d62a268e18f7760269ddd 100644 (file)
@@ -283,7 +283,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 ENTRY_END
@@ -302,7 +302,7 @@ ENTRY_END
 STEP 120 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 ftp.example.com. IN A
 ENTRY_END
index e01b6863abb1ead95e6170eda6098229162213a2..d9388862ee4b1853eef542bfe774a3ee6603c078 100644 (file)
@@ -258,7 +258,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.net. IN A
 SECTION ANSWER
index 11e3cdaf60769f3b39f63214326840255377783f..365d3611f0a4bda623048236352177e9caf62343 100644 (file)
@@ -333,7 +333,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.net. IN A
 SECTION ANSWER
index 374294637aa18b96d894811f00d9d98f2d3cfc88..78d17f81b50296d70f1adf02624bb8216bd0d87a 100644 (file)
@@ -334,7 +334,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.net. IN A
 SECTION ANSWER
index 3643f8cebf9b4a839cceac8fc61cd1c5999e176e..a921dc9fb2297eb9b49b00e1a720096f9eec6fc2 100644 (file)
@@ -314,7 +314,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.net. IN A
 SECTION ANSWER
index 50e0fc2ec6c4f448c471287acc4d42ae135806fa..3b2d79ad5fbeb6b7902502ecefe4c8b12a50f837 100644 (file)
@@ -268,7 +268,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 example.net. IN DS
 SECTION AUTHORITY
index f466b9131c909669dbf7bb69b10dc11c2e289a41..d8e6aba20a60f0fe545684fcfa9b4ec5c87db106 100644 (file)
@@ -236,7 +236,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.net. IN A
 SECTION ANSWER
index 55aa9278cb427464e2bf4e5f6c5697598a0e61df..a0437750e27fbd1cd4847b33f80cea8244df2b5e 100644 (file)
@@ -250,7 +250,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.net. IN A
 SECTION ANSWER
@@ -274,7 +274,7 @@ ENTRY_END
 STEP 210 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.net. IN A
 SECTION ANSWER
@@ -295,7 +295,7 @@ ENTRY_END
 STEP 230 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 net. IN NS
 SECTION ANSWER
index fc472da192422458a961f7bde43ffd62f7e2e9ac..474d1e9d2c99257078ad5513fe3bb8a2f7375648 100644 (file)
@@ -275,7 +275,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.net. IN A
 SECTION ANSWER
index 866746ad6802d6fcef10d4211333e89f38f05ccc..79bdea774b50ee31453bb924fb51d21c9c5e3a34 100644 (file)
@@ -365,7 +365,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub1.example.net. IN A
 SECTION ANSWER
@@ -388,7 +388,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub2.example.net. IN A
 SECTION ANSWER
index 1b9d7b2ba2f1debb1ce04ac2820c8e7ac9597e23..b0f84db575c80545105620dfaf76697cc7ce5211 100644 (file)
@@ -426,7 +426,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.down.sub.example.net. IN A
 SECTION ANSWER
index 3e4850bc38c4dd8147faf415a990a54b38097b55..47650a060fba908169e164a96bd56da1c85d1803 100644 (file)
@@ -257,7 +257,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.net. IN A
 SECTION ANSWER
index f3789e68c8130cf9d4961fd5cc161c41300277f9..8c89a70d33ba1ef352d9381a567cfd0e74ead912 100644 (file)
@@ -259,7 +259,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.net. IN A
 SECTION ANSWER
index 703acbb9cf4e6ba25d77416773da55dc3421c6d0..d99e7ab6265cd97aac0850490c173afc7b8b33c2 100644 (file)
@@ -199,7 +199,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 875052225700084ea164ab969e7ccd96e1ad6a6f..dd68cf246b189a6ccf03aba3808a175689d2f641 100644 (file)
@@ -115,7 +115,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NXDOMAIN
+REPLY QR RD RA AD DO NXDOMAIN
 SECTION QUESTION
 www.example.com.dlv.isc.org. IN DLV
 SECTION ANSWER
index 1256dfb5e426241361ba91c87e537905b4091393..2242cbb9cc705d8ca65e65107b5dc70488eff9a0 100644 (file)
@@ -133,7 +133,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. ANY A
 SECTION ANSWER
index 857a64e49d95ab86bca996f4beaa3d54f7467bc5..260888c32e51512e9630071051b092458d039171 100644 (file)
@@ -227,7 +227,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 5e5e27a346da61e17084a78ce2397bf6f0ccc2fe..91e76711ee9542df021ed0164fabfd8ffbb5ccc4 100644 (file)
@@ -437,7 +437,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 24de1e367f22b333b6747614fd8be13b24c86e47..c3709dcb1adb413d1e8fc1295c717e76c6104221 100644 (file)
@@ -329,7 +329,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 208b68327ed63c85620e26cda3375b8f9eb77e0e..91243d19fb6db8d13395d4f2c9578b6580a5552a 100644 (file)
@@ -49,7 +49,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NXDOMAIN
+REPLY QR RD RA DO NXDOMAIN
 SECTION QUESTION
 40.30.20.10.in-addr-arpa. IN PTR
 SECTION ANSWER
index 6f0880b5d55ddef86a3230c605bd336e4a5adf8c..a7372976954b47af14442f112f961153a6f400fc 100644 (file)
@@ -49,7 +49,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR AA RD RA NOERROR
+REPLY QR AA RD RA DO NOERROR
 SECTION QUESTION
 mail.example.com. IN A
 SECTION ANSWER
@@ -68,7 +68,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR AA RD RA NOERROR
+REPLY QR AA RD RA DO NOERROR
 SECTION QUESTION
 mail.example.com. IN AAAA
 SECTION ANSWER
index c1c1931aa1f64109684a8c4116148fa8b524256e..6396918f72324684d8fb66b4785c6c67a3b209da 100644 (file)
@@ -59,7 +59,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR AA RD RA NOERROR
+REPLY QR AA RD RA DO NOERROR
 SECTION QUESTION
 mail.example.com. IN A
 SECTION ANSWER
@@ -79,7 +79,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 mail.example.com. IN MX
 SECTION ANSWER
@@ -98,7 +98,7 @@ ENTRY_END
 STEP 50 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN AAAA
 SECTION ANSWER
index 5dfe9b9a9d0166bb72213d1111f0153cc4389725..9fd50df972e93f2af3af1b97b4d2bc143069e46a 100644 (file)
@@ -256,7 +256,7 @@ ENTRY_END
 STEP 3 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all ttl
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -267,7 +267,7 @@ ENTRY_END
 STEP 4 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all ttl
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -291,7 +291,7 @@ ENTRY_END
 STEP 13 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all ttl
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -301,7 +301,7 @@ ENTRY_END
 STEP 14 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all ttl
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -325,7 +325,7 @@ ENTRY_END
 STEP 53 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all ttl
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -335,7 +335,7 @@ ENTRY_END
 STEP 54 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all ttl
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -359,7 +359,7 @@ ENTRY_END
 STEP 103 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all ttl
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -369,7 +369,7 @@ ENTRY_END
 STEP 104 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all ttl
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -396,7 +396,7 @@ ENTRY_END
 STEP 203 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -406,7 +406,7 @@ ENTRY_END
 STEP 204 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -429,7 +429,7 @@ ENTRY_END
 STEP 213 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -439,7 +439,7 @@ ENTRY_END
 STEP 214 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -462,7 +462,7 @@ ENTRY_END
 STEP 223 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -472,7 +472,7 @@ ENTRY_END
 STEP 224 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -495,7 +495,7 @@ ENTRY_END
 STEP 233 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -505,7 +505,7 @@ ENTRY_END
 STEP 234 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -528,7 +528,7 @@ ENTRY_END
 STEP 243 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -538,7 +538,7 @@ ENTRY_END
 STEP 244 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -561,7 +561,7 @@ ENTRY_END
 STEP 253 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -571,7 +571,7 @@ ENTRY_END
 STEP 254 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -594,7 +594,7 @@ ENTRY_END
 STEP 263 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -604,7 +604,7 @@ ENTRY_END
 STEP 264 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -627,7 +627,7 @@ ENTRY_END
 STEP 273 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -637,7 +637,7 @@ ENTRY_END
 STEP 274 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -660,7 +660,7 @@ ENTRY_END
 STEP 283 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -670,7 +670,7 @@ ENTRY_END
 STEP 284 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -693,7 +693,7 @@ ENTRY_END
 STEP 293 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -703,7 +703,7 @@ ENTRY_END
 STEP 294 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -726,7 +726,7 @@ ENTRY_END
 STEP 303 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -736,7 +736,7 @@ ENTRY_END
 STEP 304 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -759,7 +759,7 @@ ENTRY_END
 STEP 313 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -769,7 +769,7 @@ ENTRY_END
 STEP 314 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -792,7 +792,7 @@ ENTRY_END
 STEP 323 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -802,7 +802,7 @@ ENTRY_END
 STEP 324 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -825,7 +825,7 @@ ENTRY_END
 STEP 333 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -835,7 +835,7 @@ ENTRY_END
 STEP 334 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -858,7 +858,7 @@ ENTRY_END
 STEP 343 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -868,7 +868,7 @@ ENTRY_END
 STEP 344 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -891,7 +891,7 @@ ENTRY_END
 STEP 353 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -901,7 +901,7 @@ ENTRY_END
 STEP 354 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -924,7 +924,7 @@ ENTRY_END
 STEP 363 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -934,7 +934,7 @@ ENTRY_END
 STEP 364 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -957,7 +957,7 @@ ENTRY_END
 STEP 373 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -967,7 +967,7 @@ ENTRY_END
 STEP 374 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -990,7 +990,7 @@ ENTRY_END
 STEP 383 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1000,7 +1000,7 @@ ENTRY_END
 STEP 384 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -1023,7 +1023,7 @@ ENTRY_END
 STEP 393 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1033,7 +1033,7 @@ ENTRY_END
 STEP 394 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -1056,7 +1056,7 @@ ENTRY_END
 STEP 403 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1066,7 +1066,7 @@ ENTRY_END
 STEP 404 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -1089,7 +1089,7 @@ ENTRY_END
 STEP 413 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1099,7 +1099,7 @@ ENTRY_END
 STEP 414 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -1122,7 +1122,7 @@ ENTRY_END
 STEP 423 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1132,7 +1132,7 @@ ENTRY_END
 STEP 424 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -1155,7 +1155,7 @@ ENTRY_END
 STEP 433 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1165,7 +1165,7 @@ ENTRY_END
 STEP 434 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -1188,7 +1188,7 @@ ENTRY_END
 STEP 443 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1198,7 +1198,7 @@ ENTRY_END
 STEP 444 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -1221,7 +1221,7 @@ ENTRY_END
 STEP 453 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1231,7 +1231,7 @@ ENTRY_END
 STEP 454 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -1254,7 +1254,7 @@ ENTRY_END
 STEP 463 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1264,7 +1264,7 @@ ENTRY_END
 STEP 464 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -1287,7 +1287,7 @@ ENTRY_END
 STEP 473 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1297,7 +1297,7 @@ ENTRY_END
 STEP 474 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -1320,7 +1320,7 @@ ENTRY_END
 STEP 483 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1330,7 +1330,7 @@ ENTRY_END
 STEP 484 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
@@ -1353,7 +1353,7 @@ ENTRY_END
 STEP 493 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.signed.net. IN A
 SECTION ANSWER
@@ -1363,7 +1363,7 @@ ENTRY_END
 STEP 494 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.unsigned.net. IN A
 SECTION ANSWER
index 8600209462c55ef45e29aad505c7580dfe12be7f..68a0b96cbccc293fc7038ed85312c62092198efc 100644 (file)
@@ -281,7 +281,7 @@ STEP 5 TRAFFIC
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 94122e91581527d1b932da8405c843acbb1dec51..4e1cb9c658eb71220e9145c122ccdb03e32fd5e5 100644 (file)
@@ -18,6 +18,6 @@ SECTION QUESTION
 www.example.net.    IN      A 
 SECTION ANSWER
 www.example.net. 3600  IN  A  192.0.2.91
-www.example.net. 3600  IN  RRSIG  (A 8 3 3600 20300101000000 20000101000000 9033 example.net. kRCOH6u7l0QGy9qpC9 l1sLncJcOKFLJ7GhiUOibu4teYp5VE9RncriShZNz85mwlMgNEa cFYK/lPtPiVYP4bwg== ;{id = 9033}
+www.example.net. 3600  IN  RRSIG  (A 8 3 3600 20300101000000 20000101000000 9033 example.net. kRCOH6u7l0QGy9qpC9 l1sLncJcOKFLJ7GhiUOibu4teYp5VE9RncriShZNz85mwlMgNEa cFYK/lPtPiVYP4bwg== );{id = 9033}
 ENTRY_END
 
index 66a08c524e1519daa8a2e7c7c994081cb8d07af7..be347b11d65c36ec359ad04cddf89195136d3d7a 100644 (file)
@@ -200,7 +200,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NXDOMAIN
+REPLY QR RD RA AD DO NXDOMAIN
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index d69db39d9626e7b8f2ddfc16aaa831f0e7e340c0..de9be6c456ccd12c76a55336175f4ab5678157d9 100644 (file)
@@ -199,7 +199,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NXDOMAIN
+REPLY QR RD RA DO NXDOMAIN
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 150504037cb83831f00fd47c35fc87bc25981385..1eb7778c2d4baecc7689f4119d2d72e7d505e7e3 100644 (file)
@@ -231,7 +231,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 328.0.0.194.example.com. IN A
 SECTION ANSWER
index 8eceaa962805442a6ce015706a10c4a48e36ca2f..257377202bd2ca8071235c298428e4e284f63203 100644 (file)
@@ -233,7 +233,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 328.0.0.194.example.com. IN A
 SECTION ANSWER
index e0f7b1f62d5d63e0e4ca50fe1158ebd586df48c7..4285f49c5c32fbb1e966873410b6743761d5891a 100644 (file)
@@ -161,7 +161,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 example.com. IN ANY
 SECTION ANSWER
index 925bc9240006dd8543fa7d9fbd9e233625233401..e85c14c20b53df6526359b8020d31e81473601ee 100644 (file)
@@ -148,7 +148,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN ANY
 SECTION ANSWER
index 459b11bd3713f84bc33d53c763a5f1b9ab7c0cce..6e94f9a4ee8f2fe310833ceb7a79df1227470a66 100644 (file)
@@ -163,7 +163,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 example.com. IN ANY
 SECTION ANSWER
index 5fd4acc75b10b9260f1fb07fa109a757e9339a33..11d094cdd921a60754f4c28cd8f2a2d5966a9754 100644 (file)
@@ -133,7 +133,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index e8cd24bccb4a328ac0a275aa75f7430e0285298e..af293401b9c7f717f3ad1eb516d80ad26adc574e 100644 (file)
@@ -142,7 +142,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index aa521c30fd56a358a7bf2735ff36e87913daf720..29d1565f3cddf5778ba9c9f74474a10eb3ce4f2f 100644 (file)
@@ -227,7 +227,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
@@ -252,7 +252,7 @@ ENTRY_END
 STEP 40 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.net. IN A
 SECTION ANSWER
@@ -274,7 +274,7 @@ ENTRY_END
 STEP 60 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 insecure.example.com. IN A
 SECTION ANSWER
index 0064ab58047d614a0c6674d9c36d03b66b96b15e..77c50f60b5c0a525f5444709de60c92065da5788 100644 (file)
@@ -157,7 +157,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NXDOMAIN
+REPLY QR RD RA AD DO NXDOMAIN
 SECTION QUESTION
 cname.example.com. IN A
 SECTION ANSWER
index 6676b340f811e5d96f283aa3673dfadac0efb4c0..8d9c2d4fea548c17a802bf0d756aeb536d67e4a5 100644 (file)
@@ -217,7 +217,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NXDOMAIN
+REPLY QR RD RA AD DO NXDOMAIN
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index cd9b8fa22c3e07caf128115c6520ab64abd3d340..66a894f6c2e6518cca9ac1a7d0b0708a45664cdc 100644 (file)
@@ -215,7 +215,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN CNAME
 SECTION ANSWER
index e9c05baed3d86c1a5f68ff9e9cdd7d4f1cb10b04..c3377c2395ca70e650d857320a18e8bfe1f7503a 100644 (file)
@@ -85,7 +85,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN AAAA
 SECTION ANSWER
index c56faede7111811145be4197b924ae049a64bd40..80d1020037ebe5499afc31163c0a48a068415a43 100644 (file)
@@ -87,7 +87,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN AAAA
 SECTION ANSWER
index 12f83e82b4f1445588b55a5a273221ec4d363590..56faf4130125282467b23fcdd0777e879c595261 100644 (file)
@@ -183,7 +183,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 start.example.com. IN A
 SECTION ANSWER
index d9b05c6383e12ad3dd144ef7c2dc3e46d5a1727f..43561d280777f95003979b0042c51e0ff5526f21 100644 (file)
@@ -215,7 +215,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN DNAME
 SECTION ANSWER
index 887c1afc4811d8aceb991bae7e46eb73b515ae30..0a3a323605610aeedd9f0c1f028644d730324e8a 100644 (file)
@@ -398,7 +398,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index aece72a7b6574c684ecb28b3bb2ef2db734560f5..538e9fb88efcd4d5b2db7e2dbcdfe7f91f40d0f8 100644 (file)
@@ -101,7 +101,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN AAAA
 SECTION ANSWER
@@ -123,7 +123,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.org. IN AAAA
 SECTION ANSWER
index e4716180670bffce22cde9fd6ca83fa53b89f5da..b930b5607dd67939e521792b17769e723aebca9f 100644 (file)
@@ -215,7 +215,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 5a263632c192b5036010fdff7bebe47900e632ed..588273fba008cbba656b49d6f45c07065c6f2d07 100644 (file)
@@ -252,7 +252,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 282345307c9f9f3bd20959979b2c45963d7fe9bf..6b32b8da55d848c6ad263c3a0d4ce2de61ed59b3 100644 (file)
@@ -173,7 +173,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 6b041bbc71bd6dd2a28d69992256b684952cee83..cc3315608dbac2e556a36479f30e3b36d112aeec 100644 (file)
@@ -217,7 +217,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NXDOMAIN
+REPLY QR RD RA AD DO NXDOMAIN
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 93853a741f1a3b96e558e8f236972a66b4f4baaa..aa58d07f01bdb73d09001fda951e370eafac1905 100644 (file)
@@ -177,7 +177,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index d4638d07f76c3b526178b2471d4edd74ff956511..0150a7d87c98ec15ee5f30b414716b440f3bad20 100644 (file)
@@ -94,7 +94,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.hud.gov. IN AAAA
 SECTION ANSWER
index d5136d5c5c6affe02340b718e3b605365d79c577..9ff4020a909a53982ea91997ee56ee1da3130414 100644 (file)
@@ -215,7 +215,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index bc1a6945667fb004daa5918d7ac773daf21c422a..6e8ff4f27d8127e8649f1764a35c56c52369f59a 100644 (file)
@@ -251,7 +251,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index feb178b087d8916d648c2c83860871025be3f0ed..114fa705acb814bb2bba8c666e5b5ad45675d8dd 100644 (file)
@@ -219,7 +219,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 97722566bc5f4810d74c64e8623db22984e290b5..9c3928a1931777c75ec11b0cccf8d5a1a6c6a2d4 100644 (file)
@@ -217,7 +217,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 5675c42a5758a2a6b3fd245172b7251b59a9594e..7da96e259f39de76ca901db0444a8d1581049d0e 100644 (file)
@@ -219,7 +219,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NXDOMAIN
+REPLY QR RD RA AD DO NXDOMAIN
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 057cd03119fc8751ca6c9e0a46af571f6fc2d61c..33fbc45511f8d9e8bdb54b624cca7f9e753676b5 100644 (file)
@@ -223,7 +223,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 43b27f1868ea744a28395daf744875ccfca2b903..b5eea56c6b3ee5560814a8c7ce677bf350db7161 100644 (file)
@@ -244,7 +244,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index f564f879d6bca06f6f798128b5f969104654ea75..6264a6d0ee3943dd37a56d8b41d719fc8cafa274 100644 (file)
@@ -218,7 +218,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 6ece5344006e4f1e959a5ac2e90faa11d5b0d6ec..e1e91d4947174c2896e4c62e9af1b2e0c36e0e86 100644 (file)
@@ -220,7 +220,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 3c02768a0d11ae40847c00331469d990abd68fc4..c34b9e0f9d2d4e263e50617ab121d01457fdd088 100644 (file)
@@ -254,7 +254,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 258f1c936c817c1ceeed24c068930a34d3a1447f..0b203d2676f23a8b06b14a74d30030600c9e4cbb 100644 (file)
@@ -143,7 +143,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
@@ -167,7 +167,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 example.com. IN DS
 SECTION AUTHORITY
index 1c9fb77513682b7ccfd1f560e9f8565d3249f02a..95fcf5be7e978c0d722d1ddc0a281c30381fb87e 100644 (file)
@@ -193,7 +193,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index a147b93d682c66bb4bbbb766acec1035e72bb628..d70e2ae29000000fc5031ce39e4d8fb5d865f1dc 100644 (file)
@@ -264,7 +264,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.a.example.com. IN A
 SECTION ANSWER
index 11601e1f2e68c55db21e29a9b80cd0a3ac7f25d0..10bb7fbd4c3ed926bee8846d0eebc73abb017c1e 100644 (file)
@@ -193,7 +193,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 00e6e4e3b50ddeb33024ee6d4d2f7d47833853c4..b8caae2fafaa3656cc2670a15eb1bb7d91cb8443 100644 (file)
@@ -231,7 +231,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 111382d22c4ccf21117d28a8a8de3a6b27b683d4..bbf18118597beac727e0cb1268c0d4c511f2b29b 100644 (file)
@@ -188,7 +188,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 2418c87fd6a3ca708fee50ac3ec4789c7988dc42..ee9a171233d51102e3fe809a8c14a0c3e9658c5f 100644 (file)
@@ -211,7 +211,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 32702034fdfad0c6af535d169c86ad03f05c37ae..5e55b2ba03eb15a9e151589dcb66c9e83ac39ae2 100644 (file)
@@ -246,7 +246,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NXDOMAIN
+REPLY QR RD RA AD DO NXDOMAIN
 SECTION QUESTION
 www.tub.example.com. IN A
 SECTION ANSWER
@@ -271,7 +271,7 @@ ENTRY_END
 STEP 40 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 6235baadcd5cd9710a5ded07c8f6f1da211a6b6e..6ad86271a2a15bdbaabe0a586b7b3857c9522635 100644 (file)
@@ -262,7 +262,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 a.1.2.b.3.4.c.5.6.example.com. IN A
 SECTION ANSWER
index 1d154591fe05067f36fa44c6bcad8071c3a5996e..7d0350f1a1a38ca285959a783b7900812d3c6eb4 100644 (file)
@@ -159,7 +159,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 5bd6db261d7632d4927d5c4b1902e873e3a775a0..3764000f10d8038639db0bffa1fca9bc3c663902 100644 (file)
@@ -160,7 +160,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 3fdd333463dcac53d67e6d1ec24bbfe10dec29c4..26e30f44c957d2de01005c1ac318e206b1525740 100644 (file)
@@ -216,235 +216,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
-SECTION QUESTION
-www.sub.example.com. IN A
-SECTION ANSWER
-www.sub.example.com.   3600    IN      A       11.11.11.11
-www.sub.example.com.    3600    IN      RRSIG   A 5 4 3600 20070926134150 20070829134150 30899 sub.example.com. 0DqqRfRtm7VSEQ4mmBbzrKRqQAay3JAE8DPDGmjtokrrjN9F1G/HxozDV7bjdIh2EChlQea8FPwf/GepJMUVxg== ;{id = 30899}
-SECTION AUTHORITY
-SECTION ADDITIONAL
-ENTRY_END
-
-SCENARIO_END
-; config options
-; The island of trust is at example.com
-server:
-       trust-anchor: "example.com.    3600    IN      DS      2854 3 1 46e4ffc6e9a4793b488954bd3f0cc6af0dfb201b"
-       val-override-date: "20070916134226"
-       target-fetch-policy: "0 0 0 0 0"
-
-stub-zone:
-       name: "."
-       stub-addr: 193.0.14.129         # K.ROOT-SERVERS.NET.
-stub-zone:
-       name: "sub.example.com"
-       stub-addr: 1.2.3.6
-CONFIG_END
-
-SCENARIO_BEGIN Test stub with DS query
-; The stub zone is linked validly with a DS to the public internet zone.
-; unbound just has to be able to ask the DS from the right server (not 
-; from the stub).
-
-; K.ROOT-SERVERS.NET.
-RANGE_BEGIN 0 100
-       ADDRESS 193.0.14.129 
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-. IN NS
-SECTION ANSWER
-. IN NS        K.ROOT-SERVERS.NET.
-SECTION ADDITIONAL
-K.ROOT-SERVERS.NET.    IN      A       193.0.14.129
-ENTRY_END
-
-ENTRY_BEGIN
-MATCH opcode subdomain
-ADJUST copy_id copy_query
-REPLY QR NOERROR
-SECTION QUESTION
-com. IN NS
-SECTION AUTHORITY
-com.   IN NS   a.gtld-servers.net.
-SECTION ADDITIONAL
-a.gtld-servers.net.    IN      A       192.5.6.30
-ENTRY_END
-RANGE_END
-
-; a.gtld-servers.net.
-RANGE_BEGIN 0 100
-       ADDRESS 192.5.6.30
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-com. IN NS
-SECTION ANSWER
-com.    IN NS   a.gtld-servers.net.
-SECTION ADDITIONAL
-a.gtld-servers.net.     IN      A       192.5.6.30
-ENTRY_END
-
-ENTRY_BEGIN
-MATCH opcode subdomain
-ADJUST copy_id copy_query
-REPLY QR NOERROR
-SECTION QUESTION
-example.com. IN A
-SECTION AUTHORITY
-example.com.   IN NS   ns.example.com.
-SECTION ADDITIONAL
-ns.example.com.                IN      A       1.2.3.4
-ENTRY_END
-RANGE_END
-
-; ns.example.com.
-RANGE_BEGIN 0 100
-       ADDRESS 1.2.3.4
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-example.com. IN NS
-SECTION ANSWER
-example.com.    IN NS   ns.example.com.
-example.com.    3600    IN      RRSIG   NS 3 2 3600 20070926134150 20070829134150 2854 example.com. MC0CFQCN+qHdJxoI/2tNKwsb08pra/G7aAIUAWA5sDdJTbrXA1/3OaesGBAO3sI= ;{id = 2854}
-SECTION ADDITIONAL
-ns.example.com.         IN      A       1.2.3.4
-ns.example.com. 3600    IN      RRSIG   A 3 3 3600 20070926135752 20070829135752 2854 example.com. MC0CFQCMSWxVehgOQLoYclB9PIAbNP229AIUeH0vNNGJhjnZiqgIOKvs1EhzqAo= ;{id = 2854}
-ENTRY_END
-
-; response to DNSKEY priming query
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-example.com. IN DNSKEY
-SECTION ANSWER
-example.com.    3600    IN      DNSKEY  256 3 3 ALXLUsWqUrY3JYER3T4TBJII s70j+sDS/UT2QRp61SE7S3E EXopNXoFE73JLRmvpi/UrOO/Vz4Se 6wXv/CYCKjGw06U4WRgR YXcpEhJROyNapmdIKSx hOzfLVE1gqA0PweZR8d tY3aNQSRn3sPpwJr6Mi /PqQKAMMrZ9ckJpf1+b QMOOvxgzz2U1GS18b3y ZKcgTMEaJzd/GZYzi/B N2DzQ0MsrSwYXfsNLFO Bbs8PJMW4LYIxeeOe6rUgkWOF 7CC9Dh/dduQ1QrsJhmZAEFfd6ByYV+ ;{id = 2854 (zsk), size = 1688b}
-example.com. 3600    IN      RRSIG   DNSKEY DSA 2 3600 20070926134150 20070829134150 2854 example.com. MCwCFBQRtlR4BEv9ohi+PGFjp+AHsJuHAhRCvz0shggvnvI88DFnBDCczHUcVA== ;{id = 2854}
-SECTION AUTHORITY
-example.com.   IN NS   ns.example.com.
-example.com.    3600    IN      RRSIG   NS 3 2 3600 20070926134150 20070829134150 2854 example.com. MC0CFQCN+qHdJxoI/2tNKwsb08pra/G7aAIUAWA5sDdJTbrXA1/3OaesGBAO3sI= ;{id = 2854}
-SECTION ADDITIONAL
-ns.example.com.                IN      A       1.2.3.4
-ns.example.com. 3600    IN      RRSIG   A 3 3 3600 20070926135752 20070829135752 2854 example.com. MC0CFQCMSWxVehgOQLoYclB9PIAbNP229AIUeH0vNNGJhjnZiqgIOKvs1EhzqAo= ;{id = 2854}
-ENTRY_END
-
-; response for DS of sub.example.com.
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-sub.example.com. IN DS
-SECTION ANSWER
-sub.example.com.        3600    IN      DS      30899 RSASHA1 1 f7ed618f24d5e5202927e1d27bc2e84a141cb4b3
-sub.example.com.        3600    IN      RRSIG   DS 3 3 3600 20070926134150 20070829134150 2854 example.com. MCwCFCW3ix0GD4BSvNLWIbROCJt5DAW9AhRt/kg9kBKJ20UBUdumrBUHqnskdA== ;{id = 2854}
-SECTION AUTHORITY
-SECTION ADDITIONAL
-ENTRY_END
-
-; response for delegation to sub.example.com.
-ENTRY_BEGIN
-MATCH opcode subdomain
-ADJUST copy_id copy_query
-REPLY QR NOERROR
-SECTION QUESTION
-sub.example.com. IN A
-SECTION ANSWER
-SECTION AUTHORITY
-sub.example.com. IN    NS ns.sub.example.com.
-sub.example.com.        3600    IN      DS      30899 RSASHA1 1 f7ed618f24d5e5202927e1d27bc2e84a141cb4b3
-sub.example.com.        3600    IN      RRSIG   DS 3 3 3600 20070926134150 20070829134150 2854 example.com. MCwCFCW3ix0GD4BSvNLWIbROCJt5DAW9AhRt/kg9kBKJ20UBUdumrBUHqnskdA== ;{id = 2854}
-SECTION ADDITIONAL
-ns.sub.example.com. IN A 1.2.3.6
-ENTRY_END
-
-RANGE_END
-
-; ns.sub.example.com.
-RANGE_BEGIN 0 100
-       ADDRESS 1.2.3.6
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-sub.example.com. IN NS
-SECTION ANSWER
-sub.example.com. IN    NS ns.sub.example.com.
-sub.example.com.        3600    IN      RRSIG   NS 5 3 3600 20070926134150 20070829134150 30899 sub.example.com. wcpHeBILHfo8C9uxMhcW03gcURZeUffiKdSTb50ZjzTHgMNhRyMfpcvSpXEd9548A9UTmWKeLZChfr5Z/glONw== ;{id = 30899}
-SECTION ADDITIONAL
-ns.sub.example.com. IN A 1.2.3.6
-ns.sub.example.com.     3600    IN      RRSIG   A 5 4 3600 20070926134150 20070829134150 30899 sub.example.com. UF7shD/gt1FOp2UHgLTNbPzVykklSXFMEtJ1xD+Hholwf/PIzd7zoaIttIYibNa4fUXCqMg22H9P7MRhfmFe6g== ;{id = 30899}
-ENTRY_END
-
-; response to DNSKEY priming query
-; sub.example.com.        3600    IN      DS      30899 RSASHA1 1 f7ed618f24d5e5202927e1d27bc2e84a141cb4b3
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-sub.example.com. IN DNSKEY
-SECTION ANSWER
-sub.example.com.        3600    IN      DNSKEY  256 3 5 AQPQ41chR9DEHt/aIzIFAqanbDlRflJoRs5yz1jFsoRIT7dWf0r+PeDuewdxkszNH6wnU4QL8pfKFRh5PIYVBLK3 ;{id = 30899 (zsk), size = 512b}
-sub.example.com.        3600    IN      RRSIG   DNSKEY 5 3 3600 20070926134150 20070829134150 30899 sub.example.com. uNGp99iznjD7oOX02XnQbDnbg75UwBHRvZSKYUorTKvPUnCWMHKdRsQ+mf+Fx3GZ+Fz9BVjoCmQqpnfgXLEYqw== ;{id = 30899}
-SECTION AUTHORITY
-sub.example.com. IN    NS ns.sub.example.com.
-sub.example.com.        3600    IN      RRSIG   NS 5 3 3600 20070926134150 20070829134150 30899 sub.example.com. wcpHeBILHfo8C9uxMhcW03gcURZeUffiKdSTb50ZjzTHgMNhRyMfpcvSpXEd9548A9UTmWKeLZChfr5Z/glONw== ;{id = 30899}
-SECTION ADDITIONAL
-ns.sub.example.com. IN A 1.2.3.6
-ns.sub.example.com.     3600    IN      RRSIG   A 5 4 3600 20070926134150 20070829134150 30899 sub.example.com. UF7shD/gt1FOp2UHgLTNbPzVykklSXFMEtJ1xD+Hholwf/PIzd7zoaIttIYibNa4fUXCqMg22H9P7MRhfmFe6g== ;{id = 30899}
-ENTRY_END
-
-; response for qtype DS.  This is not available here.
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR SERVFAIL
-SECTION QUESTION
-sub.example.com. IN DS
-SECTION ANSWER
-SECTION AUTHORITY
-SECTION ADDITIONAL
-ENTRY_END
-
-; response to query of interest
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-www.sub.example.com. IN A
-SECTION ANSWER
-www.sub.example.com. IN A      11.11.11.11
-www.sub.example.com.    3600    IN      RRSIG   A 5 4 3600 20070926134150 20070829134150 30899 sub.example.com. 0DqqRfRtm7VSEQ4mmBbzrKRqQAay3JAE8DPDGmjtokrrjN9F1G/HxozDV7bjdIh2EChlQea8FPwf/GepJMUVxg== ;{id = 30899}
-SECTION AUTHORITY
-SECTION ADDITIONAL
-ENTRY_END
-RANGE_END
-
-STEP 1 QUERY
-ENTRY_BEGIN
-REPLY RD DO
-SECTION QUESTION
-www.sub.example.com. IN A
-ENTRY_END
-
-; recursion happens here.
-STEP 10 CHECK_ANSWER
-ENTRY_BEGIN
-MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 9e9b13f38f329c85a5b494d8d4974bc7903d2456..9b927b20ef4cd018976b6823acda8cbfab3867e0 100644 (file)
@@ -199,7 +199,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 567b6395d7aca49aa3c3746f17c1933321309860..5f044cc2f28bdabd9049d6061e756153f121312d 100644 (file)
@@ -201,7 +201,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
@@ -226,7 +226,7 @@ ENTRY_END
 STEP 40 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 sub.example.com. IN DNSKEY
 SECTION ANSWER
index ba0c6c951d5714c767e8af414baed4933859af09..d834fe64804801e8301fbca544ee39b5469f8582 100644 (file)
@@ -134,7 +134,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 b.example.com. IN DS
 SECTION ANSWER
index a589eefbc29f540712c26b56c6095ed0ee582aeb..c7739e34cba5c02ca7998ea3ac567243c4e72924 100644 (file)
@@ -179,7 +179,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
@@ -199,7 +199,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 sub.example.com. IN DS
 SECTION ANSWER
index 7040af8302a0215ebce149b12a510303539e302f..3f35bbf3b5e73a010e62ee1a50e42d9b64a65293 100644 (file)
@@ -194,7 +194,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
@@ -214,7 +214,7 @@ ENTRY_END
 STEP 15 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NXDOMAIN
+REPLY QR RD RA AD DO NXDOMAIN
 SECTION QUESTION
 nx.example.com. IN A
 SECTION ANSWER
@@ -239,7 +239,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 sub.example.com. IN DS
 SECTION ANSWER
index 8fc8d51eed0ef24c849c2258e86476fce89ae547..1dbbb77842df2ea3f1991550ac6d9f033e2de9fc 100644 (file)
@@ -134,7 +134,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 4eaace1d80577e7a5c2166b41aff883621d60448..467bdf5f353a9df47a2162ff48da7ce694808216 100644 (file)
@@ -136,7 +136,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 0bbc2a9e8ed10c27b344d1d245ba1c3bb462c835..03c09a207dcb0982942e1381c929ae0d3cdf1d54 100644 (file)
@@ -136,7 +136,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 9cd8289c727aca6fb69b71259d64324325f43c42..df3b75e019e4f7ca14acd82d4021a680b4d2ea78 100644 (file)
@@ -150,7 +150,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index dc4971f6fc79fd6872400cc4ab1446b0edb04f98..30e38b605144d4aa8ae3cfbea542192491b40be2 100644 (file)
@@ -134,7 +134,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 375be171b3037c3713ab91d490d4b097822910a8..88d66effb4303dc8d7d9964856578c42d4ad579d 100644 (file)
@@ -131,7 +131,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index c30396af9381087d3a9c773fd9baf2b04b75527a..5eae44f8198ef34525bf517916865b7d2e15a22e 100644 (file)
@@ -152,7 +152,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index b7c300cca0e8328ccb1eefedca58e265a15787c0..dbe1f9aa3cf1dfa945c65552bd6f6c7e50dbc51d 100644 (file)
@@ -112,7 +112,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NXDOMAIN
+REPLY QR RD RA DO NXDOMAIN
 SECTION QUESTION
 a.c.x.w.example. IN A
 SECTION ANSWER
index bf4d223216a0ed2e2e5944202c5dcf13324dbee2..1293aa919d1419eff7f4c4ced3fad38d16f91f2b 100644 (file)
@@ -131,7 +131,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 a.c.x.w.example. IN A
 SECTION ANSWER
index f384792b2c04488a5f06df90728a3868cffb7add..10f51f83ab8f727db478d0bec9b1c80ca4dc361c 100644 (file)
@@ -99,7 +99,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 y.w.example.        IN A
 SECTION ANSWER
index 0700ab67aea460b98b2fd16d5123480f23c267da..11af269672628ca70e0828c04f27bda8cf965ab4 100644 (file)
@@ -99,7 +99,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 ns1.example.        IN MX
 SECTION ANSWER
index 11f1579259ec1ddf2dfb9f0661e4ad1ca3750e53..8311fffc07ba8ee46c2a14f980a04a3f70944a05 100644 (file)
@@ -126,7 +126,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 ns1.example.        IN MX
 SECTION ANSWER
index a3a938a692fe2f3a904c31f93691e634ae40d7c7..5cde1a9bcf6230a22e9d04c9fe45ecc7b12d242e 100644 (file)
@@ -195,7 +195,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 mc.c.example.       IN MX
 SECTION ANSWER
index b52b3925d6725d624d33593c0c6775c6865bc90f..c2468bab82a78690b8e9e0941dc2d2e706c17a51 100644 (file)
@@ -197,7 +197,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 mc.c.example.       IN MX
 SECTION ANSWER
index 4da066c4e0e4cfc375cf4c56f87693d82ba7f497..e3041ecd8ea48672b46ad404f879441b79910664 100644 (file)
@@ -130,7 +130,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 a.z.w.example. IN MX
 SECTION ANSWER
index d12bb8c391038e892a3f5ec2d1d74e1c113bbb38..c8014ed6931e7e4cab9242813bc0cb3e69f13d56 100644 (file)
@@ -133,7 +133,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 a.z.w.example.      IN AAAA
 SECTION ANSWER
index 34c1678560fec19d2e7260a632dc6119843c2b1c..299400569598ad92e76d75c6f30186434f8413e9 100644 (file)
@@ -194,7 +194,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN DS
 SECTION ANSWER
index 7bd0a1a2b17d052a04d7cb0a5edb22c7677fadc8..20ea0619d654bc1c076ea5ab9076cb2ed25ba05a 100644 (file)
@@ -195,7 +195,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 8babfad376731ffc7fa86bc321abf958a783072a..7b38b1a1bdfd8bed06fa2c99c88a0d6a4b8cde09 100644 (file)
@@ -201,7 +201,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NXDOMAIN
+REPLY QR RD RA DO NXDOMAIN
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index d6e92d89ac9a992c3941b229d5a31c8f06b8a608..d8f2c411e482572d0a936109b6e4d2c412c94437 100644 (file)
@@ -181,7 +181,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 start.example.com. IN A
 SECTION ANSWER
index 9ae0fcae3b73c6f6fbb8e7e8be46516fe8c505a2..451bec540a7f28e70cf66015ba347c60feba379e 100644 (file)
@@ -142,7 +142,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NXDOMAIN
+REPLY QR RD RA DO NXDOMAIN
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index d9dfdfabdab5dc94583cdb85968449ffe253f35b..60f20817f80547ebec35631421a27d84707a2ad3 100644 (file)
@@ -205,7 +205,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 8e5a0cf451ad49668491c26fc896a3c36ca37e72..5e265326449e2240eff86a88a8976ea15ca3ba76 100644 (file)
@@ -224,7 +224,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 75dcbed75f37bc055794ac5912ccfac84dcb8c7a..0c4d20ec2040449c3f1a8eb5377f1df3835e70c7 100644 (file)
@@ -206,7 +206,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 2001640c22759ef8e3eacc513034ba3083795af5..1c484eab02fc0e4456ba3394756f29027e2b9b26 100644 (file)
@@ -232,7 +232,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 sub.example.com. IN MX
 SECTION ANSWER
@@ -259,7 +259,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 sub.example.com. IN DS
 SECTION ANSWER
@@ -286,7 +286,7 @@ ENTRY_END
 STEP 50 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NXDOMAIN
+REPLY QR RD RA DO NXDOMAIN
 SECTION QUESTION
 rub.example.com. IN A
 SECTION ANSWER
@@ -314,7 +314,7 @@ ENTRY_END
 STEP 70 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 a.wild.example.com. IN A
 SECTION ANSWER
@@ -341,7 +341,7 @@ ENTRY_END
 STEP 90 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 a.wild.example.com. IN MX
 SECTION ANSWER
index 14462d48a19e503b1e7b66b16a37b00f95e05b68..3ec7ccbdd5cf5b1d4950e5fbfaf98787b6708e5e 100644 (file)
@@ -246,7 +246,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.foo.example.com. IN A
 SECTION ANSWER
@@ -266,7 +266,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index ba8ce2c3cd304ed832c064184ca3e89531e27097..fff0aa7cd4d058e9b5b3df23b510ccb60a96853f 100644 (file)
@@ -140,7 +140,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN ANY
 SECTION ANSWER
index 885dc42a3fe8929ddf007996d7547be921b25b75..434354fb487db90ba2395e7ae67cec578e6f4c38 100644 (file)
@@ -135,7 +135,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NXDOMAIN
+REPLY QR RD RA AD DO NXDOMAIN
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 60ddb1c64efa6a33eab01f26ec43a6b8ca24f3d2..85236e46eb97054d7b0f8e1388a7f70ad523ee13 100644 (file)
@@ -156,7 +156,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NXDOMAIN
+REPLY QR RD RA DO NXDOMAIN
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index f25245a0b6c1db1d02ff235cf049e6b1ba098d55..926712637f968ab66dd4ef543a7f56fc19d64077 100644 (file)
@@ -141,7 +141,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NXDOMAIN
+REPLY QR RD RA DO NXDOMAIN
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 0e958f514900ee54fdbbc70127e7ec57ecffb645..4494c30f5a58766d56e3e6904e728863af562334 100644 (file)
@@ -152,7 +152,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 63b7fd0fdbf20ecd069f63c8737e7267af2effe2..12d3a54819587f61bccc5ec7f10183c4cb4c8292 100644 (file)
@@ -135,7 +135,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 3c45c10a13410a0a33d05112d6cb1a9ce06564f9..c6f8d797a555a48955c9a2db0e3b9d9905e16183 100644 (file)
@@ -133,7 +133,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 355e31581a18daebdab8aa5360e740c1466ae265..f6a04e71ec931371e53b75a6952bebe354f864b3 100644 (file)
@@ -139,7 +139,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 8fc6195caaccace185228db132732519e68cb88f..b451135ffe98126ee347cb20f78b2376db252b89 100644 (file)
@@ -204,7 +204,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 sub.example.com. IN DS
 SECTION ANSWER
index 9a0904084bc08b33d60a1eee611fe5ff34989838..657b4856ea77031b22d26084130429843624e1ad 100644 (file)
@@ -203,7 +203,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 sub.example.com. IN DS
 SECTION ANSWER
index 0d782895618e77f6946bc369974c66897ec07db9..61e7458b0f0f3333eaad5697bf5f8f9534defe65 100644 (file)
@@ -204,7 +204,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 sub.example.com. IN DS
 SECTION ANSWER
index 93e87f619e16655b59d54d643e77a2b173b9e778..eb74817ddbbfeb1658bc31dc9d30a513d0ba3858 100644 (file)
@@ -313,7 +313,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
@@ -334,7 +334,7 @@ ENTRY_END
 STEP 12 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RA AD NOERROR
+REPLY QR RA AD DO NOERROR
 SECTION QUESTION
 bla.example.com. IN A
 SECTION ANSWER
index fe8900c0b886f5670adc0b66916f875f21ccd493..67e44ea75bffe5ecb3630b7d36599ee49fa3ea18 100644 (file)
@@ -157,7 +157,7 @@ ENTRY_END
 STEP 6 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RA AD NOERROR
+REPLY QR RA AD DO NOERROR
 SECTION QUESTION
 bla.example.com. IN A
 SECTION ANSWER
index fd7e7caa5e81aca19f651f921d4152c40065489d..bd829bff44df3c08dcec5267ce05c5786405d000 100644 (file)
@@ -281,7 +281,7 @@ ENTRY_END
 STEP 6 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RA AD NOERROR
+REPLY QR RA AD DO NOERROR
 SECTION QUESTION
 bla.example.com. IN A
 SECTION ANSWER
index 202d07ded4770cbd093dfa73990212689ca288f0..6ea8c1bc3ee77667dae6bb441b57fc22d7208968 100644 (file)
@@ -151,7 +151,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN RRSIG
 SECTION ANSWER
index 28be6142807961a4f05e8e6bb484c641b9350672..d1a5f64b5c5a92415e66069b05bf10340943e4c0 100644 (file)
@@ -198,7 +198,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 5aeb47f93a525c9493db5da923b16c82c4c659e6..310c9bb8875d114e7d22a05831983e0278870dce 100644 (file)
@@ -222,7 +222,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.sub.example.com. IN A
 ENTRY_END
index cfa133b80a7f2799e3874a0d1e527df6cc3e99c5..369bc66e428f68c4270ae1c9ed2bbec752d3b64c 100644 (file)
@@ -69,7 +69,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 proxima.lp0.eu. IN A
 SECTION ANSWER
index a79c5b6d1ae0683cc126f4fff39b5c4d73948743..565c596333dea97ebd564887c361739af2ae5d58 100644 (file)
@@ -215,235 +215,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
-SECTION QUESTION
-www.sub.example.com. IN A
-SECTION ANSWER
-www.sub.example.com.   3600    IN      A       11.11.11.11
-www.sub.example.com.    3600    IN      RRSIG   A 5 4 3600 20070926134150 20070829134150 30899 sub.example.com. 0DqqRfRtm7VSEQ4mmBbzrKRqQAay3JAE8DPDGmjtokrrjN9F1G/HxozDV7bjdIh2EChlQea8FPwf/GepJMUVxg== ;{id = 30899}
-SECTION AUTHORITY
-SECTION ADDITIONAL
-ENTRY_END
-
-SCENARIO_END
-; config options
-; The island of trust is at example.com
-server:
-       trust-anchor: "example.com.    3600    IN      DS      2854 3 1 46e4ffc6e9a4793b488954bd3f0cc6af0dfb201b"
-       val-override-date: "20070916134226"
-       target-fetch-policy: "0 0 0 0 0"
-
-stub-zone:
-       name: "."
-       stub-addr: 193.0.14.129         # K.ROOT-SERVERS.NET.
-stub-zone:
-       name: "sub.example.com"
-       stub-addr: 1.2.3.6
-CONFIG_END
-
-SCENARIO_BEGIN Test stub with DS query
-; The stub zone is linked validly with a DS to the public internet zone.
-; unbound just has to be able to ask the DS from the right server (not 
-; from the stub).
-
-; K.ROOT-SERVERS.NET.
-RANGE_BEGIN 0 100
-       ADDRESS 193.0.14.129 
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-. IN NS
-SECTION ANSWER
-. IN NS        K.ROOT-SERVERS.NET.
-SECTION ADDITIONAL
-K.ROOT-SERVERS.NET.    IN      A       193.0.14.129
-ENTRY_END
-
-ENTRY_BEGIN
-MATCH opcode subdomain
-ADJUST copy_id copy_query
-REPLY QR NOERROR
-SECTION QUESTION
-com. IN NS
-SECTION AUTHORITY
-com.   IN NS   a.gtld-servers.net.
-SECTION ADDITIONAL
-a.gtld-servers.net.    IN      A       192.5.6.30
-ENTRY_END
-RANGE_END
-
-; a.gtld-servers.net.
-RANGE_BEGIN 0 100
-       ADDRESS 192.5.6.30
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-com. IN NS
-SECTION ANSWER
-com.    IN NS   a.gtld-servers.net.
-SECTION ADDITIONAL
-a.gtld-servers.net.     IN      A       192.5.6.30
-ENTRY_END
-
-ENTRY_BEGIN
-MATCH opcode subdomain
-ADJUST copy_id copy_query
-REPLY QR NOERROR
-SECTION QUESTION
-example.com. IN A
-SECTION AUTHORITY
-example.com.   IN NS   ns.example.com.
-SECTION ADDITIONAL
-ns.example.com.                IN      A       1.2.3.4
-ENTRY_END
-RANGE_END
-
-; ns.example.com.
-RANGE_BEGIN 0 100
-       ADDRESS 1.2.3.4
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-example.com. IN NS
-SECTION ANSWER
-example.com.    IN NS   ns.example.com.
-example.com.    3600    IN      RRSIG   NS 3 2 3600 20070926134150 20070829134150 2854 example.com. MC0CFQCN+qHdJxoI/2tNKwsb08pra/G7aAIUAWA5sDdJTbrXA1/3OaesGBAO3sI= ;{id = 2854}
-SECTION ADDITIONAL
-ns.example.com.         IN      A       1.2.3.4
-ns.example.com. 3600    IN      RRSIG   A 3 3 3600 20070926135752 20070829135752 2854 example.com. MC0CFQCMSWxVehgOQLoYclB9PIAbNP229AIUeH0vNNGJhjnZiqgIOKvs1EhzqAo= ;{id = 2854}
-ENTRY_END
-
-; response to DNSKEY priming query
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-example.com. IN DNSKEY
-SECTION ANSWER
-example.com.    3600    IN      DNSKEY  256 3 3 ALXLUsWqUrY3JYER3T4TBJII s70j+sDS/UT2QRp61SE7S3E EXopNXoFE73JLRmvpi/UrOO/Vz4Se 6wXv/CYCKjGw06U4WRgR YXcpEhJROyNapmdIKSx hOzfLVE1gqA0PweZR8d tY3aNQSRn3sPpwJr6Mi /PqQKAMMrZ9ckJpf1+b QMOOvxgzz2U1GS18b3y ZKcgTMEaJzd/GZYzi/B N2DzQ0MsrSwYXfsNLFO Bbs8PJMW4LYIxeeOe6rUgkWOF 7CC9Dh/dduQ1QrsJhmZAEFfd6ByYV+ ;{id = 2854 (zsk), size = 1688b}
-example.com. 3600    IN      RRSIG   DNSKEY DSA 2 3600 20070926134150 20070829134150 2854 example.com. MCwCFBQRtlR4BEv9ohi+PGFjp+AHsJuHAhRCvz0shggvnvI88DFnBDCczHUcVA== ;{id = 2854}
-SECTION AUTHORITY
-example.com.   IN NS   ns.example.com.
-example.com.    3600    IN      RRSIG   NS 3 2 3600 20070926134150 20070829134150 2854 example.com. MC0CFQCN+qHdJxoI/2tNKwsb08pra/G7aAIUAWA5sDdJTbrXA1/3OaesGBAO3sI= ;{id = 2854}
-SECTION ADDITIONAL
-ns.example.com.                IN      A       1.2.3.4
-ns.example.com. 3600    IN      RRSIG   A 3 3 3600 20070926135752 20070829135752 2854 example.com. MC0CFQCMSWxVehgOQLoYclB9PIAbNP229AIUeH0vNNGJhjnZiqgIOKvs1EhzqAo= ;{id = 2854}
-ENTRY_END
-
-; response for DS of sub.example.com.
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-sub.example.com. IN DS
-SECTION ANSWER
-sub.example.com.        3600    IN      DS      30899 RSASHA1 1 f7ed618f24d5e5202927e1d27bc2e84a141cb4b3
-sub.example.com.        3600    IN      RRSIG   DS 3 3 3600 20070926134150 20070829134150 2854 example.com. MCwCFCW3ix0GD4BSvNLWIbROCJt5DAW9AhRt/kg9kBKJ20UBUdumrBUHqnskdA== ;{id = 2854}
-SECTION AUTHORITY
-SECTION ADDITIONAL
-ENTRY_END
-
-; response for delegation to sub.example.com.
-ENTRY_BEGIN
-MATCH opcode subdomain
-ADJUST copy_id copy_query
-REPLY QR NOERROR
-SECTION QUESTION
-sub.example.com. IN A
-SECTION ANSWER
-SECTION AUTHORITY
-sub.example.com. IN    NS ns.sub.example.com.
-sub.example.com.        3600    IN      DS      30899 RSASHA1 1 f7ed618f24d5e5202927e1d27bc2e84a141cb4b3
-sub.example.com.        3600    IN      RRSIG   DS 3 3 3600 20070926134150 20070829134150 2854 example.com. MCwCFCW3ix0GD4BSvNLWIbROCJt5DAW9AhRt/kg9kBKJ20UBUdumrBUHqnskdA== ;{id = 2854}
-SECTION ADDITIONAL
-ns.sub.example.com. IN A 1.2.3.6
-ENTRY_END
-
-RANGE_END
-
-; ns.sub.example.com.
-RANGE_BEGIN 0 100
-       ADDRESS 1.2.3.6
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-sub.example.com. IN NS
-SECTION ANSWER
-sub.example.com. IN    NS ns.sub.example.com.
-sub.example.com.        3600    IN      RRSIG   NS 5 3 3600 20070926134150 20070829134150 30899 sub.example.com. wcpHeBILHfo8C9uxMhcW03gcURZeUffiKdSTb50ZjzTHgMNhRyMfpcvSpXEd9548A9UTmWKeLZChfr5Z/glONw== ;{id = 30899}
-SECTION ADDITIONAL
-ns.sub.example.com. IN A 1.2.3.6
-ns.sub.example.com.     3600    IN      RRSIG   A 5 4 3600 20070926134150 20070829134150 30899 sub.example.com. UF7shD/gt1FOp2UHgLTNbPzVykklSXFMEtJ1xD+Hholwf/PIzd7zoaIttIYibNa4fUXCqMg22H9P7MRhfmFe6g== ;{id = 30899}
-ENTRY_END
-
-; response to DNSKEY priming query
-; sub.example.com.        3600    IN      DS      30899 RSASHA1 1 f7ed618f24d5e5202927e1d27bc2e84a141cb4b3
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-sub.example.com. IN DNSKEY
-SECTION ANSWER
-sub.example.com.        3600    IN      DNSKEY  256 3 5 AQPQ41chR9DEHt/aIzIFAqanbDlRflJoRs5yz1jFsoRIT7dWf0r+PeDuewdxkszNH6wnU4QL8pfKFRh5PIYVBLK3 ;{id = 30899 (zsk), size = 512b}
-sub.example.com.        3600    IN      RRSIG   DNSKEY 5 3 3600 20070926134150 20070829134150 30899 sub.example.com. uNGp99iznjD7oOX02XnQbDnbg75UwBHRvZSKYUorTKvPUnCWMHKdRsQ+mf+Fx3GZ+Fz9BVjoCmQqpnfgXLEYqw== ;{id = 30899}
-SECTION AUTHORITY
-sub.example.com. IN    NS ns.sub.example.com.
-sub.example.com.        3600    IN      RRSIG   NS 5 3 3600 20070926134150 20070829134150 30899 sub.example.com. wcpHeBILHfo8C9uxMhcW03gcURZeUffiKdSTb50ZjzTHgMNhRyMfpcvSpXEd9548A9UTmWKeLZChfr5Z/glONw== ;{id = 30899}
-SECTION ADDITIONAL
-ns.sub.example.com. IN A 1.2.3.6
-ns.sub.example.com.     3600    IN      RRSIG   A 5 4 3600 20070926134150 20070829134150 30899 sub.example.com. UF7shD/gt1FOp2UHgLTNbPzVykklSXFMEtJ1xD+Hholwf/PIzd7zoaIttIYibNa4fUXCqMg22H9P7MRhfmFe6g== ;{id = 30899}
-ENTRY_END
-
-; response for qtype DS.  This is not available here.
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR SERVFAIL
-SECTION QUESTION
-sub.example.com. IN DS
-SECTION ANSWER
-SECTION AUTHORITY
-SECTION ADDITIONAL
-ENTRY_END
-
-; response to query of interest
-ENTRY_BEGIN
-MATCH opcode qtype qname
-ADJUST copy_id
-REPLY QR NOERROR
-SECTION QUESTION
-www.sub.example.com. IN A
-SECTION ANSWER
-www.sub.example.com. IN A      11.11.11.11
-www.sub.example.com.    3600    IN      RRSIG   A 5 4 3600 20070926134150 20070829134150 30899 sub.example.com. 0DqqRfRtm7VSEQ4mmBbzrKRqQAay3JAE8DPDGmjtokrrjN9F1G/HxozDV7bjdIh2EChlQea8FPwf/GepJMUVxg== ;{id = 30899}
-SECTION AUTHORITY
-SECTION ADDITIONAL
-ENTRY_END
-RANGE_END
-
-STEP 1 QUERY
-ENTRY_BEGIN
-REPLY RD DO
-SECTION QUESTION
-www.sub.example.com. IN A
-ENTRY_END
-
-; recursion happens here.
-STEP 10 CHECK_ANSWER
-ENTRY_BEGIN
-MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 21cbdab7d78c1993a48b7ac1836ba63483d8e637..d5dd26040cbdd2335aa991f2baccaf0f82ab9ec5 100644 (file)
@@ -161,7 +161,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 3baeabfd720e0489c0746efdb2d804d0c5df6498..67e5fa23518ff031d3a301223ea43d4ec4e774be 100644 (file)
@@ -162,7 +162,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA SERVFAIL
+REPLY QR RD RA DO SERVFAIL
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 4474d71f85636f4839dca0cdd6da2908a22ecec4..9495c28536fef41a29805e1c1ce5f008a53c5bba 100644 (file)
@@ -107,7 +107,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 k.root-servers.org.  IN      A
 SECTION ANSWER
index e588b8a546ebfbd8aca4049dc6c6832c73ad5231..1a653186a5d41dfce5b6f7c00a30f63cb2fa0894 100644 (file)
@@ -133,7 +133,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.com. IN A
 SECTION ANSWER
index 8157793a34c53a153b2b2a37e2f5abe439b633d2..7e1d8c9d50f0c1031bac52c5d6f7c70a502049c1 100644 (file)
@@ -263,7 +263,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.example.net. IN A
 SECTION ANSWER
index 72e39b812d6031417bf6aaad0c328543d02824fd..adf1ff123442042cbba3cc63f18cc6dd73411340 100644 (file)
@@ -187,7 +187,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index a1871401bad23988d1579b84b922524ddb3947ff..c532da5ee000b9802d148cc4e529ace68ee2d5aa 100644 (file)
@@ -327,7 +327,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 a.b.sub.example.com. IN A
 SECTION ANSWER
@@ -349,7 +349,7 @@ ENTRY_END
 STEP 30 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 a.b.sub.example.com. IN DS
 SECTION AUTHORITY
index 21cb80076555763bb093f8875c0670213cb9b8b7..ff2bc7633dd4fbf94c7a20446bd06676c4386ec3 100644 (file)
@@ -179,7 +179,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index eae1dab787737ccfd3afde8657cabbcbb199e29c..de318397839182bd86ce54c164606ca51bad6174 100644 (file)
@@ -180,7 +180,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA NOERROR
+REPLY QR RD RA DO NOERROR
 SECTION QUESTION
 www.sub.example.com. IN A
 SECTION ANSWER
index 0448ea4c0f42245a554ad507bf39523de187d428..4d82a1b7e156e0b4443b84eef157514e1272a8ea 100644 (file)
@@ -192,7 +192,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 sub.example.com. IN DS
 SECTION ANSWER
index b5b56e9540fa913442a387ab65fc913ffb31868f..d47f03f59a890405b8035c8a4ce4994fa6d77a9f 100644 (file)
@@ -142,7 +142,7 @@ ENTRY_END
 STEP 10 CHECK_ANSWER
 ENTRY_BEGIN
 MATCH all
-REPLY QR RD RA AD NOERROR
+REPLY QR RD RA AD DO NOERROR
 SECTION QUESTION
 *.example.com. IN A
 SECTION ANSWER
index 1e0bd72df833b38f736daf4252c9205d02f554df..a804877d491cda12ff6bb8f63339dcd44c0d838a 100644 (file)
@@ -41,9 +41,8 @@
 
 #include "config.h"
 #include <ctype.h>
-#include <ldns/ldns.h>
+#include <stdarg.h>
 #include "util/log.h"
-
 #include "util/configyyrename.h"
 #include "util/config_file.h"
 #include "util/configparser.h"
@@ -53,6 +52,8 @@
 #include "util/regional.h"
 #include "util/fptr_wlist.h"
 #include "util/data/dname.h"
+#include "ldns/wire2str.h"
+#include "ldns/parseutil.h"
 #ifdef HAVE_GLOB_H
 # include <glob.h>
 #endif
@@ -1085,7 +1086,7 @@ cfg_convert_timeval(const char* str)
        if (tm.tm_min < 0 || tm.tm_min > 59)    return 0;
        if (tm.tm_sec < 0 || tm.tm_sec > 59)    return 0;
        /* call ldns conversion function */
-       t = mktime_from_utc(&tm);
+       t = ldns_mktime_from_utc(&tm);
        return t;
 }
 
@@ -1233,9 +1234,9 @@ strlen_after_chroot(const char* fname, struct config_file* cfg, int use_chdir)
 char*
 fname_after_chroot(const char* fname, struct config_file* cfg, int use_chdir)
 {
-       size_t len = strlen_after_chroot(fname, cfg, use_chdir);
+       size_t len = strlen_after_chroot(fname, cfg, use_chdir)+1;
        int slashit = 0;
-       char* buf = (char*)malloc(len+1);
+       char* buf = (char*)malloc(len);
        if(!buf)
                return NULL;
        buf[0] = 0;
@@ -1243,14 +1244,14 @@ fname_after_chroot(const char* fname, struct config_file* cfg, int use_chdir)
        if(cfg->chrootdir && cfg->chrootdir[0] && 
                strncmp(cfg->chrootdir, fname, strlen(cfg->chrootdir)) == 0) {
                /* already full pathname, return it */
-               strncpy(buf, fname, len);
-               buf[len] = 0;
+               strlcpy(buf, fname, len);
+               buf[len-1] = 0;
                return buf;
        }
        /* chroot */
        if(cfg->chrootdir && cfg->chrootdir[0]) {
                /* start with chrootdir */
-               strncpy(buf, cfg->chrootdir, len);
+               strlcpy(buf, cfg->chrootdir, len);
                slashit = 1;
        }
 #ifdef UB_ON_WINDOWS
@@ -1264,21 +1265,21 @@ fname_after_chroot(const char* fname, struct config_file* cfg, int use_chdir)
        } else if(cfg->directory && cfg->directory[0]) {
                /* prepend chdir */
                if(slashit && cfg->directory[0] != '/')
-                       strncat(buf, "/", len-strlen(buf));
+                       strlcat(buf, "/", len);
                /* is the directory already in the chroot? */
                if(cfg->chrootdir && cfg->chrootdir[0] && 
                        strncmp(cfg->chrootdir, cfg->directory, 
                        strlen(cfg->chrootdir)) == 0)
-                       strncat(buf, cfg->directory+strlen(cfg->chrootdir), 
-                                  len-strlen(buf));
-               else strncat(buf, cfg->directory, len-strlen(buf));
+                       strlcat(buf, cfg->directory+strlen(cfg->chrootdir), 
+                                  len);
+               else strlcat(buf, cfg->directory, len);
                slashit = 1;
        }
        /* fname */
        if(slashit && fname[0] != '/')
-               strncat(buf, "/", len-strlen(buf));
-       strncat(buf, fname, len-strlen(buf));
-       buf[len] = 0;
+               strlcat(buf, "/", len);
+       strlcat(buf, fname, len);
+       buf[len-1] = 0;
        return buf;
 }
 
@@ -1329,7 +1330,7 @@ cfg_parse_local_zone(struct config_file* cfg, const char* val)
                log_err("syntax error: bad zone name: %s", val);
                return 0;
        }
-       strncpy(buf, name, (size_t)(name_end-name));
+       strlcpy(buf, name, sizeof(buf));
        buf[name_end-name] = '\0';
 
        type = last_space_pos(name_end);
@@ -1519,18 +1520,11 @@ char* errinf_to_str(struct module_qstate* qstate)
        size_t left = sizeof(buf);
        struct config_strlist* s;
        char dname[LDNS_MAX_DOMAINLEN+1];
-       char* t = ldns_rr_type2str(qstate->qinfo.qtype);
-       char* c = ldns_rr_class2str(qstate->qinfo.qclass);
-       if(!t || !c) {
-               free(t);
-               free(c);
-               log_err("malloc failure in errinf_to_str");
-               return NULL;
-       }
+       char t[16], c[16];
+       ldns_wire2str_type_buf(qstate->qinfo.qtype, t, sizeof(t));
+       ldns_wire2str_class_buf(qstate->qinfo.qclass, c, sizeof(c));
        dname_str(qstate->qinfo.qname, dname);
        snprintf(p, left, "validation failure <%s %s %s>:", dname, t, c);
-       free(t);
-       free(c);
        left -= strlen(p); p += strlen(p);
        if(!qstate->errinf)
                snprintf(p, left, " misc failure");
@@ -1548,21 +1542,13 @@ void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr)
 {
        char buf[1024];
        char dname[LDNS_MAX_DOMAINLEN+1];
-       char *t, *c;
+       char t[16], c[16];
        if(qstate->env->cfg->val_log_level < 2 || !rr)
                return;
-       t = ldns_rr_type2str(ntohs(rr->rk.type));
-       c = ldns_rr_class2str(ntohs(rr->rk.rrset_class));
-       if(!t || !c) {
-               free(t);
-               free(c);
-               log_err("malloc failure in errinf_rrset");
-               return;
-       }
+       ldns_wire2str_type_buf(ntohs(rr->rk.type), t, sizeof(t));
+       ldns_wire2str_class_buf(ntohs(rr->rk.rrset_class), c, sizeof(c));
        dname_str(rr->rk.dname, dname);
        snprintf(buf, sizeof(buf), "for <%s %s %s>", dname, t, c);
-       free(t);
-       free(c);
        errinf(qstate, buf);
 }
 
index 7d044d09be4d715e77ef8b94b0b3605466d6f72d..d03528786ac47fc19e66a910e253707be497e208 100644 (file)
@@ -1,8 +1,8 @@
-/* A Bison parser, made by GNU Bison 2.6.1.  */
+/* A Bison parser, made by GNU Bison 2.5.  */
 
 /* Bison implementation for Yacc-like parsers in C
    
-      Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
+      Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -44,7 +44,7 @@
 #define YYBISON 1
 
 /* Bison version.  */
-#define YYBISON_VERSION "2.6.1"
+#define YYBISON_VERSION "2.5"
 
 /* Skeleton name.  */
 #define YYSKELETON_NAME "yacc.c"
 /* Pull parsers.  */
 #define YYPULL 1
 
+/* Using locations.  */
+#define YYLSP_NEEDED 0
 
 
 
 /* Copy the first part of user declarations.  */
-/* Line 336 of yacc.c  */
+
+/* Line 268 of yacc.c  */
 #line 38 "./util/configparser.y"
 
 #include "config.h"
@@ -90,16 +93,14 @@ extern struct config_parser_state* cfg_parser;
 #endif
 
 
-/* Line 336 of yacc.c  */
-#line 95 "util/configparser.c"
 
-# ifndef YY_NULL
-#  if defined __cplusplus && 201103L <= __cplusplus
-#   define YY_NULL nullptr
-#  else
-#   define YY_NULL 0
-#  endif
-# endif
+/* Line 268 of yacc.c  */
+#line 99 "util/configparser.c"
+
+/* Enabling traces.  */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
 
 /* Enabling verbose error messages.  */
 #ifdef YYERROR_VERBOSE
@@ -109,18 +110,12 @@ extern struct config_parser_state* cfg_parser;
 # define YYERROR_VERBOSE 0
 #endif
 
-/* In a future release of Bison, this section will be replaced
-   by #include "configparser.h".  */
-#ifndef YY_UTIL_CONFIGPARSER_H
-# define YY_UTIL_CONFIGPARSER_H
-/* Enabling traces.  */
-#ifndef YYDEBUG
-# define YYDEBUG 0
-#endif
-#if YYDEBUG
-extern int yydebug;
+/* Enabling the token table.  */
+#ifndef YYTOKEN_TABLE
+# define YYTOKEN_TABLE 0
 #endif
 
+
 /* Tokens.  */
 #ifndef YYTOKENTYPE
 # define YYTOKENTYPE
@@ -389,45 +384,32 @@ extern int yydebug;
 
 
 
+
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
 {
-/* Line 350 of yacc.c  */
+
+/* Line 293 of yacc.c  */
 #line 64 "./util/configparser.y"
 
        char*   str;
 
 
-/* Line 350 of yacc.c  */
-#line 403 "util/configparser.c"
+
+/* Line 293 of yacc.c  */
+#line 401 "util/configparser.c"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
 #endif
 
-extern YYSTYPE yylval;
-
-#ifdef YYPARSE_PARAM
-#if defined __STDC__ || defined __cplusplus
-int yyparse (void *YYPARSE_PARAM);
-#else
-int yyparse ();
-#endif
-#else /* ! YYPARSE_PARAM */
-#if defined __STDC__ || defined __cplusplus
-int yyparse (void);
-#else
-int yyparse ();
-#endif
-#endif /* ! YYPARSE_PARAM */
-
-#endif /* !YY_UTIL_CONFIGPARSER_H  */
 
 /* Copy the second part of user declarations.  */
 
-/* Line 353 of yacc.c  */
-#line 431 "util/configparser.c"
+
+/* Line 343 of yacc.c  */
+#line 413 "util/configparser.c"
 
 #ifdef short
 # undef short
@@ -533,7 +515,6 @@ YYID (yyi)
 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
      || defined __cplusplus || defined _MSC_VER)
 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-      /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
 #     ifndef EXIT_SUCCESS
 #      define EXIT_SUCCESS 0
 #     endif
@@ -625,20 +606,20 @@ union yyalloc
 #endif
 
 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
-/* Copy COUNT objects from SRC to DST.  The source and destination do
+/* Copy COUNT objects from FROM to TO.  The source and destination do
    not overlap.  */
 # ifndef YYCOPY
 #  if defined __GNUC__ && 1 < __GNUC__
-#   define YYCOPY(Dst, Src, Count) \
-      __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
+#   define YYCOPY(To, From, Count) \
+      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
 #  else
-#   define YYCOPY(Dst, Src, Count)              \
-      do                                        \
-        {                                       \
-          YYSIZE_T yyi;                         \
-          for (yyi = 0; yyi < (Count); yyi++)   \
-            (Dst)[yyi] = (Src)[yyi];            \
-        }                                       \
+#   define YYCOPY(To, From, Count)             \
+      do                                       \
+       {                                       \
+         YYSIZE_T yyi;                         \
+         for (yyi = 0; yyi < (Count); yyi++)   \
+           (To)[yyi] = (From)[yyi];            \
+       }                                       \
       while (YYID (0))
 #  endif
 # endif
@@ -843,7 +824,7 @@ static const yytype_uint16 yyrline[] =
 };
 #endif
 
-#if YYDEBUG || YYERROR_VERBOSE || 0
+#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
 static const char *const yytname[] =
@@ -939,7 +920,7 @@ static const char *const yytname[] =
   "contents_rc", "content_rc", "rc_control_enable", "rc_control_port",
   "rc_control_interface", "rc_server_key_file", "rc_server_cert_file",
   "rc_control_key_file", "rc_control_cert_file", "pythonstart",
-  "contents_py", "content_py", "py_script", YY_NULL
+  "contents_py", "content_py", "py_script", 0
 };
 #endif
 
@@ -1292,18 +1273,17 @@ static const yytype_uint16 yystos[] =
 
 #define YYRECOVERING()  (!!yyerrstatus)
 
-#define YYBACKUP(Token, Value)                                  \
-do                                                              \
-  if (yychar == YYEMPTY)                                        \
-    {                                                           \
-      yychar = (Token);                                         \
-      yylval = (Value);                                         \
-      YYPOPSTACK (yylen);                                       \
-      yystate = *yyssp;                                         \
-      goto yybackup;                                            \
-    }                                                           \
-  else                                                          \
-    {                                                           \
+#define YYBACKUP(Token, Value)                                 \
+do                                                             \
+  if (yychar == YYEMPTY && yylen == 1)                         \
+    {                                                          \
+      yychar = (Token);                                                \
+      yylval = (Value);                                                \
+      YYPOPSTACK (1);                                          \
+      goto yybackup;                                           \
+    }                                                          \
+  else                                                         \
+    {                                                          \
       yyerror (YY_("syntax error: cannot back up")); \
       YYERROR;                                                 \
     }                                                          \
@@ -1313,33 +1293,32 @@ while (YYID (0))
 #define YYTERROR       1
 #define YYERRCODE      256
 
+
 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
    If N is 0, then set CURRENT to the empty location which ends
    the previous symbol: RHS[0] (always defined).  */
 
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
 #ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N)                                \
-    do                                                                  \
-      if (YYID (N))                                                     \
-        {                                                               \
-          (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
-          (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
-          (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
-          (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
-        }                                                               \
-      else                                                              \
-        {                                                               \
-          (Current).first_line   = (Current).last_line   =              \
-            YYRHSLOC (Rhs, 0).last_line;                                \
-          (Current).first_column = (Current).last_column =              \
-            YYRHSLOC (Rhs, 0).last_column;                              \
-        }                                                               \
+# define YYLLOC_DEFAULT(Current, Rhs, N)                               \
+    do                                                                 \
+      if (YYID (N))                                                    \
+       {                                                               \
+         (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
+         (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
+         (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
+         (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
+       }                                                               \
+      else                                                             \
+       {                                                               \
+         (Current).first_line   = (Current).last_line   =              \
+           YYRHSLOC (Rhs, 0).last_line;                                \
+         (Current).first_column = (Current).last_column =              \
+           YYRHSLOC (Rhs, 0).last_column;                              \
+       }                                                               \
     while (YYID (0))
 #endif
 
-#define YYRHSLOC(Rhs, K) ((Rhs)[K])
-
-
 
 /* This macro is provided for backward compatibility. */
 
@@ -1399,8 +1378,6 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep)
     YYSTYPE const * const yyvaluep;
 #endif
 {
-  FILE *yyo = yyoutput;
-  YYUSE (yyo);
   if (!yyvaluep)
     return;
 # ifdef YYPRINT
@@ -1652,12 +1629,12 @@ static int
 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
                 yytype_int16 *yyssp, int yytoken)
 {
-  YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
+  YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]);
   YYSIZE_T yysize = yysize0;
   YYSIZE_T yysize1;
   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
   /* Internationalized format string. */
-  const char *yyformat = YY_NULL;
+  const char *yyformat = 0;
   /* Arguments of yyformat. */
   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
   /* Number of reported tokens (one for the "unexpected", one per
@@ -1717,7 +1694,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
                     break;
                   }
                 yyarg[yycount++] = yytname[yyx];
-                yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
+                yysize1 = yysize + yytnamerr (0, yytname[yyx]);
                 if (! (yysize <= yysize1
                        && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
                   return 2;
@@ -1809,6 +1786,20 @@ yydestruct (yymsg, yytype, yyvaluep)
 }
 
 
+/* Prevent warnings from -Wmissing-prototypes.  */
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
 
 
 /* The lookahead symbol.  */
@@ -1855,7 +1846,7 @@ yyparse ()
        `yyss': related to states.
        `yyvs': related to semantic values.
 
-       Refer to the stacks through separate pointers, to allow yyoverflow
+       Refer to the stacks thru separate pointers, to allow yyoverflow
        to reallocate them elsewhere.  */
 
     /* The state stack.  */
@@ -1909,6 +1900,7 @@ yyparse ()
      The wasted elements are never initialized.  */
   yyssp = yyss;
   yyvsp = yyvs;
+
   goto yysetstate;
 
 /*------------------------------------------------------------.
@@ -2086,7 +2078,8 @@ yyreduce:
   switch (yyn)
     {
         case 9:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 119 "./util/configparser.y"
     { 
                OUTYY(("\nP(server:)\n")); 
@@ -2094,7 +2087,8 @@ yyreduce:
     break;
 
   case 111:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 168 "./util/configparser.y"
     {
                struct config_stub* s;
@@ -2109,7 +2103,8 @@ yyreduce:
     break;
 
   case 119:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 184 "./util/configparser.y"
     {
                struct config_stub* s;
@@ -2124,7 +2119,8 @@ yyreduce:
     break;
 
   case 126:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 200 "./util/configparser.y"
     { 
                OUTYY(("P(server_num_threads:%s)\n", (yyvsp[(2) - (2)].str))); 
@@ -2136,7 +2132,8 @@ yyreduce:
     break;
 
   case 127:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 209 "./util/configparser.y"
     { 
                OUTYY(("P(server_verbosity:%s)\n", (yyvsp[(2) - (2)].str))); 
@@ -2148,7 +2145,8 @@ yyreduce:
     break;
 
   case 128:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 218 "./util/configparser.y"
     { 
                OUTYY(("P(server_statistics_interval:%s)\n", (yyvsp[(2) - (2)].str))); 
@@ -2162,7 +2160,8 @@ yyreduce:
     break;
 
   case 129:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 229 "./util/configparser.y"
     {
                OUTYY(("P(server_statistics_cumulative:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2174,7 +2173,8 @@ yyreduce:
     break;
 
   case 130:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 238 "./util/configparser.y"
     {
                OUTYY(("P(server_extended_statistics:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2186,7 +2186,8 @@ yyreduce:
     break;
 
   case 131:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 247 "./util/configparser.y"
     {
                OUTYY(("P(server_port:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2198,7 +2199,8 @@ yyreduce:
     break;
 
   case 132:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 256 "./util/configparser.y"
     {
                OUTYY(("P(server_interface:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2214,7 +2216,8 @@ yyreduce:
     break;
 
   case 133:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 269 "./util/configparser.y"
     {
                OUTYY(("P(server_outgoing_interface:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2232,7 +2235,8 @@ yyreduce:
     break;
 
   case 134:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 284 "./util/configparser.y"
     {
                OUTYY(("P(server_outgoing_range:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2244,7 +2248,8 @@ yyreduce:
     break;
 
   case 135:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 293 "./util/configparser.y"
     {
                OUTYY(("P(server_outgoing_port_permit:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2256,7 +2261,8 @@ yyreduce:
     break;
 
   case 136:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 302 "./util/configparser.y"
     {
                OUTYY(("P(server_outgoing_port_avoid:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2268,7 +2274,8 @@ yyreduce:
     break;
 
   case 137:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 311 "./util/configparser.y"
     {
                OUTYY(("P(server_outgoing_num_tcp:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2280,7 +2287,8 @@ yyreduce:
     break;
 
   case 138:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 320 "./util/configparser.y"
     {
                OUTYY(("P(server_incoming_num_tcp:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2292,7 +2300,8 @@ yyreduce:
     break;
 
   case 139:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 329 "./util/configparser.y"
     {
                OUTYY(("P(server_interface_automatic:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2304,7 +2313,8 @@ yyreduce:
     break;
 
   case 140:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 338 "./util/configparser.y"
     {
                OUTYY(("P(server_do_ip4:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2316,7 +2326,8 @@ yyreduce:
     break;
 
   case 141:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 347 "./util/configparser.y"
     {
                OUTYY(("P(server_do_ip6:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2328,7 +2339,8 @@ yyreduce:
     break;
 
   case 142:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 356 "./util/configparser.y"
     {
                OUTYY(("P(server_do_udp:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2340,7 +2352,8 @@ yyreduce:
     break;
 
   case 143:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 365 "./util/configparser.y"
     {
                OUTYY(("P(server_do_tcp:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2352,7 +2365,8 @@ yyreduce:
     break;
 
   case 144:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 374 "./util/configparser.y"
     {
                OUTYY(("P(server_tcp_upstream:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2364,7 +2378,8 @@ yyreduce:
     break;
 
   case 145:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 383 "./util/configparser.y"
     {
                OUTYY(("P(server_ssl_upstream:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2376,7 +2391,8 @@ yyreduce:
     break;
 
   case 146:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 392 "./util/configparser.y"
     {
                OUTYY(("P(server_ssl_service_key:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2386,7 +2402,8 @@ yyreduce:
     break;
 
   case 147:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 399 "./util/configparser.y"
     {
                OUTYY(("P(server_ssl_service_pem:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2396,7 +2413,8 @@ yyreduce:
     break;
 
   case 148:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 406 "./util/configparser.y"
     {
                OUTYY(("P(server_ssl_port:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2408,7 +2426,8 @@ yyreduce:
     break;
 
   case 149:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 415 "./util/configparser.y"
     {
                OUTYY(("P(server_do_daemonize:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2420,7 +2439,8 @@ yyreduce:
     break;
 
   case 150:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 424 "./util/configparser.y"
     {
                OUTYY(("P(server_use_syslog:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2437,7 +2457,8 @@ yyreduce:
     break;
 
   case 151:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 438 "./util/configparser.y"
     {
                OUTYY(("P(server_log_time_ascii:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2449,7 +2470,8 @@ yyreduce:
     break;
 
   case 152:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 447 "./util/configparser.y"
     {
                OUTYY(("P(server_log_queries:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2461,7 +2483,8 @@ yyreduce:
     break;
 
   case 153:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 456 "./util/configparser.y"
     {
                OUTYY(("P(server_chroot:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2471,7 +2494,8 @@ yyreduce:
     break;
 
   case 154:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 463 "./util/configparser.y"
     {
                OUTYY(("P(server_username:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2481,7 +2505,8 @@ yyreduce:
     break;
 
   case 155:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 470 "./util/configparser.y"
     {
                OUTYY(("P(server_directory:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2491,7 +2516,8 @@ yyreduce:
     break;
 
   case 156:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 477 "./util/configparser.y"
     {
                OUTYY(("P(server_logfile:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2502,7 +2528,8 @@ yyreduce:
     break;
 
   case 157:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 485 "./util/configparser.y"
     {
                OUTYY(("P(server_pidfile:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2512,7 +2539,8 @@ yyreduce:
     break;
 
   case 158:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 492 "./util/configparser.y"
     {
                OUTYY(("P(server_root_hints:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2522,7 +2550,8 @@ yyreduce:
     break;
 
   case 159:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 499 "./util/configparser.y"
     {
                OUTYY(("P(server_dlv_anchor_file:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2532,7 +2561,8 @@ yyreduce:
     break;
 
   case 160:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 506 "./util/configparser.y"
     {
                OUTYY(("P(server_dlv_anchor:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2542,7 +2572,8 @@ yyreduce:
     break;
 
   case 161:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 513 "./util/configparser.y"
     {
                OUTYY(("P(server_auto_trust_anchor_file:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2553,7 +2584,8 @@ yyreduce:
     break;
 
   case 162:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 521 "./util/configparser.y"
     {
                OUTYY(("P(server_trust_anchor_file:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2564,7 +2596,8 @@ yyreduce:
     break;
 
   case 163:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 529 "./util/configparser.y"
     {
                OUTYY(("P(server_trusted_keys_file:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2575,7 +2608,8 @@ yyreduce:
     break;
 
   case 164:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 537 "./util/configparser.y"
     {
                OUTYY(("P(server_trust_anchor:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2585,7 +2619,8 @@ yyreduce:
     break;
 
   case 165:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 544 "./util/configparser.y"
     {
                OUTYY(("P(server_domain_insecure:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2595,7 +2630,8 @@ yyreduce:
     break;
 
   case 166:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 551 "./util/configparser.y"
     {
                OUTYY(("P(server_hide_identity:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2607,7 +2643,8 @@ yyreduce:
     break;
 
   case 167:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 560 "./util/configparser.y"
     {
                OUTYY(("P(server_hide_version:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2619,7 +2656,8 @@ yyreduce:
     break;
 
   case 168:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 569 "./util/configparser.y"
     {
                OUTYY(("P(server_identity:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2629,7 +2667,8 @@ yyreduce:
     break;
 
   case 169:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 576 "./util/configparser.y"
     {
                OUTYY(("P(server_version:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2639,7 +2678,8 @@ yyreduce:
     break;
 
   case 170:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 583 "./util/configparser.y"
     {
                OUTYY(("P(server_so_rcvbuf:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2650,7 +2690,8 @@ yyreduce:
     break;
 
   case 171:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 591 "./util/configparser.y"
     {
                OUTYY(("P(server_so_sndbuf:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2661,7 +2702,8 @@ yyreduce:
     break;
 
   case 172:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 599 "./util/configparser.y"
     {
                OUTYY(("P(server_edns_buffer_size:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2677,7 +2719,8 @@ yyreduce:
     break;
 
   case 173:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 612 "./util/configparser.y"
     {
                OUTYY(("P(server_msg_buffer_size:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2691,7 +2734,8 @@ yyreduce:
     break;
 
   case 174:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 623 "./util/configparser.y"
     {
                OUTYY(("P(server_msg_cache_size:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2702,7 +2746,8 @@ yyreduce:
     break;
 
   case 175:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 631 "./util/configparser.y"
     {
                OUTYY(("P(server_msg_cache_slabs:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2718,7 +2763,8 @@ yyreduce:
     break;
 
   case 176:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 644 "./util/configparser.y"
     {
                OUTYY(("P(server_num_queries_per_thread:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2730,7 +2776,8 @@ yyreduce:
     break;
 
   case 177:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 653 "./util/configparser.y"
     {
                OUTYY(("P(server_jostle_timeout:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2742,7 +2789,8 @@ yyreduce:
     break;
 
   case 178:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 662 "./util/configparser.y"
     {
                OUTYY(("P(server_rrset_cache_size:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2753,7 +2801,8 @@ yyreduce:
     break;
 
   case 179:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 670 "./util/configparser.y"
     {
                OUTYY(("P(server_rrset_cache_slabs:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2769,7 +2818,8 @@ yyreduce:
     break;
 
   case 180:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 683 "./util/configparser.y"
     {
                OUTYY(("P(server_infra_host_ttl:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2781,7 +2831,8 @@ yyreduce:
     break;
 
   case 181:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 692 "./util/configparser.y"
     {
                OUTYY(("P(server_infra_lame_ttl:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2792,7 +2843,8 @@ yyreduce:
     break;
 
   case 182:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 700 "./util/configparser.y"
     {
                OUTYY(("P(server_infra_cache_numhosts:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2804,7 +2856,8 @@ yyreduce:
     break;
 
   case 183:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 709 "./util/configparser.y"
     {
                OUTYY(("P(server_infra_cache_lame_size:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2815,7 +2868,8 @@ yyreduce:
     break;
 
   case 184:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 717 "./util/configparser.y"
     {
                OUTYY(("P(server_infra_cache_slabs:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2831,7 +2885,8 @@ yyreduce:
     break;
 
   case 185:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 730 "./util/configparser.y"
     {
                OUTYY(("P(server_target_fetch_policy:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2841,7 +2896,8 @@ yyreduce:
     break;
 
   case 186:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 737 "./util/configparser.y"
     {
                OUTYY(("P(server_harden_short_bufsize:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2854,7 +2910,8 @@ yyreduce:
     break;
 
   case 187:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 747 "./util/configparser.y"
     {
                OUTYY(("P(server_harden_large_queries:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2867,7 +2924,8 @@ yyreduce:
     break;
 
   case 188:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 757 "./util/configparser.y"
     {
                OUTYY(("P(server_harden_glue:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2880,7 +2938,8 @@ yyreduce:
     break;
 
   case 189:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 767 "./util/configparser.y"
     {
                OUTYY(("P(server_harden_dnssec_stripped:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2893,7 +2952,8 @@ yyreduce:
     break;
 
   case 190:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 777 "./util/configparser.y"
     {
                OUTYY(("P(server_harden_below_nxdomain:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2906,7 +2966,8 @@ yyreduce:
     break;
 
   case 191:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 787 "./util/configparser.y"
     {
                OUTYY(("P(server_harden_referral_path:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2919,7 +2980,8 @@ yyreduce:
     break;
 
   case 192:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 797 "./util/configparser.y"
     {
                OUTYY(("P(server_use_caps_for_id:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2932,7 +2994,8 @@ yyreduce:
     break;
 
   case 193:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 807 "./util/configparser.y"
     {
                OUTYY(("P(server_private_address:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2942,7 +3005,8 @@ yyreduce:
     break;
 
   case 194:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 814 "./util/configparser.y"
     {
                OUTYY(("P(server_private_domain:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2952,7 +3016,8 @@ yyreduce:
     break;
 
   case 195:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 821 "./util/configparser.y"
     {
                OUTYY(("P(server_prefetch:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2964,7 +3029,8 @@ yyreduce:
     break;
 
   case 196:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 830 "./util/configparser.y"
     {
                OUTYY(("P(server_prefetch_key:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2976,7 +3042,8 @@ yyreduce:
     break;
 
   case 197:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 839 "./util/configparser.y"
     {
                OUTYY(("P(server_unwanted_reply_threshold:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2988,7 +3055,8 @@ yyreduce:
     break;
 
   case 198:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 848 "./util/configparser.y"
     {
                OUTYY(("P(server_do_not_query_address:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -2998,7 +3066,8 @@ yyreduce:
     break;
 
   case 199:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 855 "./util/configparser.y"
     {
                OUTYY(("P(server_do_not_query_localhost:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3011,7 +3080,8 @@ yyreduce:
     break;
 
   case 200:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 865 "./util/configparser.y"
     {
                OUTYY(("P(server_access_control:%s %s)\n", (yyvsp[(2) - (3)].str), (yyvsp[(3) - (3)].str)));
@@ -3028,7 +3098,8 @@ yyreduce:
     break;
 
   case 201:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 879 "./util/configparser.y"
     {
                OUTYY(("P(server_module_conf:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3038,7 +3109,8 @@ yyreduce:
     break;
 
   case 202:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 886 "./util/configparser.y"
     {
                OUTYY(("P(server_val_override_date:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3059,7 +3131,8 @@ yyreduce:
     break;
 
   case 203:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 904 "./util/configparser.y"
     {
                OUTYY(("P(server_val_sig_skew_min:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3075,7 +3148,8 @@ yyreduce:
     break;
 
   case 204:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 917 "./util/configparser.y"
     {
                OUTYY(("P(server_val_sig_skew_max:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3091,7 +3165,8 @@ yyreduce:
     break;
 
   case 205:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 930 "./util/configparser.y"
     {
                OUTYY(("P(server_cache_max_ttl:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3103,7 +3178,8 @@ yyreduce:
     break;
 
   case 206:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 939 "./util/configparser.y"
     {
                OUTYY(("P(server_cache_min_ttl:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3115,7 +3191,8 @@ yyreduce:
     break;
 
   case 207:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 948 "./util/configparser.y"
     {
                OUTYY(("P(server_bogus_ttl:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3127,7 +3204,8 @@ yyreduce:
     break;
 
   case 208:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 957 "./util/configparser.y"
     {
                OUTYY(("P(server_val_clean_additional:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3140,7 +3218,8 @@ yyreduce:
     break;
 
   case 209:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 967 "./util/configparser.y"
     {
                OUTYY(("P(server_val_permissive_mode:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3153,7 +3232,8 @@ yyreduce:
     break;
 
   case 210:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 977 "./util/configparser.y"
     {
                OUTYY(("P(server_ignore_cd_flag:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3165,7 +3245,8 @@ yyreduce:
     break;
 
   case 211:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 986 "./util/configparser.y"
     {
                OUTYY(("P(server_val_log_level:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3177,7 +3258,8 @@ yyreduce:
     break;
 
   case 212:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 995 "./util/configparser.y"
     {
                OUTYY(("P(server_val_nsec3_keysize_iterations:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3187,7 +3269,8 @@ yyreduce:
     break;
 
   case 213:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1002 "./util/configparser.y"
     {
                OUTYY(("P(server_add_holddown:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3199,7 +3282,8 @@ yyreduce:
     break;
 
   case 214:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1011 "./util/configparser.y"
     {
                OUTYY(("P(server_del_holddown:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3211,7 +3295,8 @@ yyreduce:
     break;
 
   case 215:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1020 "./util/configparser.y"
     {
                OUTYY(("P(server_keep_missing:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3223,7 +3308,8 @@ yyreduce:
     break;
 
   case 216:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1029 "./util/configparser.y"
     {
                OUTYY(("P(server_key_cache_size:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3234,7 +3320,8 @@ yyreduce:
     break;
 
   case 217:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1037 "./util/configparser.y"
     {
                OUTYY(("P(server_key_cache_slabs:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3250,7 +3337,8 @@ yyreduce:
     break;
 
   case 218:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1050 "./util/configparser.y"
     {
                OUTYY(("P(server_neg_cache_size:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3261,7 +3349,8 @@ yyreduce:
     break;
 
   case 219:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1058 "./util/configparser.y"
     {
                OUTYY(("P(server_local_zone:%s %s)\n", (yyvsp[(2) - (3)].str), (yyvsp[(3) - (3)].str)));
@@ -3286,7 +3375,8 @@ yyreduce:
     break;
 
   case 220:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1080 "./util/configparser.y"
     {
                OUTYY(("P(server_local_data:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3296,7 +3386,8 @@ yyreduce:
     break;
 
   case 221:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1087 "./util/configparser.y"
     {
                char* ptr;
@@ -3314,7 +3405,8 @@ yyreduce:
     break;
 
   case 222:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1102 "./util/configparser.y"
     {
                OUTYY(("P(server_minimal_responses:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3327,7 +3419,8 @@ yyreduce:
     break;
 
   case 223:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1112 "./util/configparser.y"
     {
                OUTYY(("P(server_rrset_roundrobin:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3340,7 +3433,8 @@ yyreduce:
     break;
 
   case 224:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1122 "./util/configparser.y"
     {
                OUTYY(("P(server_max_udp_size:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3350,7 +3444,8 @@ yyreduce:
     break;
 
   case 225:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1129 "./util/configparser.y"
     {
                OUTYY(("P(name:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3363,7 +3458,8 @@ yyreduce:
     break;
 
   case 226:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1139 "./util/configparser.y"
     {
                OUTYY(("P(stub-host:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3373,7 +3469,8 @@ yyreduce:
     break;
 
   case 227:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1146 "./util/configparser.y"
     {
                OUTYY(("P(stub-addr:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3383,7 +3480,8 @@ yyreduce:
     break;
 
   case 228:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1153 "./util/configparser.y"
     {
                OUTYY(("P(stub-first:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3395,7 +3493,8 @@ yyreduce:
     break;
 
   case 229:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1162 "./util/configparser.y"
     {
                OUTYY(("P(stub-prime:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3408,7 +3507,8 @@ yyreduce:
     break;
 
   case 230:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1172 "./util/configparser.y"
     {
                OUTYY(("P(name:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3421,7 +3521,8 @@ yyreduce:
     break;
 
   case 231:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1182 "./util/configparser.y"
     {
                OUTYY(("P(forward-host:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3431,7 +3532,8 @@ yyreduce:
     break;
 
   case 232:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1189 "./util/configparser.y"
     {
                OUTYY(("P(forward-addr:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3441,7 +3543,8 @@ yyreduce:
     break;
 
   case 233:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1196 "./util/configparser.y"
     {
                OUTYY(("P(forward-first:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3453,7 +3556,8 @@ yyreduce:
     break;
 
   case 234:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1205 "./util/configparser.y"
     { 
                OUTYY(("\nP(remote-control:)\n")); 
@@ -3461,7 +3565,8 @@ yyreduce:
     break;
 
   case 244:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1216 "./util/configparser.y"
     {
                OUTYY(("P(control_enable:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3474,7 +3579,8 @@ yyreduce:
     break;
 
   case 245:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1226 "./util/configparser.y"
     {
                OUTYY(("P(control_port:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3486,7 +3592,8 @@ yyreduce:
     break;
 
   case 246:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1235 "./util/configparser.y"
     {
                OUTYY(("P(control_interface:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3496,7 +3603,8 @@ yyreduce:
     break;
 
   case 247:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1242 "./util/configparser.y"
     {
                OUTYY(("P(rc_server_key_file:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3506,7 +3614,8 @@ yyreduce:
     break;
 
   case 248:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1249 "./util/configparser.y"
     {
                OUTYY(("P(rc_server_cert_file:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3516,7 +3625,8 @@ yyreduce:
     break;
 
   case 249:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1256 "./util/configparser.y"
     {
                OUTYY(("P(rc_control_key_file:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3526,7 +3636,8 @@ yyreduce:
     break;
 
   case 250:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1263 "./util/configparser.y"
     {
                OUTYY(("P(rc_control_cert_file:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3536,7 +3647,8 @@ yyreduce:
     break;
 
   case 251:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1270 "./util/configparser.y"
     { 
                OUTYY(("\nP(python:)\n")); 
@@ -3544,7 +3656,8 @@ yyreduce:
     break;
 
   case 255:
-/* Line 1787 of yacc.c  */
+
+/* Line 1806 of yacc.c  */
 #line 1279 "./util/configparser.y"
     {
                OUTYY(("P(python-script:%s)\n", (yyvsp[(2) - (2)].str)));
@@ -3554,8 +3667,9 @@ yyreduce:
     break;
 
 
-/* Line 1787 of yacc.c  */
-#line 3559 "util/configparser.c"
+
+/* Line 1806 of yacc.c  */
+#line 3673 "util/configparser.c"
       default: break;
     }
   /* User semantic actions sometimes alter yychar, and that requires
@@ -3742,7 +3856,7 @@ yyabortlab:
   yyresult = 1;
   goto yyreturn;
 
-#if !defined yyoverflow || YYERROR_VERBOSE
+#if !defined(yyoverflow) || YYERROR_VERBOSE
 /*-------------------------------------------------.
 | yyexhaustedlab -- memory exhaustion comes here.  |
 `-------------------------------------------------*/
@@ -3784,7 +3898,8 @@ yyreturn:
 }
 
 
-/* Line 2048 of yacc.c  */
+
+/* Line 2067 of yacc.c  */
 #line 1284 "./util/configparser.y"
 
 
index a862769de20620799236df334492ce63b71107fa..f036ada5a2b9fb36b5071d4edfdfef695b01de3c 100644 (file)
@@ -1,8 +1,8 @@
-/* A Bison parser, made by GNU Bison 2.6.1.  */
+/* A Bison parser, made by GNU Bison 2.5.  */
 
 /* Bison interface for Yacc-like parsers in C
    
-      Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
+      Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    This special exception was added by the Free Software Foundation in
    version 2.2 of Bison.  */
 
-#ifndef YY_UTIL_CONFIGPARSER_H
-# define YY_UTIL_CONFIGPARSER_H
-/* Enabling traces.  */
-#ifndef YYDEBUG
-# define YYDEBUG 0
-#endif
-#if YYDEBUG
-extern int yydebug;
-#endif
 
 /* Tokens.  */
 #ifndef YYTOKENTYPE
@@ -308,17 +299,20 @@ extern int yydebug;
 
 
 
+
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
 {
-/* Line 2049 of yacc.c  */
+
+/* Line 2068 of yacc.c  */
 #line 64 "./util/configparser.y"
 
        char*   str;
 
 
-/* Line 2049 of yacc.c  */
-#line 322 "util/configparser.h"
+
+/* Line 2068 of yacc.c  */
+#line 316 "util/configparser.h"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
@@ -327,18 +321,4 @@ typedef union YYSTYPE
 
 extern YYSTYPE yylval;
 
-#ifdef YYPARSE_PARAM
-#if defined __STDC__ || defined __cplusplus
-int yyparse (void *YYPARSE_PARAM);
-#else
-int yyparse ();
-#endif
-#else /* ! YYPARSE_PARAM */
-#if defined __STDC__ || defined __cplusplus
-int yyparse (void);
-#else
-int yyparse ();
-#endif
-#endif /* ! YYPARSE_PARAM */
 
-#endif /* !YY_UTIL_CONFIGPARSER_H  */
index d2b299744fb15a98d4b8ca8a0e8fce8e470aecec..8ee9d8a2da25cec92f83a246e7baaa8fe2be918d 100644 (file)
@@ -45,6 +45,7 @@
 #include "util/data/msgparse.h"
 #include "util/log.h"
 #include "util/storage/lookup3.h"
+#include "ldns/sbuffer.h"
 
 /* determine length of a dname in buffer, no compression pointers allowed */
 size_t
@@ -347,7 +348,7 @@ void dname_pkt_copy(ldns_buffer* pkt, uint8_t* to, uint8_t* dname)
        *to = 0;
 }
 
-void dname_print(FILE* out, ldns_buffer* pkt, uint8_t* dname)
+void dname_print(FILE* out, struct ldns_buffer* pkt, uint8_t* dname)
 {
        uint8_t lablen;
        if(!out) out = stdout;
index b942848a9dc7bb15e6c279bc16d653eb65a02c72..d7163289dc289b297845fe3abbb08a6df98737f1 100644 (file)
@@ -45,6 +45,7 @@
 #ifndef UTIL_DATA_DNAME_H
 #define UTIL_DATA_DNAME_H
 #include "util/storage/lruhash.h"
+struct ldns_buffer;
 
 /** max number of compression ptrs to follow */
 #define MAX_COMPRESS_PTRS 256
@@ -55,7 +56,7 @@
  *     at end, position is at end of the dname.
  * @return: 0 on parse failure, or length including ending 0 of dname. 
  */
-size_t query_dname_len(ldns_buffer* query);
+size_t query_dname_len(struct ldns_buffer* query);
 
 /**
  * Determine if dname in memory is correct. no compression ptrs allowed.
@@ -74,7 +75,7 @@ void query_dname_tolower(uint8_t* dname);
  *     is unchanged.
  * @param dname: start of dname in packet.
  */
-void pkt_dname_tolower(ldns_buffer* pkt, uint8_t* dname);
+void pkt_dname_tolower(struct ldns_buffer* pkt, uint8_t* dname);
 
 /**
  * Compare query dnames (uncompressed storage). The Dnames passed do not
@@ -106,7 +107,7 @@ int query_dname_compare(uint8_t* d1, uint8_t* d2);
  *     Compression pointers are followed and checked for loops.
  *     The uncompressed wireformat length is returned.
  */
-size_t pkt_dname_len(ldns_buffer* pkt);
+size_t pkt_dname_len(struct ldns_buffer* pkt);
 
 /**
  * Compare dnames in packet (compressed). Dnames must be valid.
@@ -117,7 +118,7 @@ size_t pkt_dname_len(ldns_buffer* pkt);
  * @return: -1, 0, or +1 depending on comparison results.
  *     Sort order is first difference found. not the canonical ordering.
  */
-int dname_pkt_compare(ldns_buffer* pkt, uint8_t* d1, uint8_t* d2);
+int dname_pkt_compare(struct ldns_buffer* pkt, uint8_t* d1, uint8_t* d2);
 
 /**
  * Hash dname, label by label, lowercasing, into hashvalue.
@@ -138,7 +139,7 @@ hashvalue_t dname_query_hash(uint8_t* dname, hashvalue_t h);
  * @return: result hash value.
  *     Result is the same as dname_query_hash, even if compression is used.
  */
-hashvalue_t dname_pkt_hash(ldns_buffer* pkt, uint8_t* dname, hashvalue_t h);
+hashvalue_t dname_pkt_hash(struct ldns_buffer* pkt, uint8_t* dname, hashvalue_t h);
 
 /**
  * Copy over a valid dname and decompress it.
@@ -146,7 +147,7 @@ hashvalue_t dname_pkt_hash(ldns_buffer* pkt, uint8_t* dname, hashvalue_t h);
  * @param to: buffer of size from pkt_len function to hold result.
  * @param dname: pointer into packet where dname starts.
  */
-void dname_pkt_copy(ldns_buffer* pkt, uint8_t* to, uint8_t* dname);
+void dname_pkt_copy(struct ldns_buffer* pkt, uint8_t* to, uint8_t* dname);
 
 /**
  * Copy over a valid dname to a packet.
@@ -154,7 +155,7 @@ void dname_pkt_copy(ldns_buffer* pkt, uint8_t* to, uint8_t* dname);
  * @param dname: dname to copy.
  * @return: 0 if not enough space in buffer.
  */
-int dname_buffer_write(ldns_buffer* pkt, uint8_t* dname);
+int dname_buffer_write(struct ldns_buffer* pkt, uint8_t* dname);
 
 /**
  * Count the number of labels in an uncompressed dname in memory.
@@ -216,7 +217,7 @@ int dname_subdomain_c(uint8_t* d1, uint8_t* d2);
  * @param pkt: if not NULL, the packet for resolving compression ptrs.
  * @param dname: pointer to (start of) dname.
  */
-void dname_print(FILE* out, ldns_buffer* pkt, uint8_t* dname);
+void dname_print(FILE* out, struct ldns_buffer* pkt, uint8_t* dname);
 
 /** 
  * Debug helper. Print dname to given string buffer (string buffer must
index 33f14b4dacc885ac7d3097b183bbcc1565646a22..66c45dfd0e97a5077a541e50f920f6522e187eb9 100644 (file)
@@ -40,7 +40,6 @@
  */
 
 #include "config.h"
-#include <ldns/wire2host.h>
 #include "util/data/msgencode.h"
 #include "util/data/msgreply.h"
 #include "util/data/msgparse.h"
@@ -48,6 +47,7 @@
 #include "util/log.h"
 #include "util/regional.h"
 #include "util/net_help.h"
+#include "ldns/sbuffer.h"
 
 /** return code that means the function ran out of memory. negative so it does
  * not conflict with DNS rcodes. */
index 13f0c1b4d334c7514a19ed02ad837febc320b1a7..a55693976836fc570e18c553a1e0f4afaeade23a 100644 (file)
@@ -42,6 +42,7 @@
 
 #ifndef UTIL_DATA_MSGENCODE_H
 #define UTIL_DATA_MSGENCODE_H
+struct ldns_buffer;
 struct query_info;
 struct reply_info;
 struct regional;
@@ -66,7 +67,7 @@ struct edns_data;
  * @return: 0 on error (server failure).
  */
 int reply_info_answer_encode(struct query_info* qinf, struct reply_info* rep, 
-       uint16_t id, uint16_t qflags, ldns_buffer* dest, time_t timenow,
+       uint16_t id, uint16_t qflags, struct ldns_buffer* dest, time_t timenow,
        int cached, struct regional* region, uint16_t udpsize, 
        struct edns_data* edns, int dnssec, int secure);
 
@@ -88,7 +89,7 @@ int reply_info_answer_encode(struct query_info* qinf, struct reply_info* rep,
  *     0 on error: malloc failure (no log_err has been done).
  */
 int reply_info_encode(struct query_info* qinfo, struct reply_info* rep, 
-       uint16_t id, uint16_t flags, ldns_buffer* buffer, time_t timenow, 
+       uint16_t id, uint16_t flags, struct ldns_buffer* buffer, time_t timenow, 
        struct regional* region, uint16_t udpsize, int dnssec);
 
 /**
@@ -96,7 +97,7 @@ int reply_info_encode(struct query_info* qinfo, struct reply_info* rep,
  * @param pkt: where to store the packet.
  * @param qinfo: query info.
  */
-void qinfo_query_encode(ldns_buffer* pkt, struct query_info* qinfo);
+void qinfo_query_encode(struct ldns_buffer* pkt, struct query_info* qinfo);
 
 /**
  * Estimate size of EDNS record in packet. EDNS record will be no larger.
@@ -111,7 +112,7 @@ uint16_t calc_edns_field_size(struct edns_data* edns);
  * @param pkt: packet added to.
  * @param edns: if NULL or present=0, nothing is added to the packet.
  */
-void attach_edns_record(ldns_buffer* pkt, struct edns_data* edns);
+void attach_edns_record(struct ldns_buffer* pkt, struct edns_data* edns);
 
 /** 
  * Encode an error. With QR and RA set.
@@ -124,7 +125,7 @@ void attach_edns_record(ldns_buffer* pkt, struct edns_data* edns);
  * @param edns: if not NULL, this is the query edns info,
  *     and an edns reply is attached. Only attached if EDNS record fits reply.
  */
-void error_encode(ldns_buffer* pkt, int r, struct query_info* qinfo,
+void error_encode(struct ldns_buffer* pkt, int r, struct query_info* qinfo,
        uint16_t qid, uint16_t qflags, struct edns_data* edns);
 
 #endif /* UTIL_DATA_MSGENCODE_H */
index 2791ae5608650fedac3efbd6a1a282c6dd4cea12..29299bfd5517e61a6df183dcc2b34e03194762d9 100644 (file)
  * Routines for message parsing a packet buffer to a descriptive structure.
  */
 #include "config.h"
-#include <ldns/ldns.h>
 #include "util/data/msgparse.h"
 #include "util/data/dname.h"
 #include "util/data/packed_rrset.h"
 #include "util/storage/lookup3.h"
 #include "util/regional.h"
+#include "ldns/rrdef.h"
+#include "ldns/sbuffer.h"
+#include "ldns/parseutil.h"
+#include "ldns/wire2str.h"
 
 /** smart comparison of (compressed, valid) dnames from packet */
 static int
@@ -614,7 +617,7 @@ get_rdf_size(ldns_rdf_type rdf)
                        return 16;
                        break;
                default:
-                       log_assert(false); /* add type above */
+                       log_assert(0); /* add type above */
                        /* only types that appear before a domain  *
                         * name are needed. rest is simply copied. */
        }
index 83d2aaaa6ea7710c5c5243c567dfefe0a1ec9ced..d0f6bb5aa5e069a107e4297006dbaf763cb9fcac 100644 (file)
@@ -63,7 +63,9 @@
 #ifndef UTIL_DATA_MSGPARSE_H
 #define UTIL_DATA_MSGPARSE_H
 #include "util/storage/lruhash.h"
-#include <ldns/packet.h>
+#include "ldns/pkthdr.h"
+#include "ldns/rrdef.h"
+struct ldns_buffer;
 struct rrset_parse;
 struct rr_parse;
 struct regional;
@@ -229,7 +231,7 @@ size_t get_rdf_size(ldns_rdf_type rdf);
  * @param region: how to alloc results.
  * @return: 0 if OK, or rcode on error.
  */
-int parse_packet(ldns_buffer* pkt, struct msg_parse* msg, 
+int parse_packet(struct ldns_buffer* pkt, struct msg_parse* msg, 
        struct regional* region);
 
 /**
@@ -259,7 +261,7 @@ int parse_extract_edns(struct msg_parse* msg, struct edns_data* edns);
  * @return: 0 on success, or an RCODE on error.
  *     RCODE formerr if OPT is badly formatted and so on.
  */
-int parse_edns_from_pkt(ldns_buffer* pkt, struct edns_data* edns);
+int parse_edns_from_pkt(struct ldns_buffer* pkt, struct edns_data* edns);
 
 /**
  * Calculate hash value for rrset in packet.
@@ -270,7 +272,7 @@ int parse_edns_from_pkt(ldns_buffer* pkt, struct edns_data* edns);
  * @param rrset_flags: rrset flags (same as packed_rrset flags).
  * @return hash value
  */
-hashvalue_t pkt_hash_rrset(ldns_buffer* pkt, uint8_t* dname, uint16_t type,
+hashvalue_t pkt_hash_rrset(struct ldns_buffer* pkt, uint8_t* dname, uint16_t type,
         uint16_t dclass, uint32_t rrset_flags);
 
 /**
@@ -286,7 +288,7 @@ hashvalue_t pkt_hash_rrset(ldns_buffer* pkt, uint8_t* dname, uint16_t type,
  * @return NULL or the rrset_parse if found.
  */
 struct rrset_parse* msgparse_hashtable_lookup(struct msg_parse* msg, 
-       ldns_buffer* pkt, hashvalue_t h, uint32_t rrset_flags, 
+       struct ldns_buffer* pkt, hashvalue_t h, uint32_t rrset_flags, 
        uint8_t* dname, size_t dnamelen, uint16_t type, uint16_t dclass);
 
 /**
index 004d6c928f5745a23c3dc431c16e45c297844483..25f0af1552d1cd7c6cbf88ae32c6b213dfaacecf 100644 (file)
@@ -40,7 +40,6 @@
  */
 
 #include "config.h"
-#include <ldns/ldns.h>
 #include "util/data/msgreply.h"
 #include "util/storage/lookup3.h"
 #include "util/log.h"
@@ -51,6 +50,8 @@
 #include "util/regional.h"
 #include "util/data/msgparse.h"
 #include "util/data/msgencode.h"
+#include "ldns/sbuffer.h"
+#include "ldns/wire2str.h"
 
 /** MAX TTL default for messages and rrsets */
 time_t MAX_TTL = 3600 * 24 * 10; /* ten days */
@@ -770,24 +771,15 @@ log_dns_msg(const char* str, struct query_info* qinfo, struct reply_info* rep)
                region, 65535, 1)) {
                log_info("%s: log_dns_msg: out of memory", str);
        } else {
-               ldns_status s;
-               ldns_pkt* pkt = NULL;
-               s = ldns_buffer2pkt_wire(&pkt, buf);
-               if(s != LDNS_STATUS_OK) {
-                       log_info("%s: log_dns_msg: ldns parse gave: %s",
-                               str, ldns_get_errorstr_by_id(s));
+               char* str = ldns_wire2str_pkt(ldns_buffer_begin(buf),
+                       ldns_buffer_limit(buf));
+               if(!str) {
+                       log_info("%s: log_dns_msg: ldns tostr failed", str);
                } else {
-                       ldns_buffer_clear(buf);
-                       s = ldns_pkt2buffer_str(buf, pkt);
-                       if(s != LDNS_STATUS_OK) {
-                               log_info("%s: log_dns_msg: ldns tostr gave: %s",
-                                       str, ldns_get_errorstr_by_id(s));
-                       } else {
-                               log_info("%s %s", 
-                                       str, (char*)ldns_buffer_begin(buf));
-                       }
+                       log_info("%s %s", 
+                               str, (char*)ldns_buffer_begin(buf));
                }
-               ldns_pkt_free(pkt);
+               free(str);
        }
        ldns_buffer_free(buf);
        regional_destroy(region);
index 6087c6b2057c462a065ae6342a5e385477d7598e..a894d3287ff48b60119637ae945a416022962ec7 100644 (file)
@@ -43,6 +43,7 @@
 #define UTIL_DATA_MSGREPLY_H
 #include "util/storage/lruhash.h"
 #include "util/data/packed_rrset.h"
+struct ldns_buffer;
 struct comm_reply;
 struct alloc_cache;
 struct iovec;
@@ -201,7 +202,7 @@ struct msgreply_entry {
  * @param query: the wireformat packet query. starts with ID.
  * @return: 0 on format error.
  */
-int query_info_parse(struct query_info* m, ldns_buffer* query);
+int query_info_parse(struct query_info* m, struct ldns_buffer* query);
 
 /**
  * Parse query reply.
@@ -218,7 +219,7 @@ int query_info_parse(struct query_info* m, ldns_buffer* query);
  *     o FORMERR for parse errors.
  *     o SERVFAIL for memory allocation errors.
  */
-int reply_info_parse(ldns_buffer* pkt, struct alloc_cache* alloc,
+int reply_info_parse(struct ldns_buffer* pkt, struct alloc_cache* alloc,
        struct query_info* qinf, struct reply_info** rep, 
        struct regional* region, struct edns_data* edns);
 
@@ -237,7 +238,7 @@ int reply_info_parse(ldns_buffer* pkt, struct alloc_cache* alloc,
  *     and no rrset_ref array in the reply is built up.
  * @return 0 if allocation failed.
  */
-int parse_create_msg(ldns_buffer* pkt, struct msg_parse* msg,
+int parse_create_msg(struct ldns_buffer* pkt, struct msg_parse* msg,
         struct alloc_cache* alloc, struct query_info* qinf,
        struct reply_info** rep, struct regional* region);
 
@@ -322,7 +323,7 @@ struct reply_info* reply_info_copy(struct reply_info* rep,
  *     Note that TTL will still be relative on return.
  * @return false on alloc failure.
  */
-int parse_copy_decompress_rrset(ldns_buffer* pkt, struct msg_parse* msg,
+int parse_copy_decompress_rrset(struct ldns_buffer* pkt, struct msg_parse* msg,
        struct rrset_parse *pset, struct regional* region, 
        struct ub_packed_rrset_key* pk);
 
index 1bf2e8f00b81b6620f6e289fa69a0157f5ddd1f6..d9c2f308aea741b055e7b179bb5cf097c4dbbb97 100644 (file)
@@ -40,7 +40,6 @@
  */
 
 #include "config.h"
-#include <ldns/wire2host.h>
 #include "util/data/packed_rrset.h"
 #include "util/data/dname.h"
 #include "util/storage/lookup3.h"
@@ -48,6 +47,9 @@
 #include "util/alloc.h"
 #include "util/regional.h"
 #include "util/net_help.h"
+#include "ldns/rrdef.h"
+#include "ldns/sbuffer.h"
+#include "ldns/wire2str.h"
 
 void
 ub_packed_rrset_parsedelete(struct ub_packed_rrset_key* pkey,
@@ -266,6 +268,52 @@ void log_rrset_key(enum verbosity_value v, const char* str,
                        ntohs(rrset->rk.type), ntohs(rrset->rk.rrset_class));
 }
 
+int packed_rr_to_string(struct ub_packed_rrset_key* rrset, size_t i,
+       time_t now, char* dest, size_t dest_len)
+{
+       struct packed_rrset_data* d = (struct packed_rrset_data*)rrset->
+               entry.data;
+       uint8_t rr[65535];
+       size_t rlen = rrset->rk.dname_len + 2 + 2 + 4 + d->rr_len[i];
+       log_assert(dest_len > 0 && dest);
+       if(rlen > dest_len) {
+               dest[0] = 0;
+               return 0;
+       }
+       memmove(rr, rrset->rk.dname, rrset->rk.dname_len);
+       if(i < d->count)
+               memmove(rr+rrset->rk.dname_len, &rrset->rk.type, 2);
+       else    ldns_write_uint16(rr+rrset->rk.dname_len, LDNS_RR_TYPE_RRSIG);
+       memmove(rr+rrset->rk.dname_len+2, &rrset->rk.rrset_class, 2);
+       ldns_write_uint32(rr+rrset->rk.dname_len+4,
+               (uint32_t)(d->rr_ttl[i]-now));
+       memmove(rr+rrset->rk.dname_len+8, d->rr_data[i], d->rr_len[i]);
+       if(ldns_wire2str_rr_buf(rr, rlen, dest, dest_len) == -1) {
+               log_info("rrbuf failure %d %s", (int)d->rr_len[i], dest);
+               dest[0] = 0;
+               return 0;
+       } 
+       return 1;
+}
+
+void log_packed_rrset(enum verbosity_value v, const char* str,
+       struct ub_packed_rrset_key* rrset)
+{
+       struct packed_rrset_data* d = (struct packed_rrset_data*)rrset->
+               entry.data;
+       char buf[65535];
+       size_t i;
+       if(verbosity < v)
+               return;
+       for(i=0; i<d->count+d->rrsig_count; i++) {
+               if(!packed_rr_to_string(rrset, i, 0, buf, sizeof(buf))) {
+                       log_info("%s: rr %d wire2str-error", str, (int)i);
+               } else {
+                       log_info("%s: %s", str, buf);
+               }
+       }
+}
+
 time_t 
 ub_packed_rrset_ttl(struct ub_packed_rrset_key* key)
 {
@@ -339,150 +387,3 @@ packed_rrset_copy_alloc(struct ub_packed_rrset_key* key,
        packed_rrset_ttl_add(dd, now);
        return dk;
 }
-
-struct ub_packed_rrset_key* 
-ub_packed_rrset_heap_key(ldns_rr_list* rrset)
-{
-       struct ub_packed_rrset_key* k;
-       ldns_rr* rr;
-       if(!rrset)
-               return NULL;
-       rr = ldns_rr_list_rr(rrset, 0);
-       if(!rr)
-               return NULL;
-       k = (struct ub_packed_rrset_key*)calloc(1, sizeof(*k));
-       if(!k)
-               return NULL;
-       k->rk.type = htons(ldns_rr_get_type(rr));
-       k->rk.rrset_class = htons(ldns_rr_get_class(rr));
-       k->rk.dname_len = ldns_rdf_size(ldns_rr_owner(rr));
-       k->rk.dname = memdup(ldns_rdf_data(ldns_rr_owner(rr)),
-               ldns_rdf_size(ldns_rr_owner(rr)));
-       if(!k->rk.dname) {
-               free(k);
-               return NULL;
-       }
-       return k;
-}
-
-struct packed_rrset_data* 
-packed_rrset_heap_data(ldns_rr_list* rrset)
-{
-       struct packed_rrset_data* data;
-       size_t count=0, rrsig_count=0, len=0, i, j, total;
-       uint8_t* nextrdata;
-       if(!rrset || ldns_rr_list_rr_count(rrset)==0)
-               return NULL;
-       /* count sizes */
-       for(i=0; i<ldns_rr_list_rr_count(rrset); i++) {
-               ldns_rr* rr = ldns_rr_list_rr(rrset, i);
-               if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_RRSIG)
-                       rrsig_count++;
-               else    count++;
-               for(j=0; j<ldns_rr_rd_count(rr); j++)
-                       len += ldns_rdf_size(ldns_rr_rdf(rr, j));
-               len += 2; /* sizeof the rdlength */
-       }
-
-       /* allocate */
-       total = count + rrsig_count;
-       len += sizeof(*data) + total*(sizeof(size_t) + sizeof(time_t) + 
-               sizeof(uint8_t*));
-       data = (struct packed_rrset_data*)calloc(1, len);
-       if(!data)
-               return NULL;
-       
-       /* fill it */
-       data->ttl = ldns_rr_ttl(ldns_rr_list_rr(rrset, 0));
-       data->count = count;
-       data->rrsig_count = rrsig_count;
-       data->rr_len = (size_t*)((uint8_t*)data +
-               sizeof(struct packed_rrset_data));
-       data->rr_data = (uint8_t**)&(data->rr_len[total]);
-       data->rr_ttl = (time_t*)&(data->rr_data[total]);
-       nextrdata = (uint8_t*)&(data->rr_ttl[total]);
-
-       /* fill out len, ttl, fields */
-       for(i=0; i<total; i++) {
-               ldns_rr* rr = ldns_rr_list_rr(rrset, i);
-               data->rr_ttl[i] = ldns_rr_ttl(rr);
-               if(data->rr_ttl[i] < data->ttl)
-                       data->ttl = data->rr_ttl[i];
-               data->rr_len[i] = 2; /* the rdlength */
-               for(j=0; j<ldns_rr_rd_count(rr); j++)
-                       data->rr_len[i] += ldns_rdf_size(ldns_rr_rdf(rr, j));
-       }
-
-       /* fixup rest of ptrs */
-       for(i=0; i<total; i++) {
-               data->rr_data[i] = nextrdata;
-               nextrdata += data->rr_len[i];
-       }
-
-       /* copy data in there */
-       for(i=0; i<total; i++) {
-               ldns_rr* rr = ldns_rr_list_rr(rrset, i);
-               uint16_t rdlen = htons(data->rr_len[i]-2);
-               size_t p = sizeof(rdlen);
-               memmove(data->rr_data[i], &rdlen, p);
-               for(j=0; j<ldns_rr_rd_count(rr); j++) {
-                       ldns_rdf* rd = ldns_rr_rdf(rr, j);
-                       memmove(data->rr_data[i]+p, ldns_rdf_data(rd),
-                               ldns_rdf_size(rd));
-                       p += ldns_rdf_size(rd);
-               }
-       }
-
-       if(data->rrsig_count && data->count == 0) {
-               data->count = data->rrsig_count; /* rrset type is RRSIG */
-               data->rrsig_count = 0;
-       }
-       return data;
-}
-
-/** convert i'th rr to ldns_rr */
-static ldns_rr*
-torr(struct ub_packed_rrset_key* k, ldns_buffer* buf, size_t i)
-{
-       struct packed_rrset_data* d = (struct packed_rrset_data*)k->entry.data;
-       ldns_rr* rr = NULL;
-       size_t pos = 0;
-       ldns_status s;
-       ldns_buffer_clear(buf);
-       ldns_buffer_write(buf, k->rk.dname, k->rk.dname_len);
-       if(i < d->count)
-               ldns_buffer_write(buf, &k->rk.type, sizeof(uint16_t));
-       else    ldns_buffer_write_u16(buf, LDNS_RR_TYPE_RRSIG);
-       ldns_buffer_write(buf, &k->rk.rrset_class, sizeof(uint16_t));
-       ldns_buffer_write_u32(buf, d->rr_ttl[i]);
-       ldns_buffer_write(buf, d->rr_data[i], d->rr_len[i]);
-       ldns_buffer_flip(buf);
-       s = ldns_wire2rr(&rr, ldns_buffer_begin(buf), ldns_buffer_limit(buf),
-               &pos, LDNS_SECTION_ANSWER);
-       if(s == LDNS_STATUS_OK)
-               return rr;
-       return NULL;
-}
-
-ldns_rr_list* 
-packed_rrset_to_rr_list(struct ub_packed_rrset_key* k, ldns_buffer* buf)
-{
-       struct packed_rrset_data* d = (struct packed_rrset_data*)k->entry.data;
-       ldns_rr_list* r = ldns_rr_list_new();
-       size_t i;
-       if(!r)
-               return NULL;
-       for(i=0; i<d->count+d->rrsig_count; i++) {
-               ldns_rr* rr = torr(k, buf, i);
-               if(!rr) {
-                       ldns_rr_list_deep_free(r);
-                       return NULL;
-               }
-               if(!ldns_rr_list_push_rr(r, rr)) {
-                       ldns_rr_free(rr);
-                       ldns_rr_list_deep_free(r);
-                       return NULL;
-               }
-       }
-       return r;
-}
index 9530aa604f123e7bb1766314ac520692f8bb3f5a..f46e5e3ee236a3e213d76cbf2f5de2a7b9f272a3 100644 (file)
@@ -42,7 +42,6 @@
 #ifndef UTIL_DATA_PACKED_RRSET_H
 #define UTIL_DATA_PACKED_RRSET_H
 #include "util/storage/lruhash.h"
-#include <ldns/rr.h>
 struct alloc_cache;
 struct regional;
 
@@ -382,6 +381,27 @@ const char* sec_status_to_string(enum sec_status s);
 void log_rrset_key(enum verbosity_value v, const char* str, 
        struct ub_packed_rrset_key* rrset);
 
+/**
+ * Convert RR from RRset to string.
+ * @param rrset: structure with data.
+ * @param i: index of rr or RRSIG.
+ * @param now: time that is subtracted from ttl before printout. Can be 0.
+ * @param dest: destination string buffer. Must be nonNULL.
+ * @param dest_len: length of dest buffer (>0).
+ * @return false on failure.
+ */
+int packed_rr_to_string(struct ub_packed_rrset_key* rrset, size_t i,
+       time_t now, char* dest, size_t dest_len);
+
+/**
+ * Print the string with prefix, one rr per line.
+ * @param v: at what verbosity level to print this.
+ * @param str: string of message.
+ * @param rrset: with name, and rdata, and rrsigs.
+ */
+void log_packed_rrset(enum verbosity_value v, const char* str,
+       struct ub_packed_rrset_key* rrset);
+
 /** 
  * Allocate rrset in region - no more locks needed 
  * @param key: a (just from rrset cache looked up) rrset key + valid,
@@ -405,30 +425,4 @@ struct ub_packed_rrset_key* packed_rrset_copy_alloc(
        struct ub_packed_rrset_key* key, struct alloc_cache* alloc, 
        time_t now);
 
-/**
- * Create a ub_packed_rrset_key allocated on the heap.
- * It therefore does not have the correct ID value, and cannot be used
- * inside the cache.  It can be used in storage outside of the cache.
- * Keys for the cache have to be obtained from alloc.h .
- * @param rrset: the ldns rr set.
- * @return key allocated or NULL on failure.
- */
-struct ub_packed_rrset_key* ub_packed_rrset_heap_key(ldns_rr_list* rrset);
-
-/**
- * Create packed_rrset data on the heap.
- * @param rrset: the ldns rr set with the data to copy.
- * @return data allocated or NULL on failure.
- */
-struct packed_rrset_data* packed_rrset_heap_data(ldns_rr_list* rrset);
-
-/**
- * Convert packed rrset to ldns rr list.
- * @param rrset: packed rrset.
- * @param buf: scratch buffer.
- * @return rr list or NULL on failure.
- */
-ldns_rr_list* packed_rrset_to_rr_list(struct ub_packed_rrset_key* rrset,
-       ldns_buffer* buf);
-
 #endif /* UTIL_DATA_PACKED_RRSET_H */
index 9b2daea3208fc62d8a82b15e4692cc100322e6af..91387161c9165578cf26d6a923c86fb387c13aac 100644 (file)
@@ -40,6 +40,8 @@
 #include "config.h"
 #include "util/log.h"
 #include "util/locks.h"
+#include "ldns/sbuffer.h"
+#include <stdarg.h>
 #ifdef HAVE_TIME_H
 #include <time.h>
 #endif
index 5ba1a0bc4d73cbcc9e71138fcc622a0c2a9d057d..2ca88d0b62c6d8e95a075c0695bfe7945e51d4eb 100644 (file)
@@ -41,7 +41,7 @@
 
 #ifndef UTIL_LOG_H
 #define UTIL_LOG_H
-#include <ldns/buffer.h>
+struct ldns_buffer;
 
 /**
  * verbosity value:
@@ -155,7 +155,7 @@ void log_hex(const char* msg, void* data, size_t length);
  * @param msg: string desc to print
  * @param buf: the buffer.
  */
-void log_buf(enum verbosity_value level, const char* msg, ldns_buffer* buf);
+void log_buf(enum verbosity_value level, const char* msg, struct ldns_buffer* buf);
 
 /**
  * Log fatal error message, and exit the current process.
index 3ec25524b03b051a31952a4b9b767f2a02eb733c..f1f03b19024d563884e21baa444ead89e4e61ac8 100644 (file)
@@ -44,6 +44,7 @@
 #include "util/storage/lruhash.h"
 #include "util/data/msgreply.h"
 #include "util/data/msgparse.h"
+struct ldns_buffer;
 struct alloc_cache;
 struct rrset_cache;
 struct key_cache;
@@ -176,7 +177,7 @@ struct module_env {
        /** region for temporary usage. May be cleared after operate() call. */
        struct regional* scratch;
        /** buffer for temporary usage. May be cleared after operate() call. */
-       ldns_buffer* scratch_buffer;
+       struct ldns_buffer* scratch_buffer;
        /** internal data for daemon - worker thread. */
        struct worker* worker;
        /** mesh area with query state dependencies */
index 64bd876dcbb1641a0934652b9323292a47af4181..a238f1548cfe0628ebc78ccd3a898e80df4d2846 100644 (file)
  */
 
 #include "config.h"
-#include <ldns/ldns.h>
 #include "util/net_help.h"
 #include "util/log.h"
 #include "util/data/dname.h"
 #include "util/module.h"
 #include "util/regional.h"
+#include "ldns/parseutil.h"
+#include "ldns/wire2str.h"
 #include <fcntl.h>
 #ifdef HAVE_OPENSSL_SSL_H
 #include <openssl/ssl.h>
@@ -159,7 +160,7 @@ log_addr(enum verbosity_value v, const char* str,
                default: break;
        }
        if(inet_ntop(af, sinaddr, dest, (socklen_t)sizeof(dest)) == 0) {
-               strncpy(dest, "(inet_ntop error)", sizeof(dest));
+               strlcpy(dest, "(inet_ntop error)", sizeof(dest));
        }
        dest[sizeof(dest)-1] = 0;
        port = ntohs(((struct sockaddr_in*)addr)->sin_port);
@@ -180,7 +181,7 @@ extstrtoaddr(const char* str, struct sockaddr_storage* addr,
                if(s-str >= MAX_ADDR_STRLEN) {
                        return 0;
                }
-               strncpy(buf, str, MAX_ADDR_STRLEN);
+               strlcpy(buf, str, sizeof(buf));
                buf[s-str] = 0;
                port = atoi(s+1);
                if(port == 0 && strcmp(s+1,"0")!=0) {
@@ -210,7 +211,7 @@ ipstrtoaddr(const char* ip, int port, struct sockaddr_storage* addr,
                if((s=strchr(ip, '%'))) { /* ip6%interface, rfc 4007 */
                        if(s-ip >= MAX_ADDR_STRLEN)
                                return 0;
-                       strncpy(buf, ip, MAX_ADDR_STRLEN);
+                       strlcpy(buf, ip, sizeof(buf));
                        buf[s-ip]=0;
                        sa->sin6_scope_id = (uint32_t)atoi(s+1);
                        ip = buf;
@@ -316,7 +317,7 @@ void log_name_addr(enum verbosity_value v, const char* str, uint8_t* zone,
                default: break;
        }
        if(inet_ntop(af, sinaddr, dest, (socklen_t)sizeof(dest)) == 0) {
-               strncpy(dest, "(inet_ntop error)", sizeof(dest));
+               strlcpy(dest, "(inet_ntop error)", sizeof(dest));
        }
        dest[sizeof(dest)-1] = 0;
        port = ntohs(((struct sockaddr_in*)addr)->sin_port);
index c25d42c2d06be6c76e55deef009c7cc582b95f9f..1a30a6145ffb4c583cded7f943390895d84f269b 100644 (file)
  * This file contains event notification functions.
  */
 #include "config.h"
-#include <ldns/wire2host.h>
 #include "util/netevent.h"
 #include "util/log.h"
 #include "util/net_help.h"
 #include "util/fptr_wlist.h"
+#include "ldns/pkthdr.h"
+#include "ldns/sbuffer.h"
 #ifdef HAVE_OPENSSL_SSL_H
 #include <openssl/ssl.h>
 #endif
@@ -422,7 +423,7 @@ static void p_ancil(const char* str, struct comm_reply* r)
                char buf[1024];
                if(inet_ntop(AF_INET6, &r->pktinfo.v6info.ipi6_addr, 
                        buf, (socklen_t)sizeof(buf)) == 0) {
-                       strncpy(buf, "(inet_ntop error)", sizeof(buf));
+                       strlcpy(buf, "(inet_ntop error)", sizeof(buf));
                }
                buf[sizeof(buf)-1]=0;
                log_info("%s: %s %d", str, buf, r->pktinfo.v6info.ipi6_ifindex);
@@ -431,13 +432,13 @@ static void p_ancil(const char* str, struct comm_reply* r)
                char buf1[1024], buf2[1024];
                if(inet_ntop(AF_INET, &r->pktinfo.v4info.ipi_addr, 
                        buf1, (socklen_t)sizeof(buf1)) == 0) {
-                       strncpy(buf1, "(inet_ntop error)", sizeof(buf1));
+                       strlcpy(buf1, "(inet_ntop error)", sizeof(buf1));
                }
                buf1[sizeof(buf1)-1]=0;
 #ifdef HAVE_STRUCT_IN_PKTINFO_IPI_SPEC_DST
                if(inet_ntop(AF_INET, &r->pktinfo.v4info.ipi_spec_dst, 
                        buf2, (socklen_t)sizeof(buf2)) == 0) {
-                       strncpy(buf2, "(inet_ntop error)", sizeof(buf2));
+                       strlcpy(buf2, "(inet_ntop error)", sizeof(buf2));
                }
                buf2[sizeof(buf2)-1]=0;
 #else
@@ -449,7 +450,7 @@ static void p_ancil(const char* str, struct comm_reply* r)
                char buf1[1024];
                if(inet_ntop(AF_INET, &r->pktinfo.v4addr, 
                        buf1, (socklen_t)sizeof(buf1)) == 0) {
-                       strncpy(buf1, "(inet_ntop error)", sizeof(buf1));
+                       strlcpy(buf1, "(inet_ntop error)", sizeof(buf1));
                }
                buf1[sizeof(buf1)-1]=0;
                log_info("%s: %s", str, buf1);
index f75c394d7b1b993645a80ef37edb343f8aa8d080..de00cc063c52c5fbac6df87a03175945d3e30cd2 100644 (file)
@@ -60,7 +60,7 @@
 #ifndef NET_EVENT_H
 #define NET_EVENT_H
 
-#include <ldns/buffer.h>
+struct ldns_buffer;
 struct comm_point;
 struct comm_reply;
 struct event_base;
@@ -149,7 +149,7 @@ struct comm_point {
        struct timeval* timeout;
 
        /** buffer pointer. Either to perthread, or own buffer or NULL */
-       ldns_buffer* buffer;
+       struct ldns_buffer* buffer;
 
        /* -------- TCP Handler -------- */
        /** Read/Write state for TCP */
@@ -367,7 +367,7 @@ struct event_base* comm_base_internal(struct comm_base* b);
  * Sets timeout to NULL. Turns off TCP options.
  */
 struct comm_point* comm_point_create_udp(struct comm_base* base,
-       int fd, ldns_buffer* buffer, 
+       int fd, struct ldns_buffer* buffer, 
        comm_point_callback_t* callback, void* callback_arg);
 
 /**
@@ -383,7 +383,7 @@ struct comm_point* comm_point_create_udp(struct comm_base* base,
  * Sets timeout to NULL. Turns off TCP options.
  */
 struct comm_point* comm_point_create_udp_ancil(struct comm_base* base,
-       int fd, ldns_buffer* buffer, 
+       int fd, struct ldns_buffer* buffer, 
        comm_point_callback_t* callback, void* callback_arg);
 
 /**
@@ -477,7 +477,7 @@ void comm_point_drop_reply(struct comm_reply* repinfo);
  * @param addrlen: length of addr.
  * @return: false on a failure.
  */
-int comm_point_send_udp_msg(struct comm_point* c, ldns_buffer* packet,
+int comm_point_send_udp_msg(struct comm_point* c, struct ldns_buffer* packet,
        struct sockaddr* addr, socklen_t addrlen);
 
 /**
index 5d71fcfa4c12d0460fec8ab63b487b8ff7f9041c..edf584febb966b6e4afe5d3b278e67396bd10c54 100644 (file)
@@ -60,6 +60,7 @@
 #include "config.h"
 #include "util/random.h"
 #include "util/log.h"
+#include <time.h>
 #ifdef HAVE_SSL
 #include <openssl/rand.h>
 #include <openssl/rc4.h>
index 3d22637b8c2e17451623f71149479fc9d4ca93e3..176fa153d2adf883f591209352f54477319e6326 100644 (file)
@@ -41,7 +41,6 @@
  * It was modified to fit into unbound. The state table process is the same.
  */
 #include "config.h"
-#include <ldns/ldns.h>
 #include "validator/autotrust.h"
 #include "validator/val_anchor.h"
 #include "validator/val_utils.h"
 #include "services/mesh.h"
 #include "services/cache/rrset.h"
 #include "validator/val_kcache.h"
+#include "ldns/sbuffer.h"
+#include "ldns/wire2str.h"
+#include "ldns/str2wire.h"
+#include "ldns/keyraw.h"
+#include "ldns/rrdef.h"
+#include <stdarg.h>
+#include <ctype.h>
 
 /** number of times a key must be seen before it can become valid */
 #define MIN_PENDINGCOUNT 2
@@ -138,8 +144,11 @@ verbose_key(struct autr_ta* ta, enum verbosity_value level,
        va_list args;
        va_start(args, format);
        if(verbosity >= level) {
-               char* str = ldns_rdf2str(ldns_rr_owner(ta->rr));
-               int keytag = (int)ldns_calc_keytag(ta->rr);
+               char* str = ldns_wire2str_dname(ta->rr, ta->dname_len);
+               int keytag = (int)ldns_calc_keytag_raw(ldns_wirerr_get_rdata(
+                       ta->rr, ta->rr_len, ta->dname_len),
+                       ldns_wirerr_get_rdatalen(ta->rr, ta->rr_len,
+                       ta->dname_len));
                char msg[MAXSYSLOGMSGLEN];
                vsnprintf(msg, sizeof(msg), format, args);
                verbose(level, "%s key %d %s", str?str:"??", keytag, msg);
@@ -262,55 +271,76 @@ str_contains_data(char* str, char comment)
         return 0;
 }
 
-/** Get DNSKEY flags */
+/** Get DNSKEY flags
+ * rdata without rdatalen in front of it. */
 static int
-dnskey_flags(ldns_rr* rr)
+dnskey_flags(uint16_t t, uint8_t* rdata, size_t len)
 {
-       if(ldns_rr_get_type(rr) != LDNS_RR_TYPE_DNSKEY)
+       uint16_t f;
+       if(t != LDNS_RR_TYPE_DNSKEY)
                return 0;
-       return (int)ldns_read_uint16(ldns_rdf_data(ldns_rr_dnskey_flags(rr)));
+       if(len < 2)
+               return 0;
+       memmove(&f, rdata, 2);
+       f = ntohs(f);
+       return (int)f;
 }
 
+/** Check if KSK DNSKEY.
+ * pass rdata without rdatalen in front of it */
+static int
+rr_is_dnskey_sep(uint16_t t, uint8_t* rdata, size_t len)
+{
+       return (dnskey_flags(t, rdata, len)&DNSKEY_BIT_SEP);
+}
 
-/** Check if KSK DNSKEY */
+/** Check if TA is KSK DNSKEY */
 static int
-rr_is_dnskey_sep(ldns_rr* rr)
+ta_is_dnskey_sep(struct autr_ta* ta)
 {
-       return (dnskey_flags(rr)&DNSKEY_BIT_SEP);
+       return (dnskey_flags(
+               ldns_wirerr_get_type(ta->rr, ta->rr_len, ta->dname_len),
+               ldns_wirerr_get_rdata(ta->rr, ta->rr_len, ta->dname_len),
+               ldns_wirerr_get_rdatalen(ta->rr, ta->rr_len, ta->dname_len)
+               ) & DNSKEY_BIT_SEP);
 }
 
-/** Check if REVOKED DNSKEY */
+/** Check if REVOKED DNSKEY
+ * pass rdata without rdatalen in front of it */
 static int
-rr_is_dnskey_revoked(ldns_rr* rr)
+rr_is_dnskey_revoked(uint16_t t, uint8_t* rdata, size_t len)
 {
-       return (dnskey_flags(rr)&LDNS_KEY_REVOKE_KEY);
+       return (dnskey_flags(t, rdata, len)&LDNS_KEY_REVOKE_KEY);
 }
 
 /** create ta */
 static struct autr_ta*
-autr_ta_create(ldns_rr* rr)
+autr_ta_create(uint8_t* rr, size_t rr_len, size_t dname_len)
 {
        struct autr_ta* ta = (struct autr_ta*)calloc(1, sizeof(*ta));
        if(!ta) {
-               ldns_rr_free(rr);
+               free(rr);
                return NULL;
        }
        ta->rr = rr;
+       ta->rr_len = rr_len;
+       ta->dname_len = dname_len;
        return ta;
 }
 
 /** create tp */
 static struct trust_anchor*
-autr_tp_create(struct val_anchors* anchors, ldns_rdf* own, uint16_t dc)
+autr_tp_create(struct val_anchors* anchors, uint8_t* own, size_t own_len,
+       uint16_t dc)
 {
        struct trust_anchor* tp = (struct trust_anchor*)calloc(1, sizeof(*tp));
        if(!tp) return NULL;
-       tp->name = memdup(ldns_rdf_data(own), ldns_rdf_size(own));
+       tp->name = memdup(own, own_len);
        if(!tp->name) {
                free(tp);
                return NULL;
        }
-       tp->namelen = ldns_rdf_size(own);
+       tp->namelen = own_len;
        tp->namelabs = dname_count_labels(tp->name);
        tp->node.key = tp;
        tp->dclass = dc;
@@ -371,7 +401,7 @@ void autr_point_delete(struct trust_anchor* tp)
                struct autr_ta* p = tp->autr->keys, *np;
                while(p) {
                        np = p->next;
-                       ldns_rr_free(p->rr);
+                       free(p->rr);
                        free(p);
                        p = np;
                }
@@ -384,13 +414,12 @@ void autr_point_delete(struct trust_anchor* tp)
 
 /** find or add a new trust point for autotrust */
 static struct trust_anchor*
-find_add_tp(struct val_anchors* anchors, ldns_rr* rr)
+find_add_tp(struct val_anchors* anchors, uint8_t* rr, size_t rr_len,
+       size_t dname_len)
 {
        struct trust_anchor* tp;
-       ldns_rdf* own = ldns_rr_owner(rr);
-       tp = anchor_find(anchors, ldns_rdf_data(own), 
-               dname_count_labels(ldns_rdf_data(own)),
-               ldns_rdf_size(own), ldns_rr_get_class(rr));
+       tp = anchor_find(anchors, rr, dname_count_labels(rr), dname_len,
+               ldns_wirerr_get_class(rr, rr_len, dname_len));
        if(tp) {
                if(!tp->autr) {
                        log_err("anchor cannot be with and without autotrust");
@@ -399,22 +428,23 @@ find_add_tp(struct val_anchors* anchors, ldns_rr* rr)
                }
                return tp;
        }
-       tp = autr_tp_create(anchors, ldns_rr_owner(rr), ldns_rr_get_class(rr));
+       tp = autr_tp_create(anchors, rr, dname_len, ldns_wirerr_get_class(rr,
+               rr_len, dname_len));
        lock_basic_lock(&tp->lock);
        return tp;
 }
 
 /** Add trust anchor from RR */
 static struct autr_ta*
-add_trustanchor_frm_rr(struct val_anchors* anchors, ldns_rr* rr, 
-       struct trust_anchor** tp)
+add_trustanchor_frm_rr(struct val_anchors* anchors, uint8_t* rr, size_t rr_len,
+        size_t dname_len, struct trust_anchor** tp)
 {
-       struct autr_ta* ta = autr_ta_create(rr);
+       struct autr_ta* ta = autr_ta_create(rr, rr_len, dname_len);
        if(!ta) 
                return NULL;
-       *tp = find_add_tp(anchors, rr);
+       *tp = find_add_tp(anchors, rr, rr_len, dname_len);
        if(!*tp) {
-               ldns_rr_free(ta->rr);
+               free(ta->rr);
                free(ta);
                return NULL;
        }
@@ -431,34 +461,51 @@ add_trustanchor_frm_rr(struct val_anchors* anchors, ldns_rr* rr,
  * @param str: string with anchor and comments, if any comments.
  * @param tp: trust point returned.
  * @param origin: what to use for @
+ * @param origin_len: length of origin
  * @param prev: previous rr name
+ * @param prev_len: length of prev
  * @param skip: if true, the result is NULL, but not an error, skip it.
  * @return new key in trust point.
  */
 static struct autr_ta*
 add_trustanchor_frm_str(struct val_anchors* anchors, char* str, 
-       struct trust_anchor** tp, ldns_rdf* origin, ldns_rdf** prev, int* skip)
+       struct trust_anchor** tp, uint8_t* origin, size_t origin_len,
+       uint8_t** prev, size_t* prev_len, int* skip)
 {
-        ldns_rr* rr;
-       ldns_status lstatus;
+       uint8_t rr[LDNS_RR_BUF_SIZE];
+       size_t rr_len = sizeof(rr), dname_len;
+       uint8_t* drr;
+       int lstatus;
         if (!str_contains_data(str, ';')) {
                *skip = 1;
                 return NULL; /* empty line */
        }
-        if (LDNS_STATUS_OK !=
-                (lstatus = ldns_rr_new_frm_str(&rr, str, 0, origin, prev)))
+       if(0 != (lstatus = ldns_str2wire_rr_buf(str, rr, &rr_len, &dname_len,
+               0, origin, origin_len, *prev, *prev_len)))
         {
-               log_err("ldns error while converting string to RR: %s",
-                       ldns_get_errorstr_by_id(lstatus));
+               log_err("ldns error while converting string to RR at%d: %s: %s",
+                       LDNS_WIREPARSE_OFFSET(lstatus),
+                       ldns_get_errorstr_parse(lstatus), str);
                 return NULL;
         }
-       if(ldns_rr_get_type(rr) != LDNS_RR_TYPE_DNSKEY &&
-               ldns_rr_get_type(rr) != LDNS_RR_TYPE_DS) {
-               ldns_rr_free(rr);
+       free(*prev);
+       *prev = memdup(rr, dname_len);
+       *prev_len = dname_len;
+       if(!*prev) {
+               log_err("malloc failure in add_trustanchor");
+               return NULL;
+       }
+       if(ldns_wirerr_get_type(rr, rr_len, dname_len)!=LDNS_RR_TYPE_DNSKEY &&
+               ldns_wirerr_get_type(rr, rr_len, dname_len)!=LDNS_RR_TYPE_DS) {
                *skip = 1;
                return NULL; /* only DS and DNSKEY allowed */
        }
-        return add_trustanchor_frm_rr(anchors, rr, tp);
+       drr = memdup(rr, rr_len);
+       if(!drr) {
+               log_err("malloc failure in add trustanchor");
+               return NULL;
+       }
+        return add_trustanchor_frm_rr(anchors, drr, rr_len, dname_len, tp);
 }
 
 /** 
@@ -467,18 +514,22 @@ add_trustanchor_frm_str(struct val_anchors* anchors, char* str,
  * @param str: comments line
  * @param fname: filename
  * @param origin: the $ORIGIN.
+ * @param origin_len: length of origin
  * @param prev: passed to ldns.
+ * @param prev_len: length of prev
  * @param skip: if true, the result is NULL, but not an error, skip it.
  * @return false on failure, otherwise the tp read.
  */
 static struct trust_anchor*
 load_trustanchor(struct val_anchors* anchors, char* str, const char* fname,
-       ldns_rdf* origin, ldns_rdf** prev, int* skip)
+       uint8_t* origin, size_t origin_len, uint8_t** prev, size_t* prev_len,
+       int* skip)
 {
         struct autr_ta* ta = NULL;
         struct trust_anchor* tp = NULL;
 
-        ta = add_trustanchor_frm_str(anchors, str, &tp, origin, prev, skip);
+        ta = add_trustanchor_frm_str(anchors, str, &tp, origin, origin_len,
+               prev, prev_len, skip);
        if(!ta)
                return NULL;
        lock_basic_lock(&tp->lock);
@@ -498,6 +549,186 @@ load_trustanchor(struct val_anchors* anchors, char* str, const char* fname,
         return tp;
 }
 
+/** iterator for DSes from keylist. return true if a next element exists */
+static int
+assemble_iterate_ds(struct autr_ta** list, uint8_t** rr, size_t* rr_len,
+       size_t* dname_len)
+{
+       while(*list) {
+               if(ldns_wirerr_get_type((*list)->rr, (*list)->rr_len,
+                       (*list)->dname_len) == LDNS_RR_TYPE_DS) {
+                       *rr = (*list)->rr;
+                       *rr_len = (*list)->rr_len;
+                       *dname_len = (*list)->dname_len;
+                       *list = (*list)->next;
+                       return 1;
+               }
+               *list = (*list)->next;
+       }
+       return 0;
+}
+
+/** iterator for DNSKEYs from keylist. return true if a next element exists */
+static int
+assemble_iterate_dnskey(struct autr_ta** list, uint8_t** rr, size_t* rr_len,
+       size_t* dname_len)
+{
+       while(*list) {
+               if(ldns_wirerr_get_type((*list)->rr, (*list)->rr_len,
+                  (*list)->dname_len) != LDNS_RR_TYPE_DS &&
+                       ((*list)->s == AUTR_STATE_VALID || 
+                        (*list)->s == AUTR_STATE_MISSING)) {
+                       *rr = (*list)->rr;
+                       *rr_len = (*list)->rr_len;
+                       *dname_len = (*list)->dname_len;
+                       *list = (*list)->next;
+                       return 1;
+               }
+               *list = (*list)->next;
+       }
+       return 0;
+}
+
+/** see if iterator-list has any elements in it, or it is empty */
+static int
+assemble_iterate_hasfirst(int iter(struct autr_ta**, uint8_t**, size_t*,
+       size_t*), struct autr_ta* list)
+{
+       uint8_t* rr = NULL;
+       size_t rr_len = 0, dname_len = 0;
+       return iter(&list, &rr, &rr_len, &dname_len);
+}
+
+/** number of elements in iterator list */
+static size_t
+assemble_iterate_count(int iter(struct autr_ta**, uint8_t**, size_t*,
+       size_t*), struct autr_ta* list)
+{
+       uint8_t* rr = NULL;
+       size_t i = 0, rr_len = 0, dname_len = 0;
+       while(iter(&list, &rr, &rr_len, &dname_len)) {
+               i++;
+       }
+       return i;
+}
+
+/**
+ * Create a ub_packed_rrset_key allocated on the heap.
+ * It therefore does not have the correct ID value, and cannot be used
+ * inside the cache.  It can be used in storage outside of the cache.
+ * Keys for the cache have to be obtained from alloc.h .
+ * @param iter: iterator over the elements in the list.  It filters elements.
+ * @param list: the list.
+ * @return key allocated or NULL on failure.
+ */
+static struct ub_packed_rrset_key* 
+ub_packed_rrset_heap_key(int iter(struct autr_ta**, uint8_t**, size_t*,
+       size_t*), struct autr_ta* list)
+{
+       uint8_t* rr = NULL;
+       size_t rr_len = 0, dname_len = 0;
+       struct ub_packed_rrset_key* k;
+       if(!iter(&list, &rr, &rr_len, &dname_len))
+               return NULL;
+       k = (struct ub_packed_rrset_key*)calloc(1, sizeof(*k));
+       if(!k)
+               return NULL;
+       k->rk.type = htons(ldns_wirerr_get_type(rr, rr_len, dname_len));
+       k->rk.rrset_class = htons(ldns_wirerr_get_class(rr, rr_len, dname_len));
+       k->rk.dname_len = dname_len;
+       k->rk.dname = memdup(rr, dname_len);
+       if(!k->rk.dname) {
+               free(k);
+               return NULL;
+       }
+       return k;
+}
+
+/**
+ * Create packed_rrset data on the heap.
+ * @param iter: iterator over the elements in the list.  It filters elements.
+ * @param list: the list.
+ * @return data allocated or NULL on failure.
+ */
+static struct packed_rrset_data* 
+packed_rrset_heap_data(int iter(struct autr_ta**, uint8_t**, size_t*,
+       size_t*), struct autr_ta* list)
+{
+       uint8_t* rr = NULL;
+       size_t rr_len = 0, dname_len = 0;
+       struct packed_rrset_data* data;
+       size_t count=0, rrsig_count=0, len=0, i, total;
+       uint8_t* nextrdata;
+       struct autr_ta* list_i;
+       time_t ttl = 0;
+
+       list_i = list;
+       while(iter(&list_i, &rr, &rr_len, &dname_len)) {
+               if(ldns_wirerr_get_type(rr, rr_len, dname_len) ==
+                       LDNS_RR_TYPE_RRSIG)
+                       rrsig_count++;
+               else    count++;
+               /* sizeof the rdlength + rdatalen */
+               len += 2 + ldns_wirerr_get_rdatalen(rr, rr_len, dname_len);
+               ttl = (time_t)ldns_wirerr_get_ttl(rr, rr_len, dname_len);
+       }
+       if(count == 0 && rrsig_count == 0)
+               return NULL;
+
+       /* allocate */
+       total = count + rrsig_count;
+       len += sizeof(*data) + total*(sizeof(size_t) + sizeof(time_t) + 
+               sizeof(uint8_t*));
+       data = (struct packed_rrset_data*)calloc(1, len);
+       if(!data)
+               return NULL;
+
+       /* fill it */
+       data->ttl = ttl;
+       data->count = count;
+       data->rrsig_count = rrsig_count;
+       data->rr_len = (size_t*)((uint8_t*)data +
+               sizeof(struct packed_rrset_data));
+       data->rr_data = (uint8_t**)&(data->rr_len[total]);
+       data->rr_ttl = (time_t*)&(data->rr_data[total]);
+       nextrdata = (uint8_t*)&(data->rr_ttl[total]);
+
+       /* fill out len, ttl, fields */
+       list_i = list;
+       i = 0;
+       while(iter(&list_i, &rr, &rr_len, &dname_len)) {
+               data->rr_ttl[i] = (time_t)ldns_wirerr_get_ttl(rr, rr_len,
+                       dname_len);
+               if(data->rr_ttl[i] < data->ttl)
+                       data->ttl = data->rr_ttl[i];
+               data->rr_len[i] = 2 /* the rdlength */ +
+                       ldns_wirerr_get_rdatalen(rr, rr_len, dname_len);
+               i++;
+       }
+
+       /* fixup rest of ptrs */
+       for(i=0; i<total; i++) {
+               data->rr_data[i] = nextrdata;
+               nextrdata += data->rr_len[i];
+       }
+
+       /* copy data in there */
+       list_i = list;
+       i = 0;
+       while(iter(&list_i, &rr, &rr_len, &dname_len)) {
+               memmove(data->rr_data[i],
+                       ldns_wirerr_get_rdatawl(rr, rr_len, dname_len),
+                       data->rr_len[i]);
+               i++;
+       }
+
+       if(data->rrsig_count && data->count == 0) {
+               data->count = data->rrsig_count; /* rrset type is RRSIG */
+               data->rrsig_count = 0;
+       }
+       return data;
+}
+
 /**
  * Assemble the trust anchors into DS and DNSKEY packed rrsets.
  * Uses only VALID and MISSING DNSKEYs.
@@ -508,60 +739,38 @@ load_trustanchor(struct val_anchors* anchors, char* str, const char* fname,
 static int 
 autr_assemble(struct trust_anchor* tp)
 {
-       ldns_rr_list* ds, *dnskey;
-       struct autr_ta* ta;
        struct ub_packed_rrset_key* ubds=NULL, *ubdnskey=NULL;
 
-       ds = ldns_rr_list_new();
-       dnskey = ldns_rr_list_new();
-       if(!ds || !dnskey) {
-               ldns_rr_list_free(ds);
-               ldns_rr_list_free(dnskey);
-               return 0;
-       }
-       for(ta = tp->autr->keys; ta; ta = ta->next) {
-               if(ldns_rr_get_type(ta->rr) == LDNS_RR_TYPE_DS) {
-                       if(!ldns_rr_list_push_rr(ds, ta->rr)) {
-                               ldns_rr_list_free(ds);
-                               ldns_rr_list_free(dnskey);
-                               return 0;
-                       }
-               } else if(ta->s == AUTR_STATE_VALID || 
-                       ta->s == AUTR_STATE_MISSING) {
-                       if(!ldns_rr_list_push_rr(dnskey, ta->rr)) {
-                               ldns_rr_list_free(ds);
-                               ldns_rr_list_free(dnskey);
-                               return 0;
-                       }
-               }
-       }
-
        /* make packed rrset keys - malloced with no ID number, they
         * are not in the cache */
        /* make packed rrset data (if there is a key) */
-
-       if(ldns_rr_list_rr_count(ds) > 0) {
-               ubds = ub_packed_rrset_heap_key(ds);
-               if(!ubds) 
+       if(assemble_iterate_hasfirst(assemble_iterate_ds, tp->autr->keys)) {
+               ubds = ub_packed_rrset_heap_key(
+                       assemble_iterate_ds, tp->autr->keys);
+               if(!ubds)
                        goto error_cleanup;
-               ubds->entry.data = packed_rrset_heap_data(ds);
+               ubds->entry.data = packed_rrset_heap_data(
+                       assemble_iterate_ds, tp->autr->keys);
                if(!ubds->entry.data)
                        goto error_cleanup;
        }
-       if(ldns_rr_list_rr_count(dnskey) > 0) {
-               ubdnskey = ub_packed_rrset_heap_key(dnskey);
+
+       /* make packed DNSKEY data */
+       if(assemble_iterate_hasfirst(assemble_iterate_dnskey, tp->autr->keys)) {
+               ubdnskey = ub_packed_rrset_heap_key(
+                       assemble_iterate_dnskey, tp->autr->keys);
                if(!ubdnskey)
                        goto error_cleanup;
-               ubdnskey->entry.data = packed_rrset_heap_data(dnskey);
+               ubdnskey->entry.data = packed_rrset_heap_data(
+                       assemble_iterate_dnskey, tp->autr->keys);
                if(!ubdnskey->entry.data) {
                error_cleanup:
                        autr_rrset_delete(ubds);
                        autr_rrset_delete(ubdnskey);
-                       ldns_rr_list_free(ds);
-                       ldns_rr_list_free(dnskey);
                        return 0;
                }
        }
+
        /* we have prepared the new keys so nothing can go wrong any more.
         * And we are sure we cannot be left without trustanchor after
         * any errors. Put in the new keys and remove old ones. */
@@ -573,11 +782,10 @@ autr_assemble(struct trust_anchor* tp)
        /* assign the data to replace the old */
        tp->ds_rrset = ubds;
        tp->dnskey_rrset = ubdnskey;
-       tp->numDS = ldns_rr_list_rr_count(ds);
-       tp->numDNSKEY = ldns_rr_list_rr_count(dnskey);
-
-       ldns_rr_list_free(ds);
-       ldns_rr_list_free(dnskey);
+       tp->numDS = assemble_iterate_count(assemble_iterate_ds,
+               tp->autr->keys);
+       tp->numDNSKEY = assemble_iterate_count(assemble_iterate_dnskey,
+               tp->autr->keys);
        return 1;
 }
 
@@ -601,27 +809,28 @@ parse_id(struct val_anchors* anchors, char* line)
 {
        struct trust_anchor *tp;
        int r;
-       ldns_rdf* rdf;
        uint16_t dclass;
+       uint8_t* dname;
+       size_t dname_len;
        /* read the owner name */
        char* next = strchr(line, ' ');
        if(!next)
                return NULL;
        next[0] = 0;
-       rdf = ldns_dname_new_frm_str(line);
-       if(!rdf)
+       dname = ldns_str2wire_dname(line, &dname_len);
+       if(!dname)
                return NULL;
 
        /* read the class */
        dclass = parse_int(next+1, &r);
        if(r == -1) {
-               ldns_rdf_deep_free(rdf);
+               free(dname);
                return NULL;
        }
 
        /* find the trust point */
-       tp = autr_tp_create(anchors, rdf, dclass);
-       ldns_rdf_deep_free(rdf);
+       tp = autr_tp_create(anchors, dname, dname_len, dclass);
+       free(dname);
        return tp;
 }
 
@@ -690,17 +899,19 @@ parse_var_line(char* line, struct val_anchors* anchors,
 
 /** handle origin lines */
 static int
-handle_origin(char* line, ldns_rdf** origin)
+handle_origin(char* line, uint8_t** origin, size_t* origin_len)
 {
+       size_t len = 0;
        while(isspace((int)*line))
                line++;
        if(strncmp(line, "$ORIGIN", 7) != 0)
                return 0;
-       ldns_rdf_deep_free(*origin);
+       free(*origin);
        line += 7;
        while(isspace((int)*line))
                line++;
-       *origin = ldns_dname_new_frm_str(line);
+       *origin = ldns_str2wire_dname(line, &len);
+       *origin_len = len;
        if(!*origin)
                log_warn("malloc failure or parse error in $ORIGIN");
        return 1;
@@ -781,7 +992,8 @@ int autr_read_file(struct val_anchors* anchors, const char* nm)
        struct trust_anchor *tp = NULL, *tp2;
        int r;
        /* for $ORIGIN parsing */
-       ldns_rdf *origin=NULL, *prev=NULL;
+       uint8_t *origin=NULL, *prev=NULL;
+       size_t origin_len=0, prev_len=0;
 
         if (!(fd = fopen(nm, "r"))) {
                 log_err("unable to open %s for reading: %s", 
@@ -794,25 +1006,25 @@ int autr_read_file(struct val_anchors* anchors, const char* nm)
                        log_err("could not parse auto-trust-anchor-file "
                                "%s line %d", nm, line_nr);
                        fclose(fd);
-                       ldns_rdf_deep_free(origin);
-                       ldns_rdf_deep_free(prev);
+                       free(origin);
+                       free(prev);
                        return 0;
                } else if(r == 1) {
                        continue;
                } else if(r == 2) {
                        log_warn("trust anchor %s has been revoked", nm);
                        fclose(fd);
-                       ldns_rdf_deep_free(origin);
-                       ldns_rdf_deep_free(prev);
+                       free(origin);
+                       free(prev);
                        return 1;
                }
                if (!str_contains_data(line, ';'))
                        continue; /* empty lines allowed */
-               if(handle_origin(line, &origin))
+               if(handle_origin(line, &origin, &origin_len))
                        continue;
                r = 0;
-                if(!(tp2=load_trustanchor(anchors, line, nm, origin, &prev, 
-                       &r))) {
+                if(!(tp2=load_trustanchor(anchors, line, nm, origin,
+                       origin_len, &prev, &prev_len, &r))) {
                        if(!r) log_err("failed to load trust anchor from %s "
                                "at line %i, skipping", nm, line_nr);
                         /* try to do the rest */
@@ -823,15 +1035,15 @@ int autr_read_file(struct val_anchors* anchors, const char* nm)
                                "the file may only contain keys for one name, "
                                "remove keys for other domain names", nm);
                        fclose(fd);
-                       ldns_rdf_deep_free(origin);
-                       ldns_rdf_deep_free(prev);
+                       free(origin);
+                       free(prev);
                        return 0;
                }
                tp = tp2;
         }
         fclose(fd);
-       ldns_rdf_deep_free(origin);
-       ldns_rdf_deep_free(prev);
+       free(origin);
+       free(prev);
        if(!tp) {
                log_err("failed to read %s", nm);
                return 0;
@@ -865,41 +1077,24 @@ trustanchor_state2str(autr_state_t s)
 
 /** print ID to file */
 static int
-print_id(FILE* out, char* fname, struct module_env* env, 
-       uint8_t* nm, size_t nmlen, uint16_t dclass)
+print_id(FILE* out, char* fname, uint8_t* nm, size_t nmlen, uint16_t dclass)
 {
-       ldns_rdf rdf;
-#ifdef UNBOUND_DEBUG
-       ldns_status s;
-#endif
-
-       memset(&rdf, 0, sizeof(rdf));
-       ldns_rdf_set_data(&rdf, nm);
-       ldns_rdf_set_size(&rdf, nmlen);
-       ldns_rdf_set_type(&rdf, LDNS_RDF_TYPE_DNAME);
-
-       ldns_buffer_clear(env->scratch_buffer);
-#ifdef UNBOUND_DEBUG
-       s =
-#else
-       (void)
-#endif
-       ldns_rdf2buffer_str_dname(env->scratch_buffer, &rdf);
-       log_assert(s == LDNS_STATUS_OK);
-       ldns_buffer_write_u8(env->scratch_buffer, 0);
-       ldns_buffer_flip(env->scratch_buffer);
-       if(fprintf(out, ";;id: %s %d\n", 
-               (char*)ldns_buffer_begin(env->scratch_buffer),
-               (int)dclass) < 0) {
+       char* s = ldns_wire2str_dname(nm, nmlen);
+       if(!s) {
+               log_err("malloc failure in write to %s", fname);
+               return 0;
+       }
+       if(fprintf(out, ";;id: %s %d\n", s, (int)dclass) < 0) {
                log_err("could not write to %s: %s", fname, strerror(errno));
+               free(s);
                return 0;
        }
+       free(s);
        return 1;
 }
 
 static int
-autr_write_contents(FILE* out, char* fn, struct module_env* env,
-       struct trust_anchor* tp)
+autr_write_contents(FILE* out, char* fn, struct trust_anchor* tp)
 {
        char tmi[32];
        struct autr_ta* ta;
@@ -921,7 +1116,7 @@ autr_write_contents(FILE* out, char* fn, struct module_env* env,
                   return 0;
                }
        }
-       if(!print_id(out, fn, env, tp->name, tp->namelen, tp->dclass)) {
+       if(!print_id(out, fn, tp->name, tp->namelen, tp->dclass)) {
                return 0;
        }
        if(fprintf(out, ";;last_queried: %u ;;%s", 
@@ -949,9 +1144,10 @@ autr_write_contents(FILE* out, char* fn, struct module_env* env,
                if(ta->s == AUTR_STATE_REMOVED)
                        continue;
                /* only store keys */
-               if(ldns_rr_get_type(ta->rr) != LDNS_RR_TYPE_DNSKEY)
+               if(ldns_wirerr_get_type(ta->rr, ta->rr_len, ta->dname_len)
+                       != LDNS_RR_TYPE_DNSKEY)
                        continue;
-               str = ldns_rr2str(ta->rr);
+               str = ldns_wire2str_rr(ta->rr, ta->rr_len);
                if(!str || !str[0]) {
                        free(str);
                        log_err("malloc failure writing %s", fn);
@@ -992,7 +1188,7 @@ void autr_write_file(struct module_env* env, struct trust_anchor* tp)
                        tempf, strerror(errno));
                return;
        }
-       if(!autr_write_contents(out, tempf, env, tp)) {
+       if(!autr_write_contents(out, tempf, tp)) {
                /* failed to write contents (completely) */
                fclose(out);
                unlink(tempf);
@@ -1036,19 +1232,25 @@ verify_dnskey(struct module_env* env, struct val_env* ve,
        return sec == sec_status_secure;
 }
 
+static int32_t
+rrsig_get_expiry(uint8_t* d, size_t len)
+{
+       /* rrsig: 2(rdlen), 2(type) 1(alg) 1(v) 4(origttl), then 4(expi), (4)incep) */
+       if(len < 2+8+4)
+               return 0;
+       return ldns_read_uint32(d+2+8);
+}
+
 /** Find minimum expiration interval from signatures */
 static time_t
-min_expiry(struct module_env* env, ldns_rr_list* rrset)
+min_expiry(struct module_env* env, struct packed_rrset_data* dd)
 {
        size_t i;
        int32_t t, r = 15 * 24 * 3600; /* 15 days max */
-       for(i=0; i<ldns_rr_list_rr_count(rrset); i++) {
-               ldns_rr* rr = ldns_rr_list_rr(rrset, i);
-               if(ldns_rr_get_type(rr) != LDNS_RR_TYPE_RRSIG)
-                       continue;
-               t = ldns_rdf2native_int32(ldns_rr_rrsig_expiration(rr));
+       for(i=dd->count; i<dd->count+dd->rrsig_count; i++) {
+               t = rrsig_get_expiry(dd->rr_data[i], dd->rr_len[i]);
                if((int32_t)t - (int32_t)*env->now > 0) {
-                       t -= *env->now;
+                       t -= (int32_t)*env->now;
                        if(t < r)
                                r = t;
                }
@@ -1092,131 +1294,92 @@ seen_revoked_trustanchor(struct autr_ta* ta, uint8_t revoked)
 static void
 revoke_dnskey(struct autr_ta* ta, int off)
 {
-        ldns_rdf* rdf;
-        uint16_t flags;
-       log_assert(ta && ta->rr);
-       if(ldns_rr_get_type(ta->rr) != LDNS_RR_TYPE_DNSKEY)
+       uint16_t flags;
+       uint8_t* data;
+       if(ldns_wirerr_get_type(ta->rr, ta->rr_len, ta->dname_len) !=
+               LDNS_RR_TYPE_DNSKEY)
                return;
-       rdf = ldns_rr_dnskey_flags(ta->rr);
-       flags = ldns_read_uint16(ldns_rdf_data(rdf));
-
+       if(ldns_wirerr_get_rdatalen(ta->rr, ta->rr_len, ta->dname_len) < 2)
+               return;
+       data = ldns_wirerr_get_rdata(ta->rr, ta->rr_len, ta->dname_len);
+       flags = ldns_read_uint16(data);
        if (off && (flags&LDNS_KEY_REVOKE_KEY))
                flags ^= LDNS_KEY_REVOKE_KEY; /* flip */
        else
                flags |= LDNS_KEY_REVOKE_KEY;
-       ldns_write_uint16(ldns_rdf_data(rdf), flags);
+       ldns_write_uint16(data, flags);
 }
 
-/** Compare two RR buffers skipping the REVOKED bit */
+/** Compare two RRs skipping the REVOKED bit. Pass rdata(no len) */
 static int
-ldns_rr_compare_wire_skip_revbit(ldns_buffer* rr1_buf, ldns_buffer* rr2_buf)
-{
-       size_t rr1_len, rr2_len, min_len, i, offset;
-       rr1_len = ldns_buffer_capacity(rr1_buf);
-       rr2_len = ldns_buffer_capacity(rr2_buf);
-       /* jump past dname (checked in earlier part) and especially past TTL */
-       offset = 0;
-       while (offset < rr1_len && *ldns_buffer_at(rr1_buf, offset) != 0)
-               offset += *ldns_buffer_at(rr1_buf, offset) + 1;
-       /* jump to rdata section (PAST the rdata length field) */
-       offset += 11; /* 0-dname-end + type + class + ttl + rdatalen */
-       min_len = (rr1_len < rr2_len) ? rr1_len : rr2_len;
+dnskey_compare_skip_revbit(uint8_t* a, size_t a_len, uint8_t* b, size_t b_len)
+{
+       size_t i;
+       if(a_len != b_len)
+               return -1;
        /* compare RRs RDATA byte for byte. */
-       for(i = offset; i < min_len; i++)
+       for(i = 0; i < a_len; i++)
        {
-               uint8_t *rdf1, *rdf2;
-               rdf1 = ldns_buffer_at(rr1_buf, i);
-               rdf2 = ldns_buffer_at(rr2_buf, i);
-               if (i==(offset+1))
-               {
+               uint8_t rdf1, rdf2;
+               rdf1 = a[i];
+               rdf2 = b[i];
+               if(i==1) {
                        /* this is the second part of the flags field */
-                       *rdf1 = *rdf1 | LDNS_KEY_REVOKE_KEY;
-                       *rdf2 = *rdf2 | LDNS_KEY_REVOKE_KEY;
+                       rdf1 |= LDNS_KEY_REVOKE_KEY;
+                       rdf2 |= LDNS_KEY_REVOKE_KEY;
                }
-               if (*rdf1 < *rdf2)      return -1;
-               else if (*rdf1 > *rdf2) return 1;
+               if (rdf1 < rdf2)        return -1;
+               else if (rdf1 > rdf2)   return 1;
         }
        return 0;
 }
 
-/** Compare two RRs skipping the REVOKED bit */
-static int
-ldns_rr_compare_skip_revbit(const ldns_rr* rr1, const ldns_rr* rr2, int* result)
-{
-       size_t rr1_len, rr2_len;
-       ldns_buffer* rr1_buf;
-       ldns_buffer* rr2_buf;
-
-       *result = ldns_rr_compare_no_rdata(rr1, rr2);
-       if (*result == 0)
-       {
-               rr1_len = ldns_rr_uncompressed_size(rr1);
-               rr2_len = ldns_rr_uncompressed_size(rr2);
-               rr1_buf = ldns_buffer_new(rr1_len);
-               rr2_buf = ldns_buffer_new(rr2_len);
-               if(!rr1_buf || !rr2_buf) {
-                       ldns_buffer_free(rr1_buf);
-                       ldns_buffer_free(rr2_buf);
-                       return 0;
-               }
-               if (ldns_rr2buffer_wire_canonical(rr1_buf, rr1,
-                       LDNS_SECTION_ANY) != LDNS_STATUS_OK)
-               {
-                       ldns_buffer_free(rr1_buf);
-                       ldns_buffer_free(rr2_buf);
-                       return 0;
-               }
-               if (ldns_rr2buffer_wire_canonical(rr2_buf, rr2,
-                       LDNS_SECTION_ANY) != LDNS_STATUS_OK) {
-                       ldns_buffer_free(rr1_buf);
-                       ldns_buffer_free(rr2_buf);
-                       return 0;
-               }
-               *result = ldns_rr_compare_wire_skip_revbit(rr1_buf, rr2_buf);
-               ldns_buffer_free(rr1_buf);
-               ldns_buffer_free(rr2_buf);
-       }
-       return 1;
-}
-
 
-/** compare two trust anchors */
+/** compare trust anchor with rdata, 0 if equal. Pass rdata(no len) */
 static int
-ta_compare(ldns_rr* a, ldns_rr* b, int* result)
-{
-       if (!a && !b)   *result = 0;
-       else if (!a)    *result = -1;
-       else if (!b)    *result = 1;
-       else if (ldns_rr_get_type(a) != ldns_rr_get_type(b))
-               *result = (int)ldns_rr_get_type(a) - (int)ldns_rr_get_type(b);
-       else if (ldns_rr_get_type(a) == LDNS_RR_TYPE_DNSKEY) {
-               if(!ldns_rr_compare_skip_revbit(a, b, result))
-                       return 0;
+ta_compare(struct autr_ta* a, uint16_t t, uint8_t* b, size_t b_len)
+{
+       if(!a) return -1;
+       else if(!b) return -1;
+       else if(ldns_wirerr_get_type(a->rr, a->rr_len, a->dname_len) != t)
+               return (int)ldns_wirerr_get_type(a->rr, a->rr_len,
+                       a->dname_len) - (int)t;
+       else if(t == LDNS_RR_TYPE_DNSKEY) {
+               return dnskey_compare_skip_revbit(
+                       ldns_wirerr_get_rdata(a->rr, a->rr_len, a->dname_len),
+                       ldns_wirerr_get_rdatalen(a->rr, a->rr_len,
+                       a->dname_len), b, b_len);
+       }
+       else if(t == LDNS_RR_TYPE_DS) {
+               if(ldns_wirerr_get_rdatalen(a->rr, a->rr_len, a->dname_len) !=
+                       b_len)
+                       return -1;
+               return memcmp(ldns_wirerr_get_rdata(a->rr,
+                       a->rr_len, a->dname_len), b, b_len);
        }
-       else if (ldns_rr_get_type(a) == LDNS_RR_TYPE_DS)
-               *result = ldns_rr_compare(a, b);
-       else    *result = -1;
-       return 1;
+       return -1;
 }
 
 /** 
  * Find key
  * @param tp: to search in
- * @param rr: to look for
+ * @param t: rr type of the rdata.
+ * @param rdata: to look for  (no rdatalen in it)
+ * @param rdata_len: length of rdata
  * @param result: returns NULL or the ta key looked for.
  * @return false on malloc failure during search. if true examine result.
  */
 static int
-find_key(struct trust_anchor* tp, ldns_rr* rr, struct autr_ta** result)
+find_key(struct trust_anchor* tp, uint16_t t, uint8_t* rdata, size_t rdata_len,
+       struct autr_ta** result)
 {
        struct autr_ta* ta;
-       int ret;
-       if(!tp || !rr)
+       if(!tp || !rdata) {
+               *result = NULL;
                return 0;
+       }
        for(ta=tp->autr->keys; ta; ta=ta->next) {
-               if(!ta_compare(ta->rr, rr, &ret))
-                       return 0;
-               if(ret == 0) {
+               if(ta_compare(ta, t, rdata, rdata_len) == 0) {
                        *result = ta;
                        return 1;
                }
@@ -1225,17 +1388,30 @@ find_key(struct trust_anchor* tp, ldns_rr* rr, struct autr_ta** result)
        return 1;
 }
 
-/** add key and clone RR and tp already locked */
+/** add key and clone RR and tp already locked. rdata without rdlen. */
 static struct autr_ta*
-add_key(struct trust_anchor* tp, ldns_rr* rr)
+add_key(struct trust_anchor* tp, uint32_t ttl, uint8_t* rdata, size_t rdata_len)
 {
-       ldns_rr* c;
        struct autr_ta* ta;
-       c = ldns_rr_clone(rr);
-       if(!c) return NULL;
-       ta = autr_ta_create(c);
+       uint8_t* rr;
+       size_t rr_len, dname_len;
+       uint16_t rrtype = htons(LDNS_RR_TYPE_DNSKEY);
+       uint16_t rrclass = htons(LDNS_RR_CLASS_IN);
+       uint16_t rdlen = htons(rdata_len);
+       dname_len = tp->namelen;
+       ttl = htonl(ttl);
+       rr_len = dname_len + 10 /* type,class,ttl,rdatalen */ + rdata_len;
+       rr = (uint8_t*)malloc(rr_len);
+       if(!rr) return NULL;
+       memmove(rr, tp->name, tp->namelen);
+       memmove(rr+dname_len, &rrtype, 2);
+       memmove(rr+dname_len+2, &rrclass, 2);
+       memmove(rr+dname_len+4, &ttl, 4);
+       memmove(rr+dname_len+8, &rdlen, 2);
+       memmove(rr+dname_len+10, rdata, rdata_len);
+       ta = autr_ta_create(rr, rr_len, dname_len);
        if(!ta) {
-               ldns_rr_free(c);
+               /* rr freed in autr_ta_create */
                return NULL;
        }
        /* link in, tp already locked */
@@ -1308,21 +1484,19 @@ check_contains_revoked(struct module_env* env, struct val_env* ve,
        struct trust_anchor* tp, struct ub_packed_rrset_key* dnskey_rrset,
        int* changed)
 {
-       ldns_rr_list* r = packed_rrset_to_rr_list(dnskey_rrset, 
-               env->scratch_buffer);
+       struct packed_rrset_data* dd = (struct packed_rrset_data*)
+               dnskey_rrset->entry.data;
        size_t i;
-       if(!r) {
-               log_err("malloc failure");
-               return;
-       }
-       for(i=0; i<ldns_rr_list_rr_count(r); i++) {
-               ldns_rr* rr = ldns_rr_list_rr(r, i);
+       log_assert(ntohs(dnskey_rrset->rk.type) == LDNS_RR_TYPE_DNSKEY);
+       for(i=0; i<dd->count; i++) {
                struct autr_ta* ta = NULL;
-               if(ldns_rr_get_type(rr) != LDNS_RR_TYPE_DNSKEY)
-                       continue;
-               if(!rr_is_dnskey_sep(rr) || !rr_is_dnskey_revoked(rr))
+               if(!rr_is_dnskey_sep(ntohs(dnskey_rrset->rk.type),
+                       dd->rr_data[i]+2, dd->rr_len[i]-2) ||
+                       !rr_is_dnskey_revoked(ntohs(dnskey_rrset->rk.type),
+                       dd->rr_data[i]+2, dd->rr_len[i]-2))
                        continue; /* not a revoked KSK */
-               if(!find_key(tp, rr, &ta)) {
+               if(!find_key(tp, ntohs(dnskey_rrset->rk.type),
+                       dd->rr_data[i]+2, dd->rr_len[i]-2, &ta)) {
                        log_err("malloc failure");
                        continue; /* malloc fail in compare*/
                }
@@ -1330,8 +1504,18 @@ check_contains_revoked(struct module_env* env, struct val_env* ve,
                        continue; /* key not found */
                if(rr_is_selfsigned_revoked(env, ve, dnskey_rrset, i)) {
                        /* checked if there is an rrsig signed by this key. */
-                       log_assert(dnskey_calc_keytag(dnskey_rrset, i) ==
-                               ldns_calc_keytag(rr)); /* checks conversion*/
+                       /* same keytag, but stored can be revoked already, so 
+                        * compare keytags, with +0 or +128(REVOKE flag) */
+                       log_assert(dnskey_calc_keytag(dnskey_rrset, i)-128 ==
+                               ldns_calc_keytag_raw(ldns_wirerr_get_rdata(
+                               ta->rr, ta->rr_len, ta->dname_len),
+                               ldns_wirerr_get_rdatalen(ta->rr, ta->rr_len,
+                               ta->dname_len)) ||
+                               dnskey_calc_keytag(dnskey_rrset, i) ==
+                               ldns_calc_keytag_raw(ldns_wirerr_get_rdata(
+                               ta->rr, ta->rr_len, ta->dname_len),
+                               ldns_wirerr_get_rdatalen(ta->rr, ta->rr_len,
+                               ta->dname_len))); /* checks conversion*/
                        verbose_key(ta, VERB_ALGO, "is self-signed revoked");
                        if(!ta->revoked) 
                                *changed = 1;
@@ -1339,7 +1523,6 @@ check_contains_revoked(struct module_env* env, struct val_env* ve,
                        do_revoked(env, ta, changed);
                }
        }
-       ldns_rr_list_deep_free(r);
 }
 
 /** See if a DNSKEY is verified by one of the DSes */
@@ -1386,20 +1569,18 @@ update_events(struct module_env* env, struct val_env* ve,
        struct trust_anchor* tp, struct ub_packed_rrset_key* dnskey_rrset, 
        int* changed)
 {
-       ldns_rr_list* r = packed_rrset_to_rr_list(dnskey_rrset, 
-               env->scratch_buffer);
+       struct packed_rrset_data* dd = (struct packed_rrset_data*)
+               dnskey_rrset->entry.data;
        size_t i;
-       if(!r) 
-               return 0;
+       log_assert(ntohs(dnskey_rrset->rk.type) == LDNS_RR_TYPE_DNSKEY);
        init_events(tp);
-       for(i=0; i<ldns_rr_list_rr_count(r); i++) {
-               ldns_rr* rr = ldns_rr_list_rr(r, i);
+       for(i=0; i<dd->count; i++) {
                struct autr_ta* ta = NULL;
-               if(ldns_rr_get_type(rr) != LDNS_RR_TYPE_DNSKEY)
-                       continue;
-               if(!rr_is_dnskey_sep(rr))
+               if(!rr_is_dnskey_sep(ntohs(dnskey_rrset->rk.type),
+                       dd->rr_data[i]+2, dd->rr_len[i]-2))
                        continue;
-               if(rr_is_dnskey_revoked(rr)) {
+               if(rr_is_dnskey_revoked(ntohs(dnskey_rrset->rk.type),
+                       dd->rr_data[i]+2, dd->rr_len[i]-2)) {
                        /* self-signed revoked keys already detected before,
                         * other revoked keys are not 'added' again */
                        continue;
@@ -1415,12 +1596,13 @@ update_events(struct module_env* env, struct val_env* ve,
                }
 
                /* is it new? if revocation bit set, find the unrevoked key */
-               if(!find_key(tp, rr, &ta)) {
-                       ldns_rr_list_deep_free(r); /* malloc fail in compare*/
+               if(!find_key(tp, ntohs(dnskey_rrset->rk.type),
+                       dd->rr_data[i]+2, dd->rr_len[i]-2, &ta)) {
                        return 0;
                }
                if(!ta) {
-                       ta = add_key(tp, rr);
+                       ta = add_key(tp, (uint32_t)dd->rr_ttl[i],
+                               dd->rr_data[i]+2, dd->rr_len[i]-2);
                        *changed = 1;
                        /* first time seen, do we have DSes? if match: VALID */
                        if(ta && tp->ds_rrset && key_matches_a_ds(env, ve,
@@ -1430,14 +1612,12 @@ update_events(struct module_env* env, struct val_env* ve,
                        }
                }
                if(!ta) {
-                       ldns_rr_list_deep_free(r);
                        return 0;
                }
                seen_trustanchor(ta, 1);
                verbose_key(ta, VERB_ALGO, "in DNS response");
        }
-       set_tp_times(tp, min_expiry(env, r), key_ttl(dnskey_rrset), changed);
-       ldns_rr_list_deep_free(r);
+       set_tp_times(tp, min_expiry(env, dd), key_ttl(dnskey_rrset), changed);
        return 1;
 }
 
@@ -1628,16 +1808,17 @@ init_zsk_to_ksk(struct module_env* env, struct trust_anchor* tp, int* changed)
        int validksk = 0;
        for(anchor = tp->autr->keys; anchor; anchor = anchor->next) {
                /* last_change test makes sure it was manually configured */
-                if (ldns_rr_get_type(anchor->rr) == LDNS_RR_TYPE_DNSKEY &&
+               if(ldns_wirerr_get_type(anchor->rr, anchor->rr_len,
+                       anchor->dname_len) == LDNS_RR_TYPE_DNSKEY &&
                        anchor->last_change == 0 && 
-                       !rr_is_dnskey_sep(anchor->rr) &&
+                       !ta_is_dnskey_sep(anchor) &&
                        anchor->s == AUTR_STATE_VALID)
                         validzsk++;
        }
        if(validzsk == 0)
                return 0;
        for(anchor = tp->autr->keys; anchor; anchor = anchor->next) {
-                if (rr_is_dnskey_sep(anchor->rr) && 
+                if (ta_is_dnskey_sep(anchor) && 
                        anchor->s == AUTR_STATE_ADDPEND) {
                        verbose_key(anchor, VERB_ALGO, "trust KSK from "
                                "ZSK(config)");
@@ -1660,7 +1841,7 @@ remove_missing_trustanchors(struct module_env* env, struct trust_anchor* tp,
        /* see if we have anchors that are valid */
        for(anchor = tp->autr->keys; anchor; anchor = anchor->next) {
                /* Only do KSKs */
-                if (!rr_is_dnskey_sep(anchor->rr))
+                if (!ta_is_dnskey_sep(anchor))
                         continue;
                 if (anchor->s == AUTR_STATE_VALID)
                         valid++;
@@ -1683,7 +1864,7 @@ remove_missing_trustanchors(struct module_env* env, struct trust_anchor* tp,
                if(anchor->s == AUTR_STATE_START)
                        continue;
                /* remove ZSKs if a KSK is present */
-                if (!rr_is_dnskey_sep(anchor->rr)) {
+                if (!ta_is_dnskey_sep(anchor)) {
                        if(valid > 0) {
                                verbose_key(anchor, VERB_ALGO, "remove ZSK "
                                        "[%d key(s) VALID]", valid);
@@ -1718,7 +1899,7 @@ do_statetable(struct module_env* env, struct trust_anchor* tp, int* changed)
        struct autr_ta* anchor;
        for(anchor = tp->autr->keys; anchor; anchor = anchor->next) {
                /* Only do KSKs */
-               if(!rr_is_dnskey_sep(anchor->rr))
+               if(!ta_is_dnskey_sep(anchor))
                        continue;
                anchor_state_update(env, anchor, changed);
        }
@@ -1732,7 +1913,7 @@ autr_holddown_exceed(struct module_env* env, struct trust_anchor* tp, int* c)
 {
        struct autr_ta* anchor;
        for(anchor = tp->autr->keys; anchor; anchor = anchor->next) {
-               if(rr_is_dnskey_sep(anchor->rr) && 
+               if(ta_is_dnskey_sep(anchor) && 
                        anchor->s == AUTR_STATE_ADDPEND)
                        do_addtime(env, anchor, c);
        }
@@ -1748,10 +1929,11 @@ autr_cleanup_keys(struct trust_anchor* tp)
        while(p) {
                /* do we want to remove this key? */
                if(p->s == AUTR_STATE_START || p->s == AUTR_STATE_REMOVED ||
-                       ldns_rr_get_type(p->rr) != LDNS_RR_TYPE_DNSKEY) {
+                       ldns_wirerr_get_type(p->rr, p->rr_len, p->dname_len)
+                       != LDNS_RR_TYPE_DNSKEY) {
                        struct autr_ta* np = p->next;
                        /* remove */
-                       ldns_rr_free(p->rr);
+                       free(p->rr);
                        free(p);
                        /* snip and go to next item */
                        *prevp = np;
@@ -2023,7 +2205,7 @@ static void
 autr_debug_print_ta(struct autr_ta* ta)
 {
        char buf[32];
-       char* str = ldns_rr2str(ta->rr);
+       char* str = ldns_wire2str_rr(ta->rr, ta->rr_len);
        if(!str) {
                log_info("out of memory in debug_print_ta");
                return;
@@ -2049,20 +2231,11 @@ autr_debug_print_tp(struct trust_anchor* tp)
        log_info("trust point %s : %d", buf, (int)tp->dclass);
        log_info("assembled %d DS and %d DNSKEYs", 
                (int)tp->numDS, (int)tp->numDNSKEY);
-       if(0) { /* turned off because it prints to stderr */
-               ldns_buffer* bf = ldns_buffer_new(70000);
-               ldns_rr_list* list;
-               if(tp->ds_rrset) {
-                       list = packed_rrset_to_rr_list(tp->ds_rrset, bf);
-                       ldns_rr_list_print(stderr, list);
-                       ldns_rr_list_deep_free(list);
-               }
-               if(tp->dnskey_rrset) {
-                       list = packed_rrset_to_rr_list(tp->dnskey_rrset, bf);
-                       ldns_rr_list_print(stderr, list);
-                       ldns_rr_list_deep_free(list);
-               }
-               ldns_buffer_free(bf);
+       if(tp->ds_rrset) {
+               log_packed_rrset(0, "DS:", tp->ds_rrset);
+       }
+       if(tp->dnskey_rrset) {
+               log_packed_rrset(0, "DNSKEY:", tp->dnskey_rrset);
        }
        log_info("file %s", tp->autr->file);
        ctime_r(&tp->autr->last_queried, buf);
index 193135cb66e68a6f85f72367a14d1d76f2257a61..c5dc3bab93cc7e31c8af3d6bc7344d990c90025b 100644 (file)
@@ -48,6 +48,7 @@ struct trust_anchor;
 struct ub_packed_rrset_key;
 struct module_env;
 struct val_env;
+struct ldns_buffer;
 
 /** Autotrust anchor states */
 typedef enum {
@@ -66,7 +67,9 @@ struct autr_ta {
        /** next key */
        struct autr_ta* next;
        /** the RR */
-       ldns_rr* rr;
+       uint8_t* rr;
+       /** length of rr */
+       size_t rr_len, dname_len;
        /** last update of key state (new pending count keeps date the same) */
        time_t last_change;
        /** 5011 state */
@@ -199,7 +202,7 @@ int autr_process_prime(struct module_env* env, struct val_env* ve,
 void autr_debug_print(struct val_anchors* anchors);
 
 /** callback for query answer to 5011 probe */
-void probe_answer_cb(void* arg, int rcode, ldns_buffer* buf, 
+void probe_answer_cb(void* arg, int rcode, struct ldns_buffer* buf, 
        enum sec_status sec, char* errinf);
 
 #endif /* VALIDATOR_AUTOTRUST_H */
index e710f2f24083a8f88ed002f64a1c07dbb635a63f..b3a72b2c55145350507beab9f27919e7896d271d 100644 (file)
@@ -40,8 +40,6 @@
  */
 #include "config.h"
 #include <ctype.h>
-#include <ldns/dname.h>
-#include <ldns/host2wire.h>
 #include "validator/val_anchor.h"
 #include "validator/val_sigcrypt.h"
 #include "validator/autotrust.h"
@@ -50,6 +48,9 @@
 #include "util/log.h"
 #include "util/net_help.h"
 #include "util/config_file.h"
+#include "ldns/sbuffer.h"
+#include "ldns/rrdef.h"
+#include "ldns/str2wire.h"
 #ifdef HAVE_GLOB_H
 #include <glob.h>
 #endif
@@ -346,36 +347,26 @@ anchor_store_new_key(struct val_anchors* anchors, uint8_t* name, uint16_t type,
 /**
  * Add new RR. It converts ldns RR to wire format.
  * @param anchors: anchor storage.
- * @param buffer: parsing buffer.
- * @param rr: the rr (allocated by caller).
+ * @param rr: the wirerr.
+ * @param rl: length of rr.
+ * @param dl: length of dname.
  * @return NULL on error, else the trust anchor.
  */
 static struct trust_anchor*
-anchor_store_new_rr(struct val_anchors* anchors, ldns_buffer* buffer, 
-       ldns_rr* rr)
+anchor_store_new_rr(struct val_anchors* anchors, uint8_t* rr, size_t rl,
+       size_t dl)
 {
        struct trust_anchor* ta;
-       ldns_rdf* owner = ldns_rr_owner(rr);
-       ldns_status status;
-       ldns_buffer_clear(buffer);
-       ldns_buffer_skip(buffer, 2); /* skip rdatalen */
-       status = ldns_rr_rdata2buffer_wire(buffer, rr);
-       if(status != LDNS_STATUS_OK) {
-               log_err("error converting trustanchor to wireformat: %s", 
-                       ldns_get_errorstr_by_id(status));
-               return NULL;
-       }
-       ldns_buffer_flip(buffer);
-       ldns_buffer_write_u16_at(buffer, 0, ldns_buffer_limit(buffer) - 2);
-
-       if(!(ta=anchor_store_new_key(anchors, ldns_rdf_data(owner), 
-               ldns_rr_get_type(rr), ldns_rr_get_class(rr),
-               ldns_buffer_begin(buffer), ldns_buffer_limit(buffer)))) {
+       if(!(ta=anchor_store_new_key(anchors, rr,
+               ldns_wirerr_get_type(rr, rl, dl),
+               ldns_wirerr_get_class(rr, rl, dl),
+               ldns_wirerr_get_rdatawl(rr, rl, dl),
+               ldns_wirerr_get_rdatalen(rr, rl, dl)+2))) {
                return NULL;
        }
        log_nametypeclass(VERB_QUERY, "adding trusted key",
-               ldns_rdf_data(owner), 
-               ldns_rr_get_type(rr), ldns_rr_get_class(rr));
+               rr, ldns_wirerr_get_type(rr, rl, dl),
+               ldns_wirerr_get_class(rr, rl, dl));
        return ta;
 }
 
@@ -389,14 +380,15 @@ static struct trust_anchor*
 anchor_insert_insecure(struct val_anchors* anchors, const char* str)
 {
        struct trust_anchor* ta;
-       ldns_rdf* nm = ldns_dname_new_frm_str(str);
+       size_t dname_len = 0;
+       uint8_t* nm = ldns_str2wire_dname(str, &dname_len);
        if(!nm) {
                log_err("parse error in domain name '%s'", str);
                return NULL;
        }
-       ta = anchor_store_new_key(anchors, ldns_rdf_data(nm), LDNS_RR_TYPE_DS,
+       ta = anchor_store_new_key(anchors, nm, LDNS_RR_TYPE_DS,
                LDNS_RR_CLASS_IN, NULL, 0);
-       ldns_rdf_deep_free(nm);
+       free(nm);
        return ta;
 }
 
@@ -405,20 +397,20 @@ anchor_store_str(struct val_anchors* anchors, ldns_buffer* buffer,
        const char* str)
 {
        struct trust_anchor* ta;
-       ldns_rr* rr = NULL;
-       ldns_status status = ldns_rr_new_frm_str(&rr, str, 0, NULL, NULL);
-       if(status != LDNS_STATUS_OK) {
-               log_err("error parsing trust anchor: %s", 
-                       ldns_get_errorstr_by_id(status));
-               ldns_rr_free(rr);
+       uint8_t* rr = ldns_buffer_begin(buffer);
+       size_t len = ldns_buffer_capacity(buffer), dname_len = 0;
+       int status = ldns_str2wire_rr_buf(str, rr, &len, &dname_len,
+               0, NULL, 0, NULL, 0);
+       if(status != 0) {
+               log_err("error parsing trust anchor %s: at %d: %s", 
+                       str, LDNS_WIREPARSE_OFFSET(status),
+                       ldns_get_errorstr_parse(status));
                return NULL;
        }
-       if(!(ta=anchor_store_new_rr(anchors, buffer, rr))) {
+       if(!(ta=anchor_store_new_rr(anchors, rr, len, dname_len))) {
                log_err("out of memory");
-               ldns_rr_free(rr);
                return NULL;
        }
-       ldns_rr_free(rr);
        return ta;
 }
 
@@ -435,40 +427,39 @@ anchor_read_file(struct val_anchors* anchors, ldns_buffer* buffer,
        const char* fname, int onlyone)
 {
        struct trust_anchor* ta = NULL, *tanew;
-       uint32_t default_ttl = 3600;
-       ldns_rdf* origin = NULL, *prev = NULL;
-       int line_nr = 1;
-       ldns_status status;
-       ldns_rr* rr;
+       struct ldns_file_parse_state pst;
+       int status;
+       size_t len, dname_len;
+       uint8_t* rr = ldns_buffer_begin(buffer);
        int ok = 1;
        FILE* in = fopen(fname, "r");
        if(!in) {
                log_err("error opening file %s: %s", fname, strerror(errno));
                return 0;
        }
+       memset(&pst, 0, sizeof(pst));
+       pst.default_ttl = 3600;
+       pst.lineno = 1;
        while(!feof(in)) {
-               rr = NULL;
-               status = ldns_rr_new_frm_fp_l(&rr, in, &default_ttl, &origin,
-                       &prev, &line_nr);
-               if(status == LDNS_STATUS_SYNTAX_EMPTY /* empty line */
-                       || status == LDNS_STATUS_SYNTAX_TTL /* $TTL */
-                       || status == LDNS_STATUS_SYNTAX_ORIGIN /* $ORIGIN */)
+               len = ldns_buffer_capacity(buffer);
+               dname_len = 0;
+               status = ldns_fp2wire_rr_buf(in, rr, &len, &dname_len, &pst);
+               if(len == 0) /* empty, $TTL, $ORIGIN */
                        continue;
-               if(status != LDNS_STATUS_OK) {
-                       log_err("parse error in %s:%d : %s", fname, line_nr,
-                               ldns_get_errorstr_by_id(status));
-                       ldns_rr_free(rr);
+               if(status != 0) {
+                       log_err("parse error in %s:%d:%d : %s", fname,
+                               pst.lineno, LDNS_WIREPARSE_OFFSET(status),
+                               ldns_get_errorstr_parse(status));
                        ok = 0;
                        break;
                }
-               if(ldns_rr_get_type(rr) != LDNS_RR_TYPE_DS && 
-                       ldns_rr_get_type(rr) != LDNS_RR_TYPE_DNSKEY) {
-                       ldns_rr_free(rr);
+               if(ldns_wirerr_get_type(rr, len, dname_len) !=
+                       LDNS_RR_TYPE_DS && ldns_wirerr_get_type(rr, len,
+                       dname_len) != LDNS_RR_TYPE_DNSKEY) {
                        continue;
                }
-               if(!(tanew=anchor_store_new_rr(anchors, buffer, rr))) {
-                       log_err("error at %s line %d", fname, line_nr);
-                       ldns_rr_free(rr);
+               if(!(tanew=anchor_store_new_rr(anchors, rr, len, dname_len))) {
+                       log_err("mem error at %s line %d", fname, pst.lineno);
                        ok = 0;
                        break;
                }
@@ -476,16 +467,12 @@ anchor_read_file(struct val_anchors* anchors, ldns_buffer* buffer,
                        log_err("error at %s line %d: no multiple anchor "
                                "domains allowed (you can have multiple "
                                "keys, but they must have the same name).", 
-                               fname, line_nr);
-                       ldns_rr_free(rr);
+                               fname, pst.lineno);
                        ok = 0;
                        break;
                }
                ta = tanew;
-               ldns_rr_free(rr);
        }
-       ldns_rdf_deep_free(origin);
-       ldns_rdf_deep_free(prev);
        fclose(in);
        if(!ok) return NULL;
        /* empty file is OK when multiple anchors are allowed */
index 5a3ad409a83e30bc71a046afda8c761571af19de..59f75437567cd97fc6b46566a1c056e5a397f25b 100644 (file)
@@ -48,6 +48,7 @@ struct config_file;
 struct ub_packed_rrset_key;
 struct autr_point_data;
 struct autr_global_data;
+struct ldns_buffer;
 
 /**
  * Trust anchor store.
@@ -184,7 +185,7 @@ struct trust_anchor* anchor_find(struct val_anchors* anchors,
  * @return NULL on error.
  */
 struct trust_anchor* anchor_store_str(struct val_anchors* anchors, 
-       ldns_buffer* buffer, const char* str);
+       struct ldns_buffer* buffer, const char* str);
 
 /**
  * Get memory in use by the trust anchor storage
index e9144838feb8053196175ce8235e50708aa30441..6885e84834d546e3e1758c4de625d22fb5f71224 100644 (file)
  * This file contains functions for dealing with validator key entries.
  */
 #include "config.h"
-#include <ldns/ldns.h>
 #include "validator/val_kentry.h"
 #include "util/data/packed_rrset.h"
 #include "util/data/dname.h"
 #include "util/storage/lookup3.h"
 #include "util/regional.h"
 #include "util/net_help.h"
+#include "ldns/rrdef.h"
+#include "ldns/keyraw.h"
 
 size_t 
 key_entry_sizefunc(void* key, void* data)
index e8d9d56ad6faea5e0914ebb78c8405d8f3b71a05..31e1197cdac4c382e4c0f6d617b15208258af45b 100644 (file)
@@ -59,6 +59,8 @@
 #include "util/config_file.h"
 #include "services/cache/rrset.h"
 #include "services/cache/dns.h"
+#include "ldns/rrdef.h"
+#include "ldns/sbuffer.h"
 
 int val_neg_data_compare(const void* a, const void* b)
 {
index ec4f42f6ab7dadf4ac88bc0015c64ccb14141fbc..deed680fbcdd33fa1e01ef122ad338731bdf8cda 100644 (file)
@@ -46,6 +46,7 @@
 #define VALIDATOR_VAL_NEG_H
 #include "util/locks.h"
 #include "util/rbtree.h"
+struct ldns_buffer;
 struct val_neg_data;
 struct config_file;
 struct reply_info;
@@ -255,7 +256,7 @@ int val_neg_dlvlookup(struct val_neg_cache* neg, uint8_t* qname, size_t len,
  */
 struct dns_msg* val_neg_getmsg(struct val_neg_cache* neg, 
        struct query_info* qinfo, struct regional* region, 
-       struct rrset_cache* rrset_cache, ldns_buffer* buf, time_t now,
+       struct rrset_cache* rrset_cache, struct ldns_buffer* buf, time_t now,
        int addsoa, uint8_t* topname);
 
 
index e377ca4b9401d51082ef93b40a32107d6547c11d..1cec40ac34dd72372307acbda21cbd83c89b180f 100644 (file)
@@ -41,7 +41,6 @@
  * for denial of existance, and proofs for presence of types.
  */
 #include "config.h"
-#include <ldns/packet.h>
 #include "validator/val_nsec.h"
 #include "validator/val_utils.h"
 #include "util/data/msgreply.h"
index 20580c0d755fc450ccb6290554eef3819f392fb6..1167776d874d126ddddf5e83eb1a4873cf18f093 100644 (file)
@@ -62,6 +62,7 @@
 #include "util/data/msgreply.h"
 /* we include nsec.h for the bitmap_has_type function */
 #include "validator/val_nsec.h"
+#include "ldns/sbuffer.h"
 
 /** 
  * This function we get from ldns-compat or from base system 
index ae4326daffb62607777b29548b33f858e698b39c..48cec2bf72a9864b5216fc4ca17276b9ba229000 100644 (file)
@@ -75,6 +75,7 @@ struct ub_packed_rrset_key;
 struct reply_info;
 struct query_info;
 struct key_entry_key;
+struct ldns_buffer;
 
 /**
  *     0 1 2 3 4 5 6 7
@@ -270,9 +271,9 @@ int nsec3_hash_cmp(const void* c1, const void* c2);
  *     0 on a malloc failure.
  *     -1 if the NSEC3 rr was badly formatted (i.e. formerr).
  */
-int nsec3_hash_name(rbtree_t* table, struct regional* region, ldns_buffer* buf,
-       struct ub_packed_rrset_key* nsec3, int rr, uint8_t* dname, 
-       size_t dname_len, struct nsec3_cached_hash** hash);
+int nsec3_hash_name(rbtree_t* table, struct regional* region,
+       struct ldns_buffer* buf, struct ub_packed_rrset_key* nsec3, int rr,
+       uint8_t* dname, size_t dname_len, struct nsec3_cached_hash** hash);
 
 /**
  * Get next owner name, converted to base32 encoding and with the
@@ -328,8 +329,9 @@ int nsec3_get_params(struct ub_packed_rrset_key* rrset, int r,
  * @param max: maximum space for result.
  * @return 0 on failure, otherwise bytelength stored.
  */
-size_t nsec3_get_hashed(ldns_buffer* buf, uint8_t* nm, size_t nmlen, int algo, 
-       size_t iter, uint8_t* salt, size_t saltlen, uint8_t* res, size_t max);
+size_t nsec3_get_hashed(struct ldns_buffer* buf, uint8_t* nm, size_t nmlen,
+       int algo, size_t iter, uint8_t* salt, size_t saltlen, uint8_t* res,
+       size_t max);
 
 /** 
  * see if NSEC3 RR contains given type
@@ -373,6 +375,6 @@ int nsec3_get_nextowner(struct ub_packed_rrset_key* rrset, int r,
  * @return true if covers, false if not.
  */
 int nsec3_covers(uint8_t* zone, struct nsec3_cached_hash* hash,
-       struct ub_packed_rrset_key* rrset, int rr, ldns_buffer* buf);
+       struct ub_packed_rrset_key* rrset, int rr, struct ldns_buffer* buf);
 
 #endif /* VALIDATOR_VAL_NSEC3_H */
index 92fd0cc4c8c20db96ccc411625cb78c2a97e3d36..c61a22234fd73f313f38fec0847a2922557c7721 100644 (file)
  * and do the library calls (for the crypto library in use).
  */
 #include "config.h"
-#include <ldns/ldns.h>
 #include "validator/val_secalgo.h"
 #include "util/data/packed_rrset.h"
 #include "util/log.h"
+#include "ldns/rrdef.h"
+#include "ldns/keyraw.h"
+#include "ldns/sbuffer.h"
 
 #if !defined(HAVE_SSL) && !defined(HAVE_NSS)
 #error "Need crypto library to do digital signature cryptography"
index a5832af871e813435d6fb717a0d4df509a8a98a5..593b7af4fd24198f2f7762153ce625cd71b56a05 100644 (file)
@@ -42,6 +42,7 @@
 
 #ifndef VALIDATOR_VAL_SECALGO_H
 #define VALIDATOR_VAL_SECALGO_H
+struct ldns_buffer;
 
 /**
  * Return size of DS digest according to its hash algorithm.
@@ -76,7 +77,7 @@ int dnskey_algo_id_is_supported(int id);
  * @return secure if verification succeeded, bogus on crypto failure,
  *     unchecked on format errors and alloc failures.
  */
-enum sec_status verify_canonrrset(ldns_buffer* buf, int algo,
+enum sec_status verify_canonrrset(struct ldns_buffer* buf, int algo,
        unsigned char* sigblock, unsigned int sigblock_len,
        unsigned char* key, unsigned int keylen, char** reason);
 
index 37e1ce14e21aed7f283f28aa698a8fb261602368..4de738a470c93ad18555696a97eaacd497541a5d 100644 (file)
@@ -41,7 +41,6 @@
  * bridging between RR wireformat data and crypto calls.
  */
 #include "config.h"
-#include <ldns/ldns.h>
 #include "validator/val_sigcrypt.h"
 #include "validator/val_secalgo.h"
 #include "validator/validator.h"
 #include "util/module.h"
 #include "util/net_help.h"
 #include "util/regional.h"
+#include "ldns/keyraw.h"
+#include "ldns/sbuffer.h"
+#include "ldns/parseutil.h"
+#include "ldns/wire2str.h"
 
+#include <ctype.h>
 #if !defined(HAVE_SSL) && !defined(HAVE_NSS)
 #error "Need crypto library to do digital signature cryptography"
 #endif
@@ -1040,6 +1044,69 @@ canonicalize_rdata(ldns_buffer* buf, struct ub_packed_rrset_key* rrset,
        }
 }
 
+int rrset_canonical_equal(struct regional* region,
+       struct ub_packed_rrset_key* k1, struct ub_packed_rrset_key* k2)
+{
+       struct rbtree_t sortree1, sortree2;
+       struct canon_rr *rrs1, *rrs2, *p1, *p2;
+       struct packed_rrset_data* d1=(struct packed_rrset_data*)k1->entry.data;
+       struct packed_rrset_data* d2=(struct packed_rrset_data*)k2->entry.data;
+       struct ub_packed_rrset_key fk;
+       struct packed_rrset_data fd;
+       size_t flen[2];
+       uint8_t* fdata[2];
+
+       /* basic compare */
+       if(k1->rk.dname_len != k2->rk.dname_len ||
+               k1->rk.flags != k2->rk.flags ||
+               k1->rk.type != k2->rk.type ||
+               k1->rk.rrset_class != k2->rk.rrset_class ||
+               query_dname_compare(k1->rk.dname, k2->rk.dname) != 0)
+               return 0;
+       if(d1->ttl != d2->ttl ||
+               d1->count != d2->count ||
+               d1->rrsig_count != d2->rrsig_count ||
+               d1->trust != d2->trust ||
+               d1->security != d2->security)
+               return 0;
+
+       /* init */
+       memset(&fk, 0, sizeof(fk));
+       memset(&fd, 0, sizeof(fd));
+       fk.entry.data = &fd;
+       fd.count = 2;
+       fd.rr_len = flen;
+       fd.rr_data = fdata;
+       rbtree_init(&sortree1, &canonical_tree_compare);
+       rbtree_init(&sortree2, &canonical_tree_compare);
+       rrs1 = regional_alloc(region, sizeof(struct canon_rr)*d1->count);
+       rrs2 = regional_alloc(region, sizeof(struct canon_rr)*d2->count);
+       if(!rrs1 || !rrs2) return 1; /* alloc failure */
+
+       /* sort */
+       canonical_sort(k1, d1, &sortree1, rrs1);
+       canonical_sort(k2, d2, &sortree2, rrs2);
+
+       /* compare canonical-sorted RRs for canonical-equality */
+       if(sortree1.count != sortree2.count)
+               return 0;
+       p1 = (struct canon_rr*)rbtree_first(&sortree1);
+       p2 = (struct canon_rr*)rbtree_first(&sortree2);
+       while(p1 != (struct canon_rr*)RBTREE_NULL &&
+               p2 != (struct canon_rr*)RBTREE_NULL) {
+               flen[0] = d1->rr_len[p1->rr_idx];
+               flen[1] = d2->rr_len[p2->rr_idx];
+               fdata[0] = d1->rr_data[p1->rr_idx];
+               fdata[1] = d2->rr_data[p2->rr_idx];
+
+               if(canonical_compare(&fk, 0, 1) != 0)
+                       return 0;
+               p1 = (struct canon_rr*)rbtree_next(&p1->node);
+               p2 = (struct canon_rr*)rbtree_next(&p2->node);
+       }
+       return 1;
+}
+
 /**
  * Create canonical form of rrset in the scratch buffer.
  * @param region: temporary region.
index 9859d3c39087b34242802dfba341da2eaabf6882..c697061383d24a75e34d72676fbd6a2027bd8a92 100644 (file)
@@ -49,6 +49,7 @@ struct module_env;
 struct ub_packed_rrset_key;
 struct rbtree_t;
 struct regional;
+struct ldns_buffer;
 
 /** number of entries in algorithm needs array */
 #define ALGO_NEEDS_MAX 256
@@ -298,7 +299,7 @@ enum sec_status dnskeyset_verify_rrset_sig(struct module_env* env,
  *     bogus if it did not validate.
  */
 enum sec_status dnskey_verify_rrset_sig(struct regional* region, 
-       ldns_buffer* buf, struct val_env* ve, time_t now,
+       struct ldns_buffer* buf, struct val_env* ve, time_t now,
        struct ub_packed_rrset_key* rrset, struct ub_packed_rrset_key* dnskey, 
        size_t dnskey_idx, size_t sig_idx,
        struct rbtree_t** sortree, int* buf_canon, char** reason);
@@ -308,4 +309,15 @@ enum sec_status dnskey_verify_rrset_sig(struct regional* region,
  */
 int canonical_tree_compare(const void* k1, const void* k2);
 
+/**
+ * Compare two rrsets and see if they are the same, canonicalised.
+ * The rrsets are not altered.
+ * @param region: temporary region.
+ * @param k1: rrset1
+ * @param k2: rrset2
+ * @return true if equal.
+ */
+int rrset_canonical_equal(struct regional* region,
+       struct ub_packed_rrset_key* k1, struct ub_packed_rrset_key* k2);
+
 #endif /* VALIDATOR_VAL_SIGCRYPT_H */
index ad472cc6a95346d2b14df9a7015368c2a68afe26..2184df2f7e95f9add18bbe83db324eff591c3e84 100644 (file)
@@ -40,7 +40,6 @@
  * According to RFC 4034.
  */
 #include "config.h"
-#include <ldns/ldns.h>
 #include "validator/validator.h"
 #include "validator/val_anchor.h"
 #include "validator/val_kcache.h"
@@ -59,6 +58,8 @@
 #include "util/regional.h"
 #include "util/config_file.h"
 #include "util/fptr_wlist.h"
+#include "ldns/rrdef.h"
+#include "ldns/wire2str.h"
 
 /* forward decl for cache response and normal super inform calls of a DS */
 static void process_ds_response(struct module_qstate* qstate, 
@@ -294,9 +295,12 @@ needs_validation(struct module_qstate* qstate, int ret_rc,
        else    rcode = (int)FLAGS_GET_RCODE(ret_msg->rep->flags);
 
        if(rcode != LDNS_RCODE_NOERROR && rcode != LDNS_RCODE_NXDOMAIN) {
-               verbose(VERB_ALGO, "cannot validate non-answer, rcode %s",
-                       ldns_lookup_by_id(ldns_rcodes, rcode)?
-                       ldns_lookup_by_id(ldns_rcodes, rcode)->name:"??");
+               if(verbosity >= VERB_ALGO) {
+                       char rc[16];
+                       rc[0]=0;
+                       (void)ldns_wire2str_rcode_buf(rcode, rc, sizeof(rc));
+                       verbose(VERB_ALGO, "cannot validate non-answer, rcode %s", rc);
+               }
                return 0;
        }
 
@@ -2344,12 +2348,13 @@ ds_response_to_ke(struct module_qstate* qstate, struct val_qstate* vq,
        char* reason = NULL;
        enum val_classification subtype;
        if(rcode != LDNS_RCODE_NOERROR) {
-               char* rc = ldns_pkt_rcode2str(rcode);
+               char rc[16];
+               rc[0]=0;
+               (void)ldns_wire2str_rcode_buf(rcode, rc, sizeof(rc));
                /* errors here pretty much break validation */
                verbose(VERB_DETAIL, "DS response was error, thus bogus");
                errinf(qstate, rc);
                errinf(qstate, "no DS");
-               free(rc);
                goto return_bogus;
        }
 
@@ -2521,10 +2526,11 @@ ds_response_to_ke(struct module_qstate* qstate, struct val_qstate* vq,
                        "DS response, thus bogus.");
                errinf(qstate, "no DS and");
                if(FLAGS_GET_RCODE(msg->rep->flags) != LDNS_RCODE_NOERROR) {
-                       char* rc = ldns_pkt_rcode2str(
-                               FLAGS_GET_RCODE(msg->rep->flags));
+                       char rc[16];
+                       rc[0]=0;
+                       (void)ldns_wire2str_rcode_buf((int)FLAGS_GET_RCODE(
+                               msg->rep->flags), rc, sizeof(rc));
                        errinf(qstate, rc);
-                       free(rc);
                } else  errinf(qstate, val_classification_to_string(subtype));
                errinf(qstate, "message fails to prove that");
                goto return_bogus;