From 29e96e86c9f3bd863fd4607c55030205c02af66c Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Thu, 31 Oct 2013 15:09:26 +0000 Subject: [PATCH] - separate ldns into core ldns inside ldns/ subdirectory. No more --with-ldns is needed and unbound does not rely on libldns. git-svn-id: file:///svn/unbound/trunk@2998 be551aaa-1e26-0410-a405-d3ace91eadb9 --- Makefile.in | 966 ++++----- compat/strlcat.c | 73 + config.h.in | 33 +- configure | 436 ++-- configure.ac | 110 +- daemon/cachedump.c | 193 +- daemon/daemon.c | 2 +- daemon/remote.c | 61 +- daemon/stats.c | 2 +- daemon/stats.h | 4 +- daemon/unbound.c | 4 +- daemon/worker.c | 2 +- doc/Changelog | 2 + iterator/iter_delegpt.c | 2 + iterator/iter_fwd.c | 44 +- iterator/iter_hints.c | 127 +- iterator/iter_priv.c | 19 +- iterator/iter_priv.h | 4 +- iterator/iter_resptype.c | 3 +- iterator/iter_scrub.c | 1 + iterator/iter_scrub.h | 4 +- iterator/iter_utils.c | 27 +- iterator/iter_utils.h | 8 +- iterator/iterator.c | 7 +- ldns/keyraw.c | 368 ++++ ldns/keyraw.h | 112 + ldns/parse.c | 451 ++++ ldns/parse.h | 184 ++ ldns/parseutil.c | 726 +++++++ ldns/parseutil.h | 148 ++ ldns/pkthdr.h | 158 ++ ldns/rrdef.c | 778 +++++++ ldns/rrdef.h | 500 +++++ ldns/sbuffer.c | 189 ++ ldns/sbuffer.h | 706 +++++++ ldns/str2wire.c | 1840 +++++++++++++++++ ldns/str2wire.h | 532 +++++ ldns/wire2str.c | 1925 ++++++++++++++++++ ldns/wire2str.h | 973 +++++++++ libunbound/context.c | 1 + libunbound/context.h | 3 +- libunbound/libunbound.c | 11 +- libunbound/libworker.c | 19 +- libunbound/libworker.h | 9 +- services/cache/dns.c | 1 + services/cache/infra.c | 2 +- services/cache/rrset.c | 1 + services/listen_dnsport.c | 7 +- services/listen_dnsport.h | 3 +- services/localzone.c | 221 +- services/localzone.h | 7 +- services/mesh.c | 2 +- services/mesh.h | 13 +- services/outside_network.c | 2 +- services/outside_network.h | 9 +- smallapp/unbound-anchor.c | 13 +- smallapp/unbound-checkconf.c | 5 +- smallapp/unbound-host.c | 70 +- smallapp/worker_cb.c | 6 +- testcode/asynclook.c | 1 + testcode/delayer.c | 5 +- testcode/fake_event.c | 143 +- testcode/harvest.c | 857 -------- testcode/ldns-testpkts.c | 898 -------- testcode/perf.c | 21 +- testcode/pktview.c | 3 +- testcode/readhex.c | 2 + testcode/readhex.h | 4 +- testcode/replay.c | 70 +- testcode/replay.h | 17 +- testcode/signit.c | 54 +- testcode/streamtcp.c | 39 +- testcode/testbound.c | 4 +- testcode/testpkts.c | 1427 +++++++++++++ testcode/{ldns-testpkts.h => testpkts.h} | 79 +- testcode/unitanchor.c | 3 +- testcode/unitdname.c | 17 +- testcode/unitmain.c | 3 +- testcode/unitmsgparse.c | 213 +- testcode/unitneg.c | 1 + testcode/unitverify.c | 46 +- testdata/autotrust_init.rpl | 2 +- testdata/autotrust_init_ds.rpl | 2 +- testdata/autotrust_init_fail.rpl | 2 +- testdata/autotrust_init_failsig.rpl | 2 +- testdata/autotrust_init_sigs.rpl | 2 +- testdata/autotrust_init_zsk.rpl | 2 +- testdata/autotrust_probefail.rpl | 2 +- testdata/autotrust_probefailsig.rpl | 2 +- testdata/autotrust_revtp.rpl | 2 +- testdata/autotrust_revtp_read.rpl | 2 +- testdata/autotrust_revtp_use.rpl | 2 +- testdata/autotrust_valid_use.rpl | 2 +- testdata/black_data.rpl | 4 +- testdata/black_dnskey.rpl | 4 +- testdata/black_ds.rpl | 4 +- testdata/black_ds_entry.rpl | 6 +- testdata/black_ent.rpl | 4 +- testdata/black_key_entry.rpl | 6 +- testdata/black_prime.rpl | 4 +- testdata/black_prime_entry.rpl | 4 +- testdata/dlv_anchor.rpl | 2 +- testdata/dlv_ask_higher.rpl | 2 +- testdata/dlv_below_ta.rpl | 2 +- testdata/dlv_delegation.rpl | 2 +- testdata/dlv_ds_lookup.rpl | 2 +- testdata/dlv_insecure.rpl | 2 +- testdata/dlv_insecure_negcache.rpl | 6 +- testdata/dlv_keyretry.rpl | 2 +- testdata/dlv_negnx.rpl | 4 +- testdata/dlv_optout.rpl | 2 +- testdata/dlv_unused.rpl | 2 +- testdata/domain_insec_dlv.rpl | 2 +- testdata/domain_insec_ds.rpl | 2 +- testdata/fwddlv_parse.rpl | 2 +- testdata/iter_class_any.rpl | 2 +- testdata/iter_emptydp.rpl | 2 +- testdata/iter_emptydp_for_glue.rpl | 2 +- testdata/iter_primenoglue.rpl | 2 +- testdata/local_nodefault.rpl | 2 +- testdata/local_transparent_sametype.rpl | 4 +- testdata/local_typetransparent.rpl | 6 +- testdata/net_signed_servfail.rpl | 136 +- testdata/nomem_cnametopos.rpl | 2 +- testdata/test_sigs.rsasha256_draft | 2 +- testdata/val_anchor_nx.rpl | 2 +- testdata/val_anchor_nx_nosig.rpl | 2 +- testdata/val_ans_dsent.rpl | 2 +- testdata/val_ans_nx.rpl | 2 +- testdata/val_any.rpl | 2 +- testdata/val_any_cname.rpl | 2 +- testdata/val_any_dname.rpl | 2 +- testdata/val_cname_loop1.rpl | 2 +- testdata/val_cname_loop2.rpl | 2 +- testdata/val_cnameinsectopos.rpl | 6 +- testdata/val_cnamenx_dblnsec.rpl | 2 +- testdata/val_cnamenx_rcodenx.rpl | 2 +- testdata/val_cnameqtype.rpl | 2 +- testdata/val_cnametocloser.rpl | 2 +- testdata/val_cnametocloser_nosig.rpl | 2 +- testdata/val_cnametocnamewctoposwc.rpl | 2 +- testdata/val_cnametodname.rpl | 2 +- testdata/val_cnametodnametocnametopos.rpl | 2 +- testdata/val_cnametoinsecure.rpl | 4 +- testdata/val_cnametonodata.rpl | 2 +- testdata/val_cnametonodata_nonsec.rpl | 2 +- testdata/val_cnametonsec.rpl | 2 +- testdata/val_cnametonx.rpl | 2 +- testdata/val_cnametooptin.rpl | 2 +- testdata/val_cnametooptout.rpl | 2 +- testdata/val_cnametopos.rpl | 2 +- testdata/val_cnametoposnowc.rpl | 2 +- testdata/val_cnametoposwc.rpl | 2 +- testdata/val_cnamewctonodata.rpl | 2 +- testdata/val_cnamewctonx.rpl | 2 +- testdata/val_cnamewctoposwc.rpl | 2 +- testdata/val_dnametoolong.rpl | 2 +- testdata/val_dnametopos.rpl | 2 +- testdata/val_dnametoposwc.rpl | 2 +- testdata/val_dnamewc.rpl | 2 +- testdata/val_ds_afterprime.rpl | 4 +- testdata/val_ds_cname.rpl | 2 +- testdata/val_ds_cnamesub.rpl | 2 +- testdata/val_ds_gost.crpl | 2 +- testdata/val_ds_gost_downgrade.crpl | 2 +- testdata/val_ds_sha2.crpl | 2 +- testdata/val_ds_sha2_downgrade.crpl | 2 +- testdata/val_dsnsec.rpl | 4 +- testdata/val_entds.rpl | 2 +- testdata/val_faildnskey.rpl | 2 +- testdata/val_faildnskey_ok.rpl | 2 +- testdata/val_fwdds.rpl | 230 +-- testdata/val_keyprefetch.rpl | 2 +- testdata/val_keyprefetch_verify.rpl | 4 +- testdata/val_mal_wc.rpl | 2 +- testdata/val_negcache_ds.rpl | 4 +- testdata/val_negcache_dssoa.rpl | 6 +- testdata/val_nodata.rpl | 2 +- testdata/val_nodata_ent.rpl | 2 +- testdata/val_nodata_entwc.rpl | 2 +- testdata/val_nodata_failsig.rpl | 2 +- testdata/val_nodatawc.rpl | 2 +- testdata/val_nodatawc_one.rpl | 2 +- testdata/val_nokeyprime.rpl | 2 +- testdata/val_nsec3_b1_nameerror.rpl | 2 +- testdata/val_nsec3_b1_nameerror_nowc.rpl | 2 +- testdata/val_nsec3_b21_nodataent.rpl | 2 +- testdata/val_nsec3_b2_nodata.rpl | 2 +- testdata/val_nsec3_b2_nodata_nons.rpl | 2 +- testdata/val_nsec3_b3_optout.rpl | 2 +- testdata/val_nsec3_b3_optout_negcache.rpl | 2 +- testdata/val_nsec3_b4_wild.rpl | 2 +- testdata/val_nsec3_b5_wcnodata.rpl | 2 +- testdata/val_nsec3_cname_ds.rpl | 2 +- testdata/val_nsec3_cname_par.rpl | 2 +- testdata/val_nsec3_cname_sub.rpl | 2 +- testdata/val_nsec3_cnametocnamewctoposwc.rpl | 2 +- testdata/val_nsec3_iter_high.rpl | 2 +- testdata/val_nsec3_nods.rpl | 2 +- testdata/val_nsec3_nods_badsig.rpl | 2 +- testdata/val_nsec3_nods_negcache.rpl | 2 +- testdata/val_nsec3_optout_ad.rpl | 10 +- testdata/val_nsec3_optout_cache.rpl | 4 +- testdata/val_nsec3_wcany.rpl | 2 +- testdata/val_nx.rpl | 2 +- testdata/val_nx_nsec3_collision.rpl | 2 +- testdata/val_nx_nsec3_params.rpl | 2 +- testdata/val_nx_overreach.rpl | 2 +- testdata/val_pos_truncns.rpl | 2 +- testdata/val_positive.rpl | 2 +- testdata/val_positive_wc.rpl | 2 +- testdata/val_qds_badanc.rpl | 2 +- testdata/val_qds_oneanc.rpl | 2 +- testdata/val_qds_twoanc.rpl | 2 +- testdata/val_refer_unsignadd.rpl | 4 +- testdata/val_referd.rpl | 2 +- testdata/val_referglue.rpl | 2 +- testdata/val_rrsig.rpl | 2 +- testdata/val_secds.rpl | 2 +- testdata/val_secds_nosig.rpl | 2 +- testdata/val_stub_noroot.rpl | 2 +- testdata/val_stubds.rpl | 230 +-- testdata/val_ta_algo_dnskey.rpl | 2 +- testdata/val_ta_algo_missing.rpl | 2 +- testdata/val_twocname.rpl | 2 +- testdata/val_unalgo_anchor.rpl | 2 +- testdata/val_unalgo_dlv.rpl | 2 +- testdata/val_unalgo_ds.rpl | 2 +- testdata/val_unsec_cname.rpl | 4 +- testdata/val_unsecds.rpl | 2 +- testdata/val_unsecds_negcache.rpl | 2 +- testdata/val_unsecds_qtypeds.rpl | 2 +- testdata/val_wild_pos.rpl | 2 +- util/config_file.c | 60 +- util/configparser.c | 555 +++-- util/configparser.h | 36 +- util/data/dname.c | 3 +- util/data/dname.h | 17 +- util/data/msgencode.c | 2 +- util/data/msgencode.h | 11 +- util/data/msgparse.c | 7 +- util/data/msgparse.h | 12 +- util/data/msgreply.c | 26 +- util/data/msgreply.h | 9 +- util/data/packed_rrset.c | 197 +- util/data/packed_rrset.h | 48 +- util/log.c | 2 + util/log.h | 4 +- util/module.h | 3 +- util/net_help.c | 11 +- util/netevent.c | 11 +- util/netevent.h | 10 +- util/random.c | 1 + validator/autotrust.c | 769 ++++--- validator/autotrust.h | 7 +- validator/val_anchor.c | 111 +- validator/val_anchor.h | 3 +- validator/val_kentry.c | 3 +- validator/val_neg.c | 2 + validator/val_neg.h | 3 +- validator/val_nsec.c | 1 - validator/val_nsec3.c | 1 + validator/val_nsec3.h | 14 +- validator/val_secalgo.c | 4 +- validator/val_secalgo.h | 3 +- validator/val_sigcrypt.c | 69 +- validator/val_sigcrypt.h | 14 +- validator/validator.c | 24 +- 268 files changed, 13947 insertions(+), 5100 deletions(-) create mode 100644 compat/strlcat.c create mode 100644 ldns/keyraw.c create mode 100644 ldns/keyraw.h create mode 100644 ldns/parse.c create mode 100644 ldns/parse.h create mode 100644 ldns/parseutil.c create mode 100644 ldns/parseutil.h create mode 100644 ldns/pkthdr.h create mode 100644 ldns/rrdef.c create mode 100644 ldns/rrdef.h create mode 100644 ldns/sbuffer.c create mode 100644 ldns/sbuffer.h create mode 100644 ldns/str2wire.c create mode 100644 ldns/str2wire.h create mode 100644 ldns/wire2str.c create mode 100644 ldns/wire2str.h delete mode 100644 testcode/harvest.c delete mode 100644 testcode/ldns-testpkts.c create mode 100644 testcode/testpkts.c rename testcode/{ldns-testpkts.h => testpkts.h} (82%) diff --git a/Makefile.in b/Makefile.in index c2d485f28..9f4b78738 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 index 000000000..0bea9250b --- /dev/null +++ b/compat/strlcat.c @@ -0,0 +1,73 @@ +/* compat/strlcat.c */ + +/*- + * Copyright (c) 1998 Todd C. Miller + * 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 +#include + +/* + * 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 */ diff --git a/config.h.in b/config.h.in index 46f38edf3..9ae30fe68 100644 --- a/config.h.in +++ b/config.h.in @@ -70,6 +70,12 @@ /* Define to 1 if you have the 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 @@ -166,15 +172,6 @@ /* 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 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 @@ -310,6 +307,9 @@ /* Define to 1 if you have the 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 @@ -475,6 +475,9 @@ /* 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 @@ -687,6 +690,12 @@ # define NDEBUG #endif +/** Use small-ldns codebase */ +#define USE_SLDNS 1 +#ifdef HAVE_SSL +# define LDNS_BUILD_CONFIG_HAVE_SSL 1 +#endif + #include #include #include @@ -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); diff --git a/configure b/configure index daf78e944..1f0868bc9 100755 --- 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 +#include +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 = 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 +# include +#else +# ifdef HAVE_SYS_TIME_H +# include +# else +# include +# 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 @@ -18008,193 +18249,6 @@ fi -# 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 -#endif -#ifdef HAVE_WS2TCPIP_H -# include -#endif -#include - -" -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 -#endif - -#ifdef HAVE_NETINET_IN_H -#include -#endif - -#ifdef HAVE_ARPA_INET_H -#include -#endif - -#ifdef HAVE_WINSOCK2_H -#include -#endif - -#ifdef HAVE_WS2TCPIP_H -#include -#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;} diff --git a/configure.ac b/configure.ac index b0ee08c9c..bbbe77d22 100644 --- a/configure.ac +++ b/configure.ac @@ -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 +# include +#else +# ifdef HAVE_SYS_TIME_H +# include +# else +# include +# 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 -#endif -#ifdef HAVE_WS2TCPIP_H -# include -#endif -#include - ]) -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 -#endif - -#ifdef HAVE_NETINET_IN_H -#include -#endif - -#ifdef HAVE_ARPA_INET_H -#include -#endif - -#ifdef HAVE_WINSOCK2_H -#include -#endif - -#ifdef HAVE_WS2TCPIP_H -#include -#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 #include #include @@ -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 diff --git a/daemon/cachedump.c b/daemon/cachedump.c index df6a40188..622371a19 100644 --- a/daemon/cachedump.c +++ b/daemon/cachedump.c @@ -40,7 +40,7 @@ * to text format. */ #include "config.h" -#include +#include #include "daemon/cachedump.h" #include "daemon/remote.h" #include "daemon/worker.h" @@ -56,64 +56,19 @@ #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; icount; i++) { - if(!dump_rrset_line(ssl, k, d, now, i, ntohs(k->rk.type))) + for(i=0; icount + d->rrsig_count; i++) { + if(!dump_rrset_line(ssl, k, now, i)) return 0; } - for(i=0; irrsig_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; } diff --git a/daemon/daemon.c b/daemon/daemon.c index b91683feb..658e65dec 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -61,7 +61,6 @@ #include "nss.h" #endif -#include #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 /** How many quit requests happened. */ diff --git a/daemon/remote.c b/daemon/remote.c index 615050225..3b76c0e29 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -47,7 +47,6 @@ #include #endif #include -#include #include "daemon/remote.h" #include "daemon/worker.h" #include "daemon/daemon.h" @@ -75,6 +74,10 @@ #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 @@ -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; icount + 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); diff --git a/daemon/stats.c b/daemon/stats.c index 9a1a7d261..707273fe4 100644 --- a/daemon/stats.c +++ b/daemon/stats.c @@ -40,7 +40,6 @@ * numbers. These 'statistics' may be of interest to the operator. */ #include "config.h" -#include #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 diff --git a/daemon/stats.h b/daemon/stats.h index c0fc1cc15..b8513afdb 100644 --- a/daemon/stats.h +++ b/daemon/stats.h @@ -43,12 +43,12 @@ #ifndef DAEMON_STATS_H #define DAEMON_STATS_H #include "util/timehist.h" -#include 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 */ diff --git a/daemon/unbound.c b/daemon/unbound.c index 28ea17355..8de3f6b98 100644 --- a/daemon/unbound.c +++ b/daemon/unbound.c @@ -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) diff --git a/daemon/worker.c b/daemon/worker.c index c7620962c..a6d3c7063 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -40,7 +40,6 @@ * pending requests. */ #include "config.h" -#include #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 diff --git a/doc/Changelog b/doc/Changelog index 9e071d1b4..72a0af6d6 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -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 diff --git a/iterator/iter_delegpt.c b/iterator/iter_delegpt.c index c204ddfec..7a5aea493 100644 --- a/iterator/iter_delegpt.c +++ b/iterator/iter_delegpt.c @@ -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) diff --git a/iterator/iter_fwd.c b/iterator/iter_fwd.c index b84e5eff6..75e7a9f12 100644 --- a/iterator/iter_fwd.c +++ b/iterator/iter_fwd.c @@ -40,15 +40,14 @@ * Keep track of forward zones and config settings. */ #include "config.h" -#include -#include -#include #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; } diff --git a/iterator/iter_hints.c b/iterator/iter_hints.c index cde3a7e1b..960c98e05 100644 --- a/iterator/iter_hints.c +++ b/iterator/iter_hints.c @@ -40,14 +40,15 @@ * Keep track of stub and root hints, and read those from config. */ #include "config.h" -#include -#include #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; diff --git a/iterator/iter_priv.c b/iterator/iter_priv.c index 572f701f3..37cd35d89 100644 --- a/iterator/iter_priv.c +++ b/iterator/iter_priv.c @@ -41,7 +41,6 @@ */ #include "config.h" -#include #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); diff --git a/iterator/iter_priv.h b/iterator/iter_priv.h index e6e51c159..19b3cbc3f 100644 --- a/iterator/iter_priv.h +++ b/iterator/iter_priv.h @@ -43,7 +43,7 @@ #ifndef ITERATOR_ITER_PRIV_H #define ITERATOR_ITER_PRIV_H #include "util/rbtree.h" -#include +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); /** diff --git a/iterator/iter_resptype.c b/iterator/iter_resptype.c index 2cdc5fcfc..377cdf454 100644 --- a/iterator/iter_resptype.c +++ b/iterator/iter_resptype.c @@ -40,12 +40,13 @@ * one of the response types. */ #include "config.h" -#include #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, diff --git a/iterator/iter_scrub.c b/iterator/iter_scrub.c index a2407c27c..0b1a02ae0 100644 --- a/iterator/iter_scrub.c +++ b/iterator/iter_scrub.c @@ -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 diff --git a/iterator/iter_scrub.h b/iterator/iter_scrub.h index 6b7274e4a..7ef14ded3 100644 --- a/iterator/iter_scrub.h +++ b/iterator/iter_scrub.h @@ -42,7 +42,7 @@ #ifndef ITERATOR_ITER_SCRUB_H #define ITERATOR_ITER_SCRUB_H -#include +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); diff --git a/iterator/iter_utils.c b/iterator/iter_utils.c index 28f7dc241..6bea745ae 100644 --- a/iterator/iter_utils.c +++ b/iterator/iter_utils.c @@ -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; irrset_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; diff --git a/iterator/iter_utils.h b/iterator/iter_utils.h index 2070622d4..d660772db 100644 --- a/iterator/iter_utils.h +++ b/iterator/iter_utils.h @@ -43,7 +43,7 @@ #ifndef ITERATOR_ITER_UTILS_H #define ITERATOR_ITER_UTILS_H #include "iterator/iter_resptype.h" -#include +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 diff --git a/iterator/iterator.c b/iterator/iterator.c index 3c9804926..c4254c17a 100644 --- a/iterator/iterator.c +++ b/iterator/iterator.c @@ -41,7 +41,6 @@ */ #include "config.h" -#include #include "iterator/iterator.h" #include "iterator/iter_utils.h" #include "iterator/iter_hints.h" @@ -62,6 +61,10 @@ #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 index 000000000..a20783590 --- /dev/null +++ b/ldns/keyraw.c @@ -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 +#include +#include +#include +#include +#ifdef HAVE_OPENSSL_ENGINE_H +# include +#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 index 000000000..9314891cb --- /dev/null +++ b/ldns/keyraw.h @@ -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 +# include +#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 index 000000000..e5edc1b44 --- /dev/null +++ b/ldns/parse.c @@ -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 +#include + +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 index 000000000..1ddd013d2 --- /dev/null +++ b/ldns/parse.h @@ -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 index 000000000..61fa6385b --- /dev/null +++ b/ldns/parseutil.c @@ -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 +#include +#include + +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 index 000000000..9808ef3cc --- /dev/null +++ b/ldns/parseutil.h @@ -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 index 000000000..30177cdc0 --- /dev/null +++ b/ldns/pkthdr.h @@ -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 index 000000000..0d4d14038 --- /dev/null +++ b/ldns/rrdef.c @@ -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 index 000000000..45ffa32df --- /dev/null +++ b/ldns/rrdef.h @@ -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 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 index 000000000..0561752d8 --- /dev/null +++ b/ldns/sbuffer.c @@ -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 + +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 index 000000000..dd66dfe55 --- /dev/null +++ b/ldns/sbuffer.h @@ -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 index 000000000..b3f75bd3e --- /dev/null +++ b/ldns/str2wire.c @@ -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 +#ifdef HAVE_TIME_H +#include +#endif +#ifdef HAVE_NETDB_H +#include +#endif + +/** return an error */ +#define RET_ERR(e, off) ((int)((e)|((off)< 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] */ + if((status=rrinternal_get_ttl(&strbuf, token, sizeof(token), + ¬_there, &ttl, default_ttl)) != 0) + return status; + if((status=rrinternal_get_class(&strbuf, token, sizeof(token), + ¬_there, &cl)) != 0) + return status; + if((status=rrinternal_get_type(&strbuf, token, sizeof(token), + ¬_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; iid); + } 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 "[.][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 index 000000000..8746bfc65 --- /dev/null +++ b/ldns/str2wire.h @@ -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 + +#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 index 000000000..8bd74f110 --- /dev/null +++ b/ldns/wire2str.c @@ -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 +#include +#ifdef HAVE_NETDB_H +#include +#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>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 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 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>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. ? */ + if(exponent < 2) { + if(exponent == 1) + mantissa *= 10; + return ldns_str_print(str, sl, "0.%02ld", (long)mantissa); + } + /* always */ + w += ldns_str_print(str, sl, "%d", (int)mantissa); + for(i=0; i 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; iname) + 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; iname) + 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 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 index 000000000..a29ace7a3 --- /dev/null +++ b/ldns/wire2str.h @@ -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 */ diff --git a/libunbound/context.c b/libunbound/context.c index 18f34e454..44862648b 100644 --- a/libunbound/context.c +++ b/libunbound/context.c @@ -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) diff --git a/libunbound/context.h b/libunbound/context.h index 4447b02eb..a08353982 100644 --- a/libunbound/context.h +++ b/libunbound/context.h @@ -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 diff --git a/libunbound/libunbound.c b/libunbound/libunbound.c index 870e37699..3ec9196fe 100644 --- a/libunbound/libunbound.c +++ b/libunbound/libunbound.c @@ -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 #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; } diff --git a/libunbound/libworker.c b/libunbound/libworker.c index 313b41680..0863887e9 100644 --- a/libunbound/libworker.c +++ b/libunbound/libworker.c @@ -42,8 +42,6 @@ * returns from the procedure when done. */ #include "config.h" -#include -#include #ifdef HAVE_SSL #include #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; } diff --git a/libunbound/libworker.h b/libunbound/libworker.h index 66644a90f..509ffd026 100644 --- a/libunbound/libworker.h +++ b/libunbound/libworker.h @@ -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 */ diff --git a/services/cache/dns.c b/services/cache/dns.c index 7dadb5c39..9e9222c65 100644 --- a/services/cache/dns.c +++ b/services/cache/dns.c @@ -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. diff --git a/services/cache/infra.c b/services/cache/infra.c index 42d6acad1..da8c67b0f 100644 --- a/services/cache/infra.c +++ b/services/cache/infra.c @@ -39,7 +39,7 @@ * This file contains the infrastructure cache. */ #include "config.h" -#include +#include "ldns/rrdef.h" #include "services/cache/infra.h" #include "util/storage/slabhash.h" #include "util/storage/lookup3.h" diff --git a/services/cache/rrset.c b/services/cache/rrset.c index 642236231..57284667f 100644 --- a/services/cache/rrset.c +++ b/services/cache/rrset.c @@ -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" diff --git a/services/listen_dnsport.c b/services/listen_dnsport.c index 6eeedb75e..b27c9fff9 100644 --- a/services/listen_dnsport.c +++ b/services/listen_dnsport.c @@ -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 @@ -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); diff --git a/services/listen_dnsport.h b/services/listen_dnsport.h index 451a64abc..106ad8423 100644 --- a/services/listen_dnsport.h +++ b/services/listen_dnsport.h @@ -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; diff --git a/services/localzone.c b/services/localzone.c index 4a2187ec4..ef138b9e0 100644 --- a/services/localzone.c +++ b/services/localzone.c @@ -39,9 +39,9 @@ * This file contains functions to enable local zone authority service. */ #include "config.h" -#include -#include #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; icount; 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; } diff --git a/services/localzone.h b/services/localzone.h index 794988e66..ec707a338 100644 --- a/services/localzone.h +++ b/services/localzone.h @@ -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. diff --git a/services/mesh.c b/services/mesh.c index a8cb115ab..e225e6162 100644 --- a/services/mesh.c +++ b/services/mesh.c @@ -43,7 +43,6 @@ * send back to clients. */ #include "config.h" -#include #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 diff --git a/services/mesh.h b/services/mesh.h index 54a3cafec..dc9e6a1e2 100644 --- a/services/mesh.h +++ b/services/mesh.h @@ -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. diff --git a/services/outside_network.c b/services/outside_network.c index ece59098a..b5e3b3ae6 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -45,7 +45,6 @@ # include #endif #include -#include #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 #endif diff --git a/services/outside_network.h b/services/outside_network.h index 87fe8ff10..3d294155f 100644 --- a/services/outside_network.h +++ b/services/outside_network.h @@ -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. diff --git a/smallapp/unbound-anchor.c b/smallapp/unbound-anchor.c index 2b6d4232b..ff54caea2 100644 --- a/smallapp/unbound-anchor.c +++ b/smallapp/unbound-anchor.c @@ -116,7 +116,7 @@ #include "config.h" #include "libunbound/unbound.h" -#include +#include "ldns/rrdef.h" #include #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--; diff --git a/smallapp/unbound-checkconf.c b/smallapp/unbound-checkconf.c index c73d8bdc7..77d2e2e1f 100644 --- a/smallapp/unbound-checkconf.c +++ b/smallapp/unbound-checkconf.c @@ -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 #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); diff --git a/smallapp/unbound-host.c b/smallapp/unbound-host.c index 715aa4a65..c3fb58a12 100644 --- a/smallapp/unbound-host.c +++ b/smallapp/unbound-host.c @@ -60,7 +60,8 @@ #define unbound_lite_wrapstr(s) s #endif #include "libunbound/unbound.h" -#include +#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; ianswer_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); } diff --git a/smallapp/worker_cb.c b/smallapp/worker_cb.c index 4fc2e7d90..ccf9b5910 100644 --- a/smallapp/worker_cb.c +++ b/smallapp/worker_cb.c @@ -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); diff --git a/testcode/asynclook.c b/testcode/asynclook.c index 7ec013c0c..05f15dcf5 100644 --- a/testcode/asynclook.c +++ b/testcode/asynclook.c @@ -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 diff --git a/testcode/delayer.c b/testcode/delayer.c index b42a3b1aa..0c15b5e31 100644 --- a/testcode/delayer.c +++ b/testcode/delayer.c @@ -50,6 +50,7 @@ #include #include "util/net_help.h" #include "util/config_file.h" +#include "ldns/sbuffer.h" #include /** 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, diff --git a/testcode/fake_event.c b/testcode/fake_event.c index 085068c67..d16c0dcc2 100644 --- a/testcode/fake_event.c +++ b/testcode/fake_event.c @@ -57,9 +57,12 @@ #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 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 index 1952dc2a2..000000000 --- a/testcode/harvest.c +++ /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 -#endif -#include -#include -#include "libunbound/unbound.h" -#ifdef HAVE_SYS_STAT_H -#include -#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; iqname); - 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; isublabels) { - if(has_SOA(lab->rrlist)) { - /* copy only NS glue */ - for(i=0; irrlist); 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; irrlist); 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; irrlist); 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; irrlist); 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; irrlist); 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; irrlist))) { - 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; dmaxlabels; 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 index be94eb2fe..000000000 --- a/testcode/ldns-testpkts.c +++ /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 -#include -#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= '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; inext) { - 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; - } -} diff --git a/testcode/perf.c b/testcode/perf.c index cc892efa9..19ce20509 100644 --- a/testcode/perf.c +++ b/testcode/perf.c @@ -43,7 +43,6 @@ #ifdef HAVE_GETOPT_H #include #endif -#include #include #include "util/log.h" #include "util/locks.h" @@ -51,6 +50,10 @@ #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 /** 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; } diff --git a/testcode/pktview.c b/testcode/pktview.c index 3cbdfc395..d9895856d 100644 --- a/testcode/pktview.c +++ b/testcode/pktview.c @@ -40,12 +40,13 @@ */ #include "config.h" -#include #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[]) diff --git a/testcode/readhex.c b/testcode/readhex.c index f212ddd74..886920a91 100644 --- a/testcode/readhex.c +++ b/testcode/readhex.c @@ -41,6 +41,8 @@ #include #include "testcode/readhex.h" #include "util/log.h" +#include "ldns/sbuffer.h" +#include "ldns/parseutil.h" /** skip whitespace */ static void diff --git a/testcode/readhex.h b/testcode/readhex.h index 5ae3f4dbd..eb053d26f 100644 --- a/testcode/readhex.h +++ b/testcode/readhex.h @@ -40,13 +40,13 @@ #ifndef TESTCODE_READHEX_H #define TESTCODE_READHEX_H -#include +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 */ diff --git a/testcode/replay.c b/testcode/replay.c index ce050ed0a..b589e1347 100644 --- a/testcode/replay.c +++ b/testcode/replay.c @@ -42,12 +42,15 @@ #include "config.h" /* for strtod prototype */ #include +#include +#include #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; } diff --git a/testcode/replay.h b/testcode/replay.h index beac3ce83..09ec9a6e1 100644 --- a/testcode/replay.h +++ b/testcode/replay.h @@ -129,7 +129,7 @@ #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; }; /** diff --git a/testcode/signit.c b/testcode/signit.c index 49256e707..7b40bb46c 100644 --- a/testcode/signit.c +++ b/testcode/signit.c @@ -41,9 +41,9 @@ */ #include "config.h" #include -#include "util/log.h" -#include "util/config_file.h" -#include "util/net_help.h" +#include + +#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(); } diff --git a/testcode/streamtcp.c b/testcode/streamtcp.c index 06a18e4cf..7d4bd8cb8 100644 --- a/testcode/streamtcp.c +++ b/testcode/streamtcp.c @@ -43,7 +43,6 @@ #ifdef HAVE_GETOPT_H #include #endif -#include #include #include "util/locks.h" #include "util/log.h" @@ -52,6 +51,11 @@ #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 +#include #include #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 /** 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 index 000000000..77014045f --- /dev/null +++ b/testcode/testpkts.c @@ -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 +#include +#include +#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= '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_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 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; + } +} diff --git a/testcode/ldns-testpkts.h b/testcode/testpkts.h similarity index 82% rename from testcode/ldns-testpkts.h rename to testcode/testpkts.h index 2431e2e1e..77293eedd 100644 --- a/testcode/ldns-testpkts.h +++ b/testcode/testpkts.h @@ -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 - /** 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 */ diff --git a/testcode/unitanchor.c b/testcode/unitanchor.c index de4106a80..e8ee0f7a8 100644 --- a/testcode/unitanchor.c +++ b/testcode/unitanchor.c @@ -39,11 +39,12 @@ */ #include "config.h" -#include #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 diff --git a/testcode/unitdname.c b/testcode/unitdname.c index 3dcd8e43c..50f082353 100644 --- a/testcode/unitdname.c +++ b/testcode/unitdname.c @@ -39,25 +39,24 @@ */ #include "config.h" -#include -#include #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; } diff --git a/testcode/unitmain.c b/testcode/unitmain.c index be4bed95e..40cf29623 100644 --- a/testcode/unitmain.c +++ b/testcode/unitmain.c @@ -61,7 +61,8 @@ #include "nss.h" #endif -#include +#include "ldns/rrdef.h" +#include "ldns/keyraw.h" #include "util/log.h" #include "testcode/unitmain.h" diff --git a/testcode/unitmsgparse.c b/testcode/unitmsgparse.c index 72f9b63a6..9de637897 100644 --- a/testcode/unitmsgparse.c +++ b/testcode/unitmsgparse.c @@ -39,7 +39,7 @@ */ #include "config.h" -#include +#include #include "util/log.h" #include "testcode/unitmain.h" #include "util/data/msgparse.h" @@ -50,6 +50,10 @@ #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; iname); + 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; icount+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; ian_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; ian_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; irrset_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); diff --git a/testcode/unitneg.c b/testcode/unitneg.c index 686ad0086..56900f59a 100644 --- a/testcode/unitneg.c +++ b/testcode/unitneg.c @@ -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; diff --git a/testcode/unitverify.c b/testcode/unitverify.c index d2d268dfd..a26497513 100644 --- a/testcode/unitverify.c +++ b/testcode/unitverify.c @@ -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" @@ -56,6 +56,10 @@ #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); diff --git a/testdata/autotrust_init.rpl b/testdata/autotrust_init.rpl index 53698a107..f7208c264 100644 --- a/testdata/autotrust_init.rpl +++ b/testdata/autotrust_init.rpl @@ -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 diff --git a/testdata/autotrust_init_ds.rpl b/testdata/autotrust_init_ds.rpl index b6c620c73..6245a4add 100644 --- a/testdata/autotrust_init_ds.rpl +++ b/testdata/autotrust_init_ds.rpl @@ -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 diff --git a/testdata/autotrust_init_fail.rpl b/testdata/autotrust_init_fail.rpl index f62e28539..bd7098ea7 100644 --- a/testdata/autotrust_init_fail.rpl +++ b/testdata/autotrust_init_fail.rpl @@ -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 diff --git a/testdata/autotrust_init_failsig.rpl b/testdata/autotrust_init_failsig.rpl index ad46bae8c..792ac9ead 100644 --- a/testdata/autotrust_init_failsig.rpl +++ b/testdata/autotrust_init_failsig.rpl @@ -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 diff --git a/testdata/autotrust_init_sigs.rpl b/testdata/autotrust_init_sigs.rpl index ac8bde0e1..050edf2a9 100644 --- a/testdata/autotrust_init_sigs.rpl +++ b/testdata/autotrust_init_sigs.rpl @@ -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 diff --git a/testdata/autotrust_init_zsk.rpl b/testdata/autotrust_init_zsk.rpl index 16b0a0588..7ef09e45c 100644 --- a/testdata/autotrust_init_zsk.rpl +++ b/testdata/autotrust_init_zsk.rpl @@ -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 diff --git a/testdata/autotrust_probefail.rpl b/testdata/autotrust_probefail.rpl index b63613a96..7b8429d8b 100644 --- a/testdata/autotrust_probefail.rpl +++ b/testdata/autotrust_probefail.rpl @@ -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 diff --git a/testdata/autotrust_probefailsig.rpl b/testdata/autotrust_probefailsig.rpl index 110f23dd2..1b6e288a1 100644 --- a/testdata/autotrust_probefailsig.rpl +++ b/testdata/autotrust_probefailsig.rpl @@ -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 diff --git a/testdata/autotrust_revtp.rpl b/testdata/autotrust_revtp.rpl index 26a4f3093..40075e731 100644 --- a/testdata/autotrust_revtp.rpl +++ b/testdata/autotrust_revtp.rpl @@ -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 diff --git a/testdata/autotrust_revtp_read.rpl b/testdata/autotrust_revtp_read.rpl index b7ea63a8e..80d505028 100644 --- a/testdata/autotrust_revtp_read.rpl +++ b/testdata/autotrust_revtp_read.rpl @@ -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 diff --git a/testdata/autotrust_revtp_use.rpl b/testdata/autotrust_revtp_use.rpl index a6ff624ff..37a097dca 100644 --- a/testdata/autotrust_revtp_use.rpl +++ b/testdata/autotrust_revtp_use.rpl @@ -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 diff --git a/testdata/autotrust_valid_use.rpl b/testdata/autotrust_valid_use.rpl index a6330b143..d461da78a 100644 --- a/testdata/autotrust_valid_use.rpl +++ b/testdata/autotrust_valid_use.rpl @@ -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 diff --git a/testdata/black_data.rpl b/testdata/black_data.rpl index 2ca757939..dd703f62b 100644 --- a/testdata/black_data.rpl +++ b/testdata/black_data.rpl @@ -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 diff --git a/testdata/black_dnskey.rpl b/testdata/black_dnskey.rpl index b75e46a7c..0537757c0 100644 --- a/testdata/black_dnskey.rpl +++ b/testdata/black_dnskey.rpl @@ -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 diff --git a/testdata/black_ds.rpl b/testdata/black_ds.rpl index fd02a8806..7638c1b3f 100644 --- a/testdata/black_ds.rpl +++ b/testdata/black_ds.rpl @@ -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 diff --git a/testdata/black_ds_entry.rpl b/testdata/black_ds_entry.rpl index b0e2cd6b9..f77eecba4 100644 --- a/testdata/black_ds_entry.rpl +++ b/testdata/black_ds_entry.rpl @@ -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 diff --git a/testdata/black_ent.rpl b/testdata/black_ent.rpl index 8a6d3c12e..5aa3d3b04 100644 --- a/testdata/black_ent.rpl +++ b/testdata/black_ent.rpl @@ -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 diff --git a/testdata/black_key_entry.rpl b/testdata/black_key_entry.rpl index 1bc41859a..6a644da18 100644 --- a/testdata/black_key_entry.rpl +++ b/testdata/black_key_entry.rpl @@ -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 diff --git a/testdata/black_prime.rpl b/testdata/black_prime.rpl index cdd0a8707..bb89c39ac 100644 --- a/testdata/black_prime.rpl +++ b/testdata/black_prime.rpl @@ -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 diff --git a/testdata/black_prime_entry.rpl b/testdata/black_prime_entry.rpl index 8ccbb90a7..9bcb1857d 100644 --- a/testdata/black_prime_entry.rpl +++ b/testdata/black_prime_entry.rpl @@ -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 diff --git a/testdata/dlv_anchor.rpl b/testdata/dlv_anchor.rpl index e01b6863a..d9388862e 100644 --- a/testdata/dlv_anchor.rpl +++ b/testdata/dlv_anchor.rpl @@ -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 diff --git a/testdata/dlv_ask_higher.rpl b/testdata/dlv_ask_higher.rpl index 11e3cdaf6..365d3611f 100644 --- a/testdata/dlv_ask_higher.rpl +++ b/testdata/dlv_ask_higher.rpl @@ -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 diff --git a/testdata/dlv_below_ta.rpl b/testdata/dlv_below_ta.rpl index 374294637..78d17f81b 100644 --- a/testdata/dlv_below_ta.rpl +++ b/testdata/dlv_below_ta.rpl @@ -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 diff --git a/testdata/dlv_delegation.rpl b/testdata/dlv_delegation.rpl index 3643f8ceb..a921dc9fb 100644 --- a/testdata/dlv_delegation.rpl +++ b/testdata/dlv_delegation.rpl @@ -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 diff --git a/testdata/dlv_ds_lookup.rpl b/testdata/dlv_ds_lookup.rpl index 50e0fc2ec..3b2d79ad5 100644 --- a/testdata/dlv_ds_lookup.rpl +++ b/testdata/dlv_ds_lookup.rpl @@ -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 diff --git a/testdata/dlv_insecure.rpl b/testdata/dlv_insecure.rpl index f466b9131..d8e6aba20 100644 --- a/testdata/dlv_insecure.rpl +++ b/testdata/dlv_insecure.rpl @@ -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 diff --git a/testdata/dlv_insecure_negcache.rpl b/testdata/dlv_insecure_negcache.rpl index 55aa9278c..a0437750e 100644 --- a/testdata/dlv_insecure_negcache.rpl +++ b/testdata/dlv_insecure_negcache.rpl @@ -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 diff --git a/testdata/dlv_keyretry.rpl b/testdata/dlv_keyretry.rpl index fc472da19..474d1e9d2 100644 --- a/testdata/dlv_keyretry.rpl +++ b/testdata/dlv_keyretry.rpl @@ -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 diff --git a/testdata/dlv_negnx.rpl b/testdata/dlv_negnx.rpl index 866746ad6..79bdea774 100644 --- a/testdata/dlv_negnx.rpl +++ b/testdata/dlv_negnx.rpl @@ -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 diff --git a/testdata/dlv_optout.rpl b/testdata/dlv_optout.rpl index 1b9d7b2ba..b0f84db57 100644 --- a/testdata/dlv_optout.rpl +++ b/testdata/dlv_optout.rpl @@ -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 diff --git a/testdata/dlv_unused.rpl b/testdata/dlv_unused.rpl index 3e4850bc3..47650a060 100644 --- a/testdata/dlv_unused.rpl +++ b/testdata/dlv_unused.rpl @@ -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 diff --git a/testdata/domain_insec_dlv.rpl b/testdata/domain_insec_dlv.rpl index f3789e68c..8c89a70d3 100644 --- a/testdata/domain_insec_dlv.rpl +++ b/testdata/domain_insec_dlv.rpl @@ -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 diff --git a/testdata/domain_insec_ds.rpl b/testdata/domain_insec_ds.rpl index 703acbb9c..d99e7ab62 100644 --- a/testdata/domain_insec_ds.rpl +++ b/testdata/domain_insec_ds.rpl @@ -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 diff --git a/testdata/fwddlv_parse.rpl b/testdata/fwddlv_parse.rpl index 875052225..dd68cf246 100644 --- a/testdata/fwddlv_parse.rpl +++ b/testdata/fwddlv_parse.rpl @@ -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 diff --git a/testdata/iter_class_any.rpl b/testdata/iter_class_any.rpl index 1256dfb5e..2242cbb9c 100644 --- a/testdata/iter_class_any.rpl +++ b/testdata/iter_class_any.rpl @@ -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 diff --git a/testdata/iter_emptydp.rpl b/testdata/iter_emptydp.rpl index 857a64e49..260888c32 100644 --- a/testdata/iter_emptydp.rpl +++ b/testdata/iter_emptydp.rpl @@ -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 diff --git a/testdata/iter_emptydp_for_glue.rpl b/testdata/iter_emptydp_for_glue.rpl index 5e5e27a34..91e76711e 100644 --- a/testdata/iter_emptydp_for_glue.rpl +++ b/testdata/iter_emptydp_for_glue.rpl @@ -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 diff --git a/testdata/iter_primenoglue.rpl b/testdata/iter_primenoglue.rpl index 24de1e367..c3709dcb1 100644 --- a/testdata/iter_primenoglue.rpl +++ b/testdata/iter_primenoglue.rpl @@ -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 diff --git a/testdata/local_nodefault.rpl b/testdata/local_nodefault.rpl index 208b68327..91243d19f 100644 --- a/testdata/local_nodefault.rpl +++ b/testdata/local_nodefault.rpl @@ -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 diff --git a/testdata/local_transparent_sametype.rpl b/testdata/local_transparent_sametype.rpl index 6f0880b5d..a73729769 100644 --- a/testdata/local_transparent_sametype.rpl +++ b/testdata/local_transparent_sametype.rpl @@ -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 diff --git a/testdata/local_typetransparent.rpl b/testdata/local_typetransparent.rpl index c1c1931aa..6396918f7 100644 --- a/testdata/local_typetransparent.rpl +++ b/testdata/local_typetransparent.rpl @@ -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 diff --git a/testdata/net_signed_servfail.rpl b/testdata/net_signed_servfail.rpl index 5dfe9b9a9..9fd50df97 100644 --- a/testdata/net_signed_servfail.rpl +++ b/testdata/net_signed_servfail.rpl @@ -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 diff --git a/testdata/nomem_cnametopos.rpl b/testdata/nomem_cnametopos.rpl index 860020946..68a0b96cb 100644 --- a/testdata/nomem_cnametopos.rpl +++ b/testdata/nomem_cnametopos.rpl @@ -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 diff --git a/testdata/test_sigs.rsasha256_draft b/testdata/test_sigs.rsasha256_draft index 94122e915..4e1cb9c65 100644 --- a/testdata/test_sigs.rsasha256_draft +++ b/testdata/test_sigs.rsasha256_draft @@ -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 diff --git a/testdata/val_anchor_nx.rpl b/testdata/val_anchor_nx.rpl index 66a08c524..be347b11d 100644 --- a/testdata/val_anchor_nx.rpl +++ b/testdata/val_anchor_nx.rpl @@ -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 diff --git a/testdata/val_anchor_nx_nosig.rpl b/testdata/val_anchor_nx_nosig.rpl index d69db39d9..de9be6c45 100644 --- a/testdata/val_anchor_nx_nosig.rpl +++ b/testdata/val_anchor_nx_nosig.rpl @@ -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 diff --git a/testdata/val_ans_dsent.rpl b/testdata/val_ans_dsent.rpl index 150504037..1eb7778c2 100644 --- a/testdata/val_ans_dsent.rpl +++ b/testdata/val_ans_dsent.rpl @@ -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 diff --git a/testdata/val_ans_nx.rpl b/testdata/val_ans_nx.rpl index 8eceaa962..257377202 100644 --- a/testdata/val_ans_nx.rpl +++ b/testdata/val_ans_nx.rpl @@ -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 diff --git a/testdata/val_any.rpl b/testdata/val_any.rpl index e0f7b1f62..4285f49c5 100644 --- a/testdata/val_any.rpl +++ b/testdata/val_any.rpl @@ -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 diff --git a/testdata/val_any_cname.rpl b/testdata/val_any_cname.rpl index 925bc9240..e85c14c20 100644 --- a/testdata/val_any_cname.rpl +++ b/testdata/val_any_cname.rpl @@ -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 diff --git a/testdata/val_any_dname.rpl b/testdata/val_any_dname.rpl index 459b11bd3..6e94f9a4e 100644 --- a/testdata/val_any_dname.rpl +++ b/testdata/val_any_dname.rpl @@ -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 diff --git a/testdata/val_cname_loop1.rpl b/testdata/val_cname_loop1.rpl index 5fd4acc75..11d094cdd 100644 --- a/testdata/val_cname_loop1.rpl +++ b/testdata/val_cname_loop1.rpl @@ -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 diff --git a/testdata/val_cname_loop2.rpl b/testdata/val_cname_loop2.rpl index e8cd24bcc..af293401b 100644 --- a/testdata/val_cname_loop2.rpl +++ b/testdata/val_cname_loop2.rpl @@ -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 diff --git a/testdata/val_cnameinsectopos.rpl b/testdata/val_cnameinsectopos.rpl index aa521c30f..29d1565f3 100644 --- a/testdata/val_cnameinsectopos.rpl +++ b/testdata/val_cnameinsectopos.rpl @@ -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 diff --git a/testdata/val_cnamenx_dblnsec.rpl b/testdata/val_cnamenx_dblnsec.rpl index 0064ab580..77c50f60b 100644 --- a/testdata/val_cnamenx_dblnsec.rpl +++ b/testdata/val_cnamenx_dblnsec.rpl @@ -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 diff --git a/testdata/val_cnamenx_rcodenx.rpl b/testdata/val_cnamenx_rcodenx.rpl index 6676b340f..8d9c2d4fe 100644 --- a/testdata/val_cnamenx_rcodenx.rpl +++ b/testdata/val_cnamenx_rcodenx.rpl @@ -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 diff --git a/testdata/val_cnameqtype.rpl b/testdata/val_cnameqtype.rpl index cd9b8fa22..66a894f6c 100644 --- a/testdata/val_cnameqtype.rpl +++ b/testdata/val_cnameqtype.rpl @@ -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 diff --git a/testdata/val_cnametocloser.rpl b/testdata/val_cnametocloser.rpl index e9c05baed..c3377c239 100644 --- a/testdata/val_cnametocloser.rpl +++ b/testdata/val_cnametocloser.rpl @@ -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 diff --git a/testdata/val_cnametocloser_nosig.rpl b/testdata/val_cnametocloser_nosig.rpl index c56faede7..80d102003 100644 --- a/testdata/val_cnametocloser_nosig.rpl +++ b/testdata/val_cnametocloser_nosig.rpl @@ -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 diff --git a/testdata/val_cnametocnamewctoposwc.rpl b/testdata/val_cnametocnamewctoposwc.rpl index 12f83e82b..56faf4130 100644 --- a/testdata/val_cnametocnamewctoposwc.rpl +++ b/testdata/val_cnametocnamewctoposwc.rpl @@ -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 diff --git a/testdata/val_cnametodname.rpl b/testdata/val_cnametodname.rpl index d9b05c638..43561d280 100644 --- a/testdata/val_cnametodname.rpl +++ b/testdata/val_cnametodname.rpl @@ -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 diff --git a/testdata/val_cnametodnametocnametopos.rpl b/testdata/val_cnametodnametocnametopos.rpl index 887c1afc4..0a3a32360 100644 --- a/testdata/val_cnametodnametocnametopos.rpl +++ b/testdata/val_cnametodnametocnametopos.rpl @@ -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 diff --git a/testdata/val_cnametoinsecure.rpl b/testdata/val_cnametoinsecure.rpl index aece72a7b..538e9fb88 100644 --- a/testdata/val_cnametoinsecure.rpl +++ b/testdata/val_cnametoinsecure.rpl @@ -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 diff --git a/testdata/val_cnametonodata.rpl b/testdata/val_cnametonodata.rpl index e47161806..b930b5607 100644 --- a/testdata/val_cnametonodata.rpl +++ b/testdata/val_cnametonodata.rpl @@ -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 diff --git a/testdata/val_cnametonodata_nonsec.rpl b/testdata/val_cnametonodata_nonsec.rpl index 5a263632c..588273fba 100644 --- a/testdata/val_cnametonodata_nonsec.rpl +++ b/testdata/val_cnametonodata_nonsec.rpl @@ -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 diff --git a/testdata/val_cnametonsec.rpl b/testdata/val_cnametonsec.rpl index 282345307..6b32b8da5 100644 --- a/testdata/val_cnametonsec.rpl +++ b/testdata/val_cnametonsec.rpl @@ -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 diff --git a/testdata/val_cnametonx.rpl b/testdata/val_cnametonx.rpl index 6b041bbc7..cc3315608 100644 --- a/testdata/val_cnametonx.rpl +++ b/testdata/val_cnametonx.rpl @@ -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 diff --git a/testdata/val_cnametooptin.rpl b/testdata/val_cnametooptin.rpl index 93853a741..aa58d07f0 100644 --- a/testdata/val_cnametooptin.rpl +++ b/testdata/val_cnametooptin.rpl @@ -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 diff --git a/testdata/val_cnametooptout.rpl b/testdata/val_cnametooptout.rpl index d4638d07f..0150a7d87 100644 --- a/testdata/val_cnametooptout.rpl +++ b/testdata/val_cnametooptout.rpl @@ -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 diff --git a/testdata/val_cnametopos.rpl b/testdata/val_cnametopos.rpl index d5136d5c5..9ff4020a9 100644 --- a/testdata/val_cnametopos.rpl +++ b/testdata/val_cnametopos.rpl @@ -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 diff --git a/testdata/val_cnametoposnowc.rpl b/testdata/val_cnametoposnowc.rpl index bc1a69456..6e8ff4f27 100644 --- a/testdata/val_cnametoposnowc.rpl +++ b/testdata/val_cnametoposnowc.rpl @@ -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 diff --git a/testdata/val_cnametoposwc.rpl b/testdata/val_cnametoposwc.rpl index feb178b08..114fa705a 100644 --- a/testdata/val_cnametoposwc.rpl +++ b/testdata/val_cnametoposwc.rpl @@ -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 diff --git a/testdata/val_cnamewctonodata.rpl b/testdata/val_cnamewctonodata.rpl index 97722566b..9c3928a19 100644 --- a/testdata/val_cnamewctonodata.rpl +++ b/testdata/val_cnamewctonodata.rpl @@ -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 diff --git a/testdata/val_cnamewctonx.rpl b/testdata/val_cnamewctonx.rpl index 5675c42a5..7da96e259 100644 --- a/testdata/val_cnamewctonx.rpl +++ b/testdata/val_cnamewctonx.rpl @@ -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 diff --git a/testdata/val_cnamewctoposwc.rpl b/testdata/val_cnamewctoposwc.rpl index 057cd0311..33fbc4551 100644 --- a/testdata/val_cnamewctoposwc.rpl +++ b/testdata/val_cnamewctoposwc.rpl @@ -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 diff --git a/testdata/val_dnametoolong.rpl b/testdata/val_dnametoolong.rpl index 43b27f186..b5eea56c6 100644 --- a/testdata/val_dnametoolong.rpl +++ b/testdata/val_dnametoolong.rpl @@ -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 diff --git a/testdata/val_dnametopos.rpl b/testdata/val_dnametopos.rpl index f564f879d..6264a6d0e 100644 --- a/testdata/val_dnametopos.rpl +++ b/testdata/val_dnametopos.rpl @@ -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 diff --git a/testdata/val_dnametoposwc.rpl b/testdata/val_dnametoposwc.rpl index 6ece53440..e1e91d494 100644 --- a/testdata/val_dnametoposwc.rpl +++ b/testdata/val_dnametoposwc.rpl @@ -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 diff --git a/testdata/val_dnamewc.rpl b/testdata/val_dnamewc.rpl index 3c02768a0..c34b9e0f9 100644 --- a/testdata/val_dnamewc.rpl +++ b/testdata/val_dnamewc.rpl @@ -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 diff --git a/testdata/val_ds_afterprime.rpl b/testdata/val_ds_afterprime.rpl index 258f1c936..0b203d267 100644 --- a/testdata/val_ds_afterprime.rpl +++ b/testdata/val_ds_afterprime.rpl @@ -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 diff --git a/testdata/val_ds_cname.rpl b/testdata/val_ds_cname.rpl index 1c9fb7751..95fcf5be7 100644 --- a/testdata/val_ds_cname.rpl +++ b/testdata/val_ds_cname.rpl @@ -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 diff --git a/testdata/val_ds_cnamesub.rpl b/testdata/val_ds_cnamesub.rpl index a147b93d6..d70e2ae29 100644 --- a/testdata/val_ds_cnamesub.rpl +++ b/testdata/val_ds_cnamesub.rpl @@ -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 diff --git a/testdata/val_ds_gost.crpl b/testdata/val_ds_gost.crpl index 11601e1f2..10bb7fbd4 100644 --- a/testdata/val_ds_gost.crpl +++ b/testdata/val_ds_gost.crpl @@ -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 diff --git a/testdata/val_ds_gost_downgrade.crpl b/testdata/val_ds_gost_downgrade.crpl index 00e6e4e3b..b8caae2fa 100644 --- a/testdata/val_ds_gost_downgrade.crpl +++ b/testdata/val_ds_gost_downgrade.crpl @@ -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 diff --git a/testdata/val_ds_sha2.crpl b/testdata/val_ds_sha2.crpl index 111382d22..bbf181185 100644 --- a/testdata/val_ds_sha2.crpl +++ b/testdata/val_ds_sha2.crpl @@ -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 diff --git a/testdata/val_ds_sha2_downgrade.crpl b/testdata/val_ds_sha2_downgrade.crpl index 2418c87fd..ee9a17123 100644 --- a/testdata/val_ds_sha2_downgrade.crpl +++ b/testdata/val_ds_sha2_downgrade.crpl @@ -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 diff --git a/testdata/val_dsnsec.rpl b/testdata/val_dsnsec.rpl index 32702034f..5e55b2ba0 100644 --- a/testdata/val_dsnsec.rpl +++ b/testdata/val_dsnsec.rpl @@ -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 diff --git a/testdata/val_entds.rpl b/testdata/val_entds.rpl index 6235baadc..6ad86271a 100644 --- a/testdata/val_entds.rpl +++ b/testdata/val_entds.rpl @@ -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 diff --git a/testdata/val_faildnskey.rpl b/testdata/val_faildnskey.rpl index 1d154591f..7d0350f1a 100644 --- a/testdata/val_faildnskey.rpl +++ b/testdata/val_faildnskey.rpl @@ -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 diff --git a/testdata/val_faildnskey_ok.rpl b/testdata/val_faildnskey_ok.rpl index 5bd6db261..3764000f1 100644 --- a/testdata/val_faildnskey_ok.rpl +++ b/testdata/val_faildnskey_ok.rpl @@ -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 diff --git a/testdata/val_fwdds.rpl b/testdata/val_fwdds.rpl index 3fdd33346..26e30f44c 100644 --- a/testdata/val_fwdds.rpl +++ b/testdata/val_fwdds.rpl @@ -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 diff --git a/testdata/val_keyprefetch.rpl b/testdata/val_keyprefetch.rpl index 9e9b13f38..9b927b20e 100644 --- a/testdata/val_keyprefetch.rpl +++ b/testdata/val_keyprefetch.rpl @@ -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 diff --git a/testdata/val_keyprefetch_verify.rpl b/testdata/val_keyprefetch_verify.rpl index 567b6395d..5f044cc2f 100644 --- a/testdata/val_keyprefetch_verify.rpl +++ b/testdata/val_keyprefetch_verify.rpl @@ -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 diff --git a/testdata/val_mal_wc.rpl b/testdata/val_mal_wc.rpl index ba0c6c951..d834fe648 100644 --- a/testdata/val_mal_wc.rpl +++ b/testdata/val_mal_wc.rpl @@ -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 diff --git a/testdata/val_negcache_ds.rpl b/testdata/val_negcache_ds.rpl index a589eefbc..c7739e34c 100644 --- a/testdata/val_negcache_ds.rpl +++ b/testdata/val_negcache_ds.rpl @@ -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 diff --git a/testdata/val_negcache_dssoa.rpl b/testdata/val_negcache_dssoa.rpl index 7040af830..3f35bbf3b 100644 --- a/testdata/val_negcache_dssoa.rpl +++ b/testdata/val_negcache_dssoa.rpl @@ -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 diff --git a/testdata/val_nodata.rpl b/testdata/val_nodata.rpl index 8fc8d51ee..1dbbb7784 100644 --- a/testdata/val_nodata.rpl +++ b/testdata/val_nodata.rpl @@ -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 diff --git a/testdata/val_nodata_ent.rpl b/testdata/val_nodata_ent.rpl index 4eaace1d8..467bdf5f3 100644 --- a/testdata/val_nodata_ent.rpl +++ b/testdata/val_nodata_ent.rpl @@ -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 diff --git a/testdata/val_nodata_entwc.rpl b/testdata/val_nodata_entwc.rpl index 0bbc2a9e8..03c09a207 100644 --- a/testdata/val_nodata_entwc.rpl +++ b/testdata/val_nodata_entwc.rpl @@ -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 diff --git a/testdata/val_nodata_failsig.rpl b/testdata/val_nodata_failsig.rpl index 9cd8289c7..df3b75e01 100644 --- a/testdata/val_nodata_failsig.rpl +++ b/testdata/val_nodata_failsig.rpl @@ -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 diff --git a/testdata/val_nodatawc.rpl b/testdata/val_nodatawc.rpl index dc4971f6f..30e38b605 100644 --- a/testdata/val_nodatawc.rpl +++ b/testdata/val_nodatawc.rpl @@ -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 diff --git a/testdata/val_nodatawc_one.rpl b/testdata/val_nodatawc_one.rpl index 375be171b..88d66effb 100644 --- a/testdata/val_nodatawc_one.rpl +++ b/testdata/val_nodatawc_one.rpl @@ -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 diff --git a/testdata/val_nokeyprime.rpl b/testdata/val_nokeyprime.rpl index c30396af9..5eae44f81 100644 --- a/testdata/val_nokeyprime.rpl +++ b/testdata/val_nokeyprime.rpl @@ -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 diff --git a/testdata/val_nsec3_b1_nameerror.rpl b/testdata/val_nsec3_b1_nameerror.rpl index b7c300cca..dbe1f9aa3 100644 --- a/testdata/val_nsec3_b1_nameerror.rpl +++ b/testdata/val_nsec3_b1_nameerror.rpl @@ -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 diff --git a/testdata/val_nsec3_b1_nameerror_nowc.rpl b/testdata/val_nsec3_b1_nameerror_nowc.rpl index bf4d22321..1293aa919 100644 --- a/testdata/val_nsec3_b1_nameerror_nowc.rpl +++ b/testdata/val_nsec3_b1_nameerror_nowc.rpl @@ -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 diff --git a/testdata/val_nsec3_b21_nodataent.rpl b/testdata/val_nsec3_b21_nodataent.rpl index f384792b2..10f51f83a 100644 --- a/testdata/val_nsec3_b21_nodataent.rpl +++ b/testdata/val_nsec3_b21_nodataent.rpl @@ -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 diff --git a/testdata/val_nsec3_b2_nodata.rpl b/testdata/val_nsec3_b2_nodata.rpl index 0700ab67a..11af26967 100644 --- a/testdata/val_nsec3_b2_nodata.rpl +++ b/testdata/val_nsec3_b2_nodata.rpl @@ -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 diff --git a/testdata/val_nsec3_b2_nodata_nons.rpl b/testdata/val_nsec3_b2_nodata_nons.rpl index 11f157925..8311fffc0 100644 --- a/testdata/val_nsec3_b2_nodata_nons.rpl +++ b/testdata/val_nsec3_b2_nodata_nons.rpl @@ -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 diff --git a/testdata/val_nsec3_b3_optout.rpl b/testdata/val_nsec3_b3_optout.rpl index a3a938a69..5cde1a9bc 100644 --- a/testdata/val_nsec3_b3_optout.rpl +++ b/testdata/val_nsec3_b3_optout.rpl @@ -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 diff --git a/testdata/val_nsec3_b3_optout_negcache.rpl b/testdata/val_nsec3_b3_optout_negcache.rpl index b52b3925d..c2468bab8 100644 --- a/testdata/val_nsec3_b3_optout_negcache.rpl +++ b/testdata/val_nsec3_b3_optout_negcache.rpl @@ -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 diff --git a/testdata/val_nsec3_b4_wild.rpl b/testdata/val_nsec3_b4_wild.rpl index 4da066c4e..e3041ecd8 100644 --- a/testdata/val_nsec3_b4_wild.rpl +++ b/testdata/val_nsec3_b4_wild.rpl @@ -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 diff --git a/testdata/val_nsec3_b5_wcnodata.rpl b/testdata/val_nsec3_b5_wcnodata.rpl index d12bb8c39..c8014ed69 100644 --- a/testdata/val_nsec3_b5_wcnodata.rpl +++ b/testdata/val_nsec3_b5_wcnodata.rpl @@ -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 diff --git a/testdata/val_nsec3_cname_ds.rpl b/testdata/val_nsec3_cname_ds.rpl index 34c167856..299400569 100644 --- a/testdata/val_nsec3_cname_ds.rpl +++ b/testdata/val_nsec3_cname_ds.rpl @@ -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 diff --git a/testdata/val_nsec3_cname_par.rpl b/testdata/val_nsec3_cname_par.rpl index 7bd0a1a2b..20ea0619d 100644 --- a/testdata/val_nsec3_cname_par.rpl +++ b/testdata/val_nsec3_cname_par.rpl @@ -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 diff --git a/testdata/val_nsec3_cname_sub.rpl b/testdata/val_nsec3_cname_sub.rpl index 8babfad37..7b38b1a1b 100644 --- a/testdata/val_nsec3_cname_sub.rpl +++ b/testdata/val_nsec3_cname_sub.rpl @@ -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 diff --git a/testdata/val_nsec3_cnametocnamewctoposwc.rpl b/testdata/val_nsec3_cnametocnamewctoposwc.rpl index d6e92d89a..d8f2c411e 100644 --- a/testdata/val_nsec3_cnametocnamewctoposwc.rpl +++ b/testdata/val_nsec3_cnametocnamewctoposwc.rpl @@ -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 diff --git a/testdata/val_nsec3_iter_high.rpl b/testdata/val_nsec3_iter_high.rpl index 9ae0fcae3..451bec540 100644 --- a/testdata/val_nsec3_iter_high.rpl +++ b/testdata/val_nsec3_iter_high.rpl @@ -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 diff --git a/testdata/val_nsec3_nods.rpl b/testdata/val_nsec3_nods.rpl index d9dfdfabd..60f20817f 100644 --- a/testdata/val_nsec3_nods.rpl +++ b/testdata/val_nsec3_nods.rpl @@ -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 diff --git a/testdata/val_nsec3_nods_badsig.rpl b/testdata/val_nsec3_nods_badsig.rpl index 8e5a0cf45..5e2653264 100644 --- a/testdata/val_nsec3_nods_badsig.rpl +++ b/testdata/val_nsec3_nods_badsig.rpl @@ -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 diff --git a/testdata/val_nsec3_nods_negcache.rpl b/testdata/val_nsec3_nods_negcache.rpl index 75dcbed75..0c4d20ec2 100644 --- a/testdata/val_nsec3_nods_negcache.rpl +++ b/testdata/val_nsec3_nods_negcache.rpl @@ -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 diff --git a/testdata/val_nsec3_optout_ad.rpl b/testdata/val_nsec3_optout_ad.rpl index 2001640c2..1c484eab0 100644 --- a/testdata/val_nsec3_optout_ad.rpl +++ b/testdata/val_nsec3_optout_ad.rpl @@ -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 diff --git a/testdata/val_nsec3_optout_cache.rpl b/testdata/val_nsec3_optout_cache.rpl index 14462d48a..3ec7ccbdd 100644 --- a/testdata/val_nsec3_optout_cache.rpl +++ b/testdata/val_nsec3_optout_cache.rpl @@ -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 diff --git a/testdata/val_nsec3_wcany.rpl b/testdata/val_nsec3_wcany.rpl index ba8ce2c3c..fff0aa7cd 100644 --- a/testdata/val_nsec3_wcany.rpl +++ b/testdata/val_nsec3_wcany.rpl @@ -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 diff --git a/testdata/val_nx.rpl b/testdata/val_nx.rpl index 885dc42a3..434354fb4 100644 --- a/testdata/val_nx.rpl +++ b/testdata/val_nx.rpl @@ -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 diff --git a/testdata/val_nx_nsec3_collision.rpl b/testdata/val_nx_nsec3_collision.rpl index 60ddb1c64..85236e46e 100644 --- a/testdata/val_nx_nsec3_collision.rpl +++ b/testdata/val_nx_nsec3_collision.rpl @@ -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 diff --git a/testdata/val_nx_nsec3_params.rpl b/testdata/val_nx_nsec3_params.rpl index f25245a0b..926712637 100644 --- a/testdata/val_nx_nsec3_params.rpl +++ b/testdata/val_nx_nsec3_params.rpl @@ -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 diff --git a/testdata/val_nx_overreach.rpl b/testdata/val_nx_overreach.rpl index 0e958f514..4494c30f5 100644 --- a/testdata/val_nx_overreach.rpl +++ b/testdata/val_nx_overreach.rpl @@ -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 diff --git a/testdata/val_pos_truncns.rpl b/testdata/val_pos_truncns.rpl index 63b7fd0fd..12d3a5481 100644 --- a/testdata/val_pos_truncns.rpl +++ b/testdata/val_pos_truncns.rpl @@ -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 diff --git a/testdata/val_positive.rpl b/testdata/val_positive.rpl index 3c45c10a1..c6f8d797a 100644 --- a/testdata/val_positive.rpl +++ b/testdata/val_positive.rpl @@ -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 diff --git a/testdata/val_positive_wc.rpl b/testdata/val_positive_wc.rpl index 355e31581..f6a04e71e 100644 --- a/testdata/val_positive_wc.rpl +++ b/testdata/val_positive_wc.rpl @@ -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 diff --git a/testdata/val_qds_badanc.rpl b/testdata/val_qds_badanc.rpl index 8fc6195ca..b451135ff 100644 --- a/testdata/val_qds_badanc.rpl +++ b/testdata/val_qds_badanc.rpl @@ -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 diff --git a/testdata/val_qds_oneanc.rpl b/testdata/val_qds_oneanc.rpl index 9a0904084..657b4856e 100644 --- a/testdata/val_qds_oneanc.rpl +++ b/testdata/val_qds_oneanc.rpl @@ -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 diff --git a/testdata/val_qds_twoanc.rpl b/testdata/val_qds_twoanc.rpl index 0d7828956..61e7458b0 100644 --- a/testdata/val_qds_twoanc.rpl +++ b/testdata/val_qds_twoanc.rpl @@ -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 diff --git a/testdata/val_refer_unsignadd.rpl b/testdata/val_refer_unsignadd.rpl index 93e87f619..eb74817dd 100644 --- a/testdata/val_refer_unsignadd.rpl +++ b/testdata/val_refer_unsignadd.rpl @@ -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 diff --git a/testdata/val_referd.rpl b/testdata/val_referd.rpl index fe8900c0b..67e44ea75 100644 --- a/testdata/val_referd.rpl +++ b/testdata/val_referd.rpl @@ -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 diff --git a/testdata/val_referglue.rpl b/testdata/val_referglue.rpl index fd7e7caa5..bd829bff4 100644 --- a/testdata/val_referglue.rpl +++ b/testdata/val_referglue.rpl @@ -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 diff --git a/testdata/val_rrsig.rpl b/testdata/val_rrsig.rpl index 202d07ded..6ea8c1bc3 100644 --- a/testdata/val_rrsig.rpl +++ b/testdata/val_rrsig.rpl @@ -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 diff --git a/testdata/val_secds.rpl b/testdata/val_secds.rpl index 28be61428..d1a5f64b5 100644 --- a/testdata/val_secds.rpl +++ b/testdata/val_secds.rpl @@ -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 diff --git a/testdata/val_secds_nosig.rpl b/testdata/val_secds_nosig.rpl index 5aeb47f93..310c9bb88 100644 --- a/testdata/val_secds_nosig.rpl +++ b/testdata/val_secds_nosig.rpl @@ -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 diff --git a/testdata/val_stub_noroot.rpl b/testdata/val_stub_noroot.rpl index cfa133b80..369bc66e4 100644 --- a/testdata/val_stub_noroot.rpl +++ b/testdata/val_stub_noroot.rpl @@ -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 diff --git a/testdata/val_stubds.rpl b/testdata/val_stubds.rpl index a79c5b6d1..565c59633 100644 --- a/testdata/val_stubds.rpl +++ b/testdata/val_stubds.rpl @@ -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 diff --git a/testdata/val_ta_algo_dnskey.rpl b/testdata/val_ta_algo_dnskey.rpl index 21cbdab7d..d5dd26040 100644 --- a/testdata/val_ta_algo_dnskey.rpl +++ b/testdata/val_ta_algo_dnskey.rpl @@ -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 diff --git a/testdata/val_ta_algo_missing.rpl b/testdata/val_ta_algo_missing.rpl index 3baeabfd7..67e5fa235 100644 --- a/testdata/val_ta_algo_missing.rpl +++ b/testdata/val_ta_algo_missing.rpl @@ -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 diff --git a/testdata/val_twocname.rpl b/testdata/val_twocname.rpl index 4474d71f8..9495c2853 100644 --- a/testdata/val_twocname.rpl +++ b/testdata/val_twocname.rpl @@ -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 diff --git a/testdata/val_unalgo_anchor.rpl b/testdata/val_unalgo_anchor.rpl index e588b8a54..1a653186a 100644 --- a/testdata/val_unalgo_anchor.rpl +++ b/testdata/val_unalgo_anchor.rpl @@ -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 diff --git a/testdata/val_unalgo_dlv.rpl b/testdata/val_unalgo_dlv.rpl index 8157793a3..7e1d8c9d5 100644 --- a/testdata/val_unalgo_dlv.rpl +++ b/testdata/val_unalgo_dlv.rpl @@ -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 diff --git a/testdata/val_unalgo_ds.rpl b/testdata/val_unalgo_ds.rpl index 72e39b812..adf1ff123 100644 --- a/testdata/val_unalgo_ds.rpl +++ b/testdata/val_unalgo_ds.rpl @@ -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 diff --git a/testdata/val_unsec_cname.rpl b/testdata/val_unsec_cname.rpl index a1871401b..c532da5ee 100644 --- a/testdata/val_unsec_cname.rpl +++ b/testdata/val_unsec_cname.rpl @@ -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 diff --git a/testdata/val_unsecds.rpl b/testdata/val_unsecds.rpl index 21cb80076..ff2bc7633 100644 --- a/testdata/val_unsecds.rpl +++ b/testdata/val_unsecds.rpl @@ -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 diff --git a/testdata/val_unsecds_negcache.rpl b/testdata/val_unsecds_negcache.rpl index eae1dab78..de3183978 100644 --- a/testdata/val_unsecds_negcache.rpl +++ b/testdata/val_unsecds_negcache.rpl @@ -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 diff --git a/testdata/val_unsecds_qtypeds.rpl b/testdata/val_unsecds_qtypeds.rpl index 0448ea4c0..4d82a1b7e 100644 --- a/testdata/val_unsecds_qtypeds.rpl +++ b/testdata/val_unsecds_qtypeds.rpl @@ -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 diff --git a/testdata/val_wild_pos.rpl b/testdata/val_wild_pos.rpl index b5b56e954..d47f03f59 100644 --- a/testdata/val_wild_pos.rpl +++ b/testdata/val_wild_pos.rpl @@ -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 diff --git a/util/config_file.c b/util/config_file.c index 1e0bd72df..a804877d4 100644 --- a/util/config_file.c +++ b/util/config_file.c @@ -41,9 +41,8 @@ #include "config.h" #include -#include +#include #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 #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); } diff --git a/util/configparser.c b/util/configparser.c index 7d044d09b..d03528786 100644 --- a/util/configparser.c +++ b/util/configparser.c @@ -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" @@ -58,11 +58,14 @@ /* 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 /* 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" diff --git a/util/configparser.h b/util/configparser.h index a862769de..f036ada5a 100644 --- a/util/configparser.h +++ b/util/configparser.h @@ -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 @@ -30,15 +30,6 @@ 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 */ diff --git a/util/data/dname.c b/util/data/dname.c index d2b299744..8ee9d8a2d 100644 --- a/util/data/dname.c +++ b/util/data/dname.c @@ -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; diff --git a/util/data/dname.h b/util/data/dname.h index b942848a9..d7163289d 100644 --- a/util/data/dname.h +++ b/util/data/dname.h @@ -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 diff --git a/util/data/msgencode.c b/util/data/msgencode.c index 33f14b4da..66c45dfd0 100644 --- a/util/data/msgencode.c +++ b/util/data/msgencode.c @@ -40,7 +40,6 @@ */ #include "config.h" -#include #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. */ diff --git a/util/data/msgencode.h b/util/data/msgencode.h index 13f0c1b4d..a55693976 100644 --- a/util/data/msgencode.h +++ b/util/data/msgencode.h @@ -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 */ diff --git a/util/data/msgparse.c b/util/data/msgparse.c index 2791ae560..29299bfd5 100644 --- a/util/data/msgparse.c +++ b/util/data/msgparse.c @@ -37,12 +37,15 @@ * Routines for message parsing a packet buffer to a descriptive structure. */ #include "config.h" -#include #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. */ } diff --git a/util/data/msgparse.h b/util/data/msgparse.h index 83d2aaaa6..d0f6bb5aa 100644 --- a/util/data/msgparse.h +++ b/util/data/msgparse.h @@ -63,7 +63,9 @@ #ifndef UTIL_DATA_MSGPARSE_H #define UTIL_DATA_MSGPARSE_H #include "util/storage/lruhash.h" -#include +#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); /** diff --git a/util/data/msgreply.c b/util/data/msgreply.c index 004d6c928..25f0af155 100644 --- a/util/data/msgreply.c +++ b/util/data/msgreply.c @@ -40,7 +40,6 @@ */ #include "config.h" -#include #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); diff --git a/util/data/msgreply.h b/util/data/msgreply.h index 6087c6b20..a894d3287 100644 --- a/util/data/msgreply.h +++ b/util/data/msgreply.h @@ -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); diff --git a/util/data/packed_rrset.c b/util/data/packed_rrset.c index 1bf2e8f00..d9c2f308a 100644 --- a/util/data/packed_rrset.c +++ b/util/data/packed_rrset.c @@ -40,7 +40,6 @@ */ #include "config.h" -#include #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; icount+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; ittl = 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; irr_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; jrr_len[i] += ldns_rdf_size(ldns_rr_rdf(rr, j)); - } - - /* fixup rest of ptrs */ - for(i=0; irr_data[i] = nextrdata; - nextrdata += data->rr_len[i]; - } - - /* copy data in there */ - for(i=0; irr_len[i]-2); - size_t p = sizeof(rdlen); - memmove(data->rr_data[i], &rdlen, p); - for(j=0; jrr_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; icount+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; -} diff --git a/util/data/packed_rrset.h b/util/data/packed_rrset.h index 9530aa604..f46e5e3ee 100644 --- a/util/data/packed_rrset.h +++ b/util/data/packed_rrset.h @@ -42,7 +42,6 @@ #ifndef UTIL_DATA_PACKED_RRSET_H #define UTIL_DATA_PACKED_RRSET_H #include "util/storage/lruhash.h" -#include 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 */ diff --git a/util/log.c b/util/log.c index 9b2daea32..91387161c 100644 --- a/util/log.c +++ b/util/log.c @@ -40,6 +40,8 @@ #include "config.h" #include "util/log.h" #include "util/locks.h" +#include "ldns/sbuffer.h" +#include #ifdef HAVE_TIME_H #include #endif diff --git a/util/log.h b/util/log.h index 5ba1a0bc4..2ca88d0b6 100644 --- a/util/log.h +++ b/util/log.h @@ -41,7 +41,7 @@ #ifndef UTIL_LOG_H #define UTIL_LOG_H -#include +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. diff --git a/util/module.h b/util/module.h index 3ec25524b..f1f03b190 100644 --- a/util/module.h +++ b/util/module.h @@ -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 */ diff --git a/util/net_help.c b/util/net_help.c index 64bd876dc..a238f1548 100644 --- a/util/net_help.c +++ b/util/net_help.c @@ -38,12 +38,13 @@ */ #include "config.h" -#include #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 #ifdef HAVE_OPENSSL_SSL_H #include @@ -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); diff --git a/util/netevent.c b/util/netevent.c index c25d42c2d..1a30a6145 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -39,11 +39,12 @@ * This file contains event notification functions. */ #include "config.h" -#include #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 #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); diff --git a/util/netevent.h b/util/netevent.h index f75c394d7..de00cc063 100644 --- a/util/netevent.h +++ b/util/netevent.h @@ -60,7 +60,7 @@ #ifndef NET_EVENT_H #define NET_EVENT_H -#include +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); /** diff --git a/util/random.c b/util/random.c index 5d71fcfa4..edf584feb 100644 --- a/util/random.c +++ b/util/random.c @@ -60,6 +60,7 @@ #include "config.h" #include "util/random.h" #include "util/log.h" +#include #ifdef HAVE_SSL #include #include diff --git a/validator/autotrust.c b/validator/autotrust.c index 3d22637b8..176fa153d 100644 --- a/validator/autotrust.c +++ b/validator/autotrust.c @@ -41,7 +41,6 @@ * It was modified to fit into unbound. The state table process is the same. */ #include "config.h" -#include #include "validator/autotrust.h" #include "validator/val_anchor.h" #include "validator/val_utils.h" @@ -58,6 +57,13 @@ #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 +#include /** 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; irr_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; icount; icount+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; irk.type) == LDNS_RR_TYPE_DNSKEY); + for(i=0; icount; 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; icount; 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); diff --git a/validator/autotrust.h b/validator/autotrust.h index 193135cb6..c5dc3bab9 100644 --- a/validator/autotrust.h +++ b/validator/autotrust.h @@ -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 */ diff --git a/validator/val_anchor.c b/validator/val_anchor.c index e710f2f24..b3a72b2c5 100644 --- a/validator/val_anchor.c +++ b/validator/val_anchor.c @@ -40,8 +40,6 @@ */ #include "config.h" #include -#include -#include #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 #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 */ diff --git a/validator/val_anchor.h b/validator/val_anchor.h index 5a3ad409a..59f754375 100644 --- a/validator/val_anchor.h +++ b/validator/val_anchor.h @@ -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 diff --git a/validator/val_kentry.c b/validator/val_kentry.c index e9144838f..6885e8483 100644 --- a/validator/val_kentry.c +++ b/validator/val_kentry.c @@ -39,13 +39,14 @@ * This file contains functions for dealing with validator key entries. */ #include "config.h" -#include #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) diff --git a/validator/val_neg.c b/validator/val_neg.c index e8d9d56ad..31e1197cd 100644 --- a/validator/val_neg.c +++ b/validator/val_neg.c @@ -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) { diff --git a/validator/val_neg.h b/validator/val_neg.h index ec4f42f6a..deed680fb 100644 --- a/validator/val_neg.h +++ b/validator/val_neg.h @@ -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); diff --git a/validator/val_nsec.c b/validator/val_nsec.c index e377ca4b9..1cec40ac3 100644 --- a/validator/val_nsec.c +++ b/validator/val_nsec.c @@ -41,7 +41,6 @@ * for denial of existance, and proofs for presence of types. */ #include "config.h" -#include #include "validator/val_nsec.h" #include "validator/val_utils.h" #include "util/data/msgreply.h" diff --git a/validator/val_nsec3.c b/validator/val_nsec3.c index 20580c0d7..1167776d8 100644 --- a/validator/val_nsec3.c +++ b/validator/val_nsec3.c @@ -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 diff --git a/validator/val_nsec3.h b/validator/val_nsec3.h index ae4326daf..48cec2bf7 100644 --- a/validator/val_nsec3.h +++ b/validator/val_nsec3.h @@ -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 */ diff --git a/validator/val_secalgo.c b/validator/val_secalgo.c index 92fd0cc4c..c61a22234 100644 --- a/validator/val_secalgo.c +++ b/validator/val_secalgo.c @@ -41,10 +41,12 @@ * and do the library calls (for the crypto library in use). */ #include "config.h" -#include #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" diff --git a/validator/val_secalgo.h b/validator/val_secalgo.h index a5832af87..593b7af4f 100644 --- a/validator/val_secalgo.h +++ b/validator/val_secalgo.h @@ -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); diff --git a/validator/val_sigcrypt.c b/validator/val_sigcrypt.c index 37e1ce14e..4de738a47 100644 --- a/validator/val_sigcrypt.c +++ b/validator/val_sigcrypt.c @@ -41,7 +41,6 @@ * bridging between RR wireformat data and crypto calls. */ #include "config.h" -#include #include "validator/val_sigcrypt.h" #include "validator/val_secalgo.h" #include "validator/validator.h" @@ -52,7 +51,12 @@ #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 #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. diff --git a/validator/val_sigcrypt.h b/validator/val_sigcrypt.h index 9859d3c39..c69706138 100644 --- a/validator/val_sigcrypt.h +++ b/validator/val_sigcrypt.h @@ -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 */ diff --git a/validator/validator.c b/validator/validator.c index ad472cc6a..2184df2f7 100644 --- a/validator/validator.c +++ b/validator/validator.c @@ -40,7 +40,6 @@ * According to RFC 4034. */ #include "config.h" -#include #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; -- 2.47.2