mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-08-17 21:25:50 +02:00
Compare commits
293
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a91e71523 | ||
|
|
313193c6fc | ||
|
|
63c2d6badd | ||
|
|
7323d057e8 | ||
|
|
7d421f1f02 | ||
|
|
a7244fff67 | ||
|
|
c6e121caee | ||
|
|
f417d6e8dc | ||
|
|
7c66e7254a | ||
|
|
0b86905fbc | ||
|
|
127de50bc3 | ||
|
|
c0e89ba331 | ||
|
|
cc21a1ca9a | ||
|
|
919b1ab1b6 | ||
|
|
ad69492495 | ||
|
|
2b2cfd7e4b | ||
|
|
84a3dbe660 | ||
|
|
d7b0d86b09 | ||
|
|
bce5467f59 | ||
|
|
a6ae1d6194 | ||
|
|
0ee5532396 | ||
|
|
7c5182d3fd | ||
|
|
d41f40b028 | ||
|
|
518e7511d7 | ||
|
|
6048ba67fa | ||
|
|
0eddfd7528 | ||
|
|
3ed2f28b76 | ||
|
|
e9277fc201 | ||
|
|
5d5f08e4fd | ||
|
|
a06131872d | ||
|
|
d2892aa5ab | ||
|
|
27c8952a2c | ||
|
|
5b966557cc | ||
|
|
734abf9323 | ||
|
|
2725ad55fc | ||
|
|
f79c387f3f | ||
|
|
2e9785cfb5 | ||
|
|
75c30382ba | ||
|
|
fe44f5918a | ||
|
|
63dc8ffde2 | ||
|
|
2bb408e2aa | ||
|
|
0eb3149af5 | ||
|
|
298e1fd688 | ||
|
|
861483ac82 | ||
|
|
f92d51b3fe | ||
|
|
633daf4bc7 | ||
|
|
b247774236 | ||
|
|
63aa7463e8 | ||
|
|
280352760c | ||
|
|
f8dcdf6e3a | ||
|
|
2885210384 | ||
|
|
253a6e0143 | ||
|
|
90df76f931 | ||
|
|
391504fd03 | ||
|
|
da79cd57d9 | ||
|
|
c8c099960a | ||
|
|
3a84f02606 | ||
|
|
086b257b1d | ||
|
|
f22716c237 | ||
|
|
c74ae3212b | ||
|
|
b40163446e | ||
|
|
ce11690aa1 | ||
|
|
6f49c2fe55 | ||
|
|
63bef95aac | ||
|
|
f768fc1148 | ||
|
|
8e54424abc | ||
|
|
c41d12bb94 | ||
|
|
268ada0d33 | ||
|
|
907ab3d99a | ||
|
|
f12875c910 | ||
|
|
482658b1cc | ||
|
|
75792c34dc | ||
|
|
be0bdf0260 | ||
|
|
08549c7610 | ||
|
|
108539c94c | ||
|
|
a4d4d0fe3a | ||
|
|
9e732da50b | ||
|
|
fe33f7c72c | ||
|
|
631ccb58bf | ||
|
|
189fafa1da | ||
|
|
4260a18fb1 | ||
|
|
79f840acd4 | ||
|
|
fed59bca84 | ||
|
|
aecdb781fc | ||
|
|
bef17e9e7c | ||
|
|
25da698bf1 | ||
|
|
3aea7c2630 | ||
|
|
d4424931f4 | ||
|
|
a5ac86f410 | ||
|
|
aed61e4d8a | ||
|
|
c46e1a1ee8 | ||
|
|
2bfe2d5fe3 | ||
|
|
75bfcb8c91 | ||
|
|
f4049b54c4 | ||
|
|
9fec5d86d3 | ||
|
|
f856eef411 | ||
|
|
24d1ed15c4 | ||
|
|
26c4e7a182 | ||
|
|
8e55996b7c | ||
|
|
2a547a35a7 | ||
|
|
9a60182c86 | ||
|
|
107a915c67 | ||
|
|
41e847df18 | ||
|
|
7ccfb10392 | ||
|
|
d4614cf1ce | ||
|
|
a740dfe195 | ||
|
|
a73089c5f0 | ||
|
|
759f666177 | ||
|
|
e7883b13f4 | ||
|
|
f0015b8919 | ||
|
|
1115d50dce | ||
|
|
dc34bb36b3 | ||
|
|
8f8627a0c3 | ||
|
|
c2f8d43f9d | ||
|
|
6a482dc7f2 | ||
|
|
bc9f482b2a | ||
|
|
8659118a5e | ||
|
|
01db268dff | ||
|
|
6cb2b251c5 | ||
|
|
41e1ffe1c4 | ||
|
|
5a6638fed0 | ||
|
|
fd3293a0ee | ||
|
|
0f7ced491e | ||
|
|
52e48a90ea | ||
|
|
2a5bcffcc2 | ||
|
|
931efbbaa0 | ||
|
|
74468b2edb | ||
|
|
f2ba9e985b | ||
|
|
553ebaf7a9 | ||
|
|
5043992159 | ||
|
|
463bd32b26 | ||
|
|
a81e19a6eb | ||
|
|
db695709e6 | ||
|
|
62e37fe3ee | ||
|
|
c6e92c19b2 | ||
|
|
9865f38f69 | ||
|
|
8959cd47a8 | ||
|
|
c968fc7581 | ||
|
|
cbd9764601 | ||
|
|
9c1f6e2df5 | ||
|
|
e8bcec4529 | ||
|
|
c4392dd54c | ||
|
|
748bfb0b0e | ||
|
|
6510d8f20a | ||
|
|
c7d15770c1 | ||
|
|
48aec18ef7 | ||
|
|
7987b687dc | ||
|
|
b22e1d4273 | ||
|
|
92198b3624 | ||
|
|
facde2ca10 | ||
|
|
d85debfae4 | ||
|
|
db452ffc16 | ||
|
|
26f9ea8942 | ||
|
|
b0b9193603 | ||
|
|
d2bf27acd7 | ||
|
|
149ff1cd5a | ||
|
|
08bf892be6 | ||
|
|
ab316be813 | ||
|
|
5134e8e1ae | ||
|
|
4736eaf80d | ||
|
|
a404373112 | ||
|
|
5f9e30aacb | ||
|
|
7b76e85956 | ||
|
|
cb3044c09d | ||
|
|
009a68a795 | ||
|
|
f52b202747 | ||
|
|
a9ea07cbb3 | ||
|
|
e384cdaf70 | ||
|
|
18a5fb1fc5 | ||
|
|
bf02cdbf5c | ||
|
|
4d473bd618 | ||
|
|
496c91c250 | ||
|
|
91786f4cc6 | ||
|
|
359d9ec426 | ||
|
|
d45774fe03 | ||
|
|
0e11cd160d | ||
|
|
bb67a404fb | ||
|
|
4016aa755e | ||
|
|
b33c39334b | ||
|
|
6fe044de03 | ||
|
|
81fe98956c | ||
|
|
ab143fd1f8 | ||
|
|
eb0deb1301 | ||
|
|
8351afe61a | ||
|
|
edbbacecf9 | ||
|
|
1e5a3fb786 | ||
|
|
7f4a12c652 | ||
|
|
49bb418691 | ||
|
|
2540d6c511 | ||
|
|
fd7af10ff6 | ||
|
|
f304a2a459 | ||
|
|
fceea2bcd5 | ||
|
|
45297772c9 | ||
|
|
a22a3b1669 | ||
|
|
341492391e | ||
|
|
de6d807e3d | ||
|
|
134db23ea8 | ||
|
|
e8a709a315 | ||
|
|
dd9da95c70 | ||
|
|
824ceffedb | ||
|
|
e839035a7a | ||
|
|
3d832f5dca | ||
|
|
459039cf08 | ||
|
|
60470b186e | ||
|
|
c988905aa4 | ||
|
|
af2b300529 | ||
|
|
0e90c03e95 | ||
|
|
f293924be8 | ||
|
|
f9cc9481e2 | ||
|
|
542b812690 | ||
|
|
674fdd5e39 | ||
|
|
c9107bfb1a | ||
|
|
5a62edfc26 | ||
|
|
87fafec48a | ||
|
|
a490e8777f | ||
|
|
3a422ba496 | ||
|
|
6890f55d17 | ||
|
|
b54a0400ab | ||
|
|
a7001366a1 | ||
|
|
a084af819c | ||
|
|
5c9f7c00ba | ||
|
|
cf4ef6fbaf | ||
|
|
9c8fd98719 | ||
|
|
272096d611 | ||
|
|
834a8fc30f | ||
|
|
0f9ae7acd8 | ||
|
|
5605f8d003 | ||
|
|
1b42a51048 | ||
|
|
3f8b0b1cfe | ||
|
|
453df0c66c | ||
|
|
cedeaa8316 | ||
|
|
9ddbb430ef | ||
|
|
568f0699dc | ||
|
|
24aad68487 | ||
|
|
e4aa70b4c5 | ||
|
|
f6371f11a4 | ||
|
|
ce290651d0 | ||
|
|
1d29f79974 | ||
|
|
927af50c81 | ||
|
|
f06b1e8ef3 | ||
|
|
c2b1ad1418 | ||
|
|
9db2d3fa78 | ||
|
|
8a290f6a16 | ||
|
|
016f27739d | ||
|
|
c49a3af953 | ||
|
|
7d07e1b9c3 | ||
|
|
f8719c1aa1 | ||
|
|
448a9f414f | ||
|
|
86723bd032 | ||
|
|
0374d468c8 | ||
|
|
2157540f35 | ||
|
|
749ee526e8 | ||
|
|
b12ae95d1d | ||
|
|
1dd6ef9f24 | ||
|
|
5166d65ea2 | ||
|
|
9ada9f1093 | ||
|
|
d5e4fa21de | ||
|
|
45f95a18af | ||
|
|
8f58908f45 | ||
|
|
bdb519c5c1 | ||
|
|
7726691af9 | ||
|
|
eb5ab1f8e6 | ||
|
|
b2639ba961 | ||
|
|
c3a5bcb8d4 | ||
|
|
ff4f04de2a | ||
|
|
b24aac895f | ||
|
|
188bfacd05 | ||
|
|
4eaa855db9 | ||
|
|
44560e40ea | ||
|
|
1d83bb84ed | ||
|
|
9ebbdbabd3 | ||
|
|
6d8e67e7f9 | ||
|
|
eb1b1e6044 | ||
|
|
d48e17e1dd | ||
|
|
669a20084c | ||
|
|
6b8f7df843 | ||
|
|
37a906991e | ||
|
|
fd3e3ed05b | ||
|
|
ce12d59957 | ||
|
|
c70c747c04 | ||
|
|
6849c1030b | ||
|
|
947bd1ab91 | ||
|
|
c9a1cdec68 | ||
|
|
dba780a00c | ||
|
|
4f8f9f2f74 | ||
|
|
630d9dbc94 | ||
|
|
c3f6bcb89a | ||
|
|
62b02dc911 | ||
|
|
2122b961d3 | ||
|
|
56916e48fb | ||
|
|
ec4878be75 | ||
|
|
ac895c6d35 | ||
|
|
39e8652152 |
+92
-27
@@ -28,12 +28,13 @@ doxygen=@doxygen@
|
||||
libtool=@libtool@
|
||||
ldnsdir=@ldnsdir@
|
||||
staticexe=@staticexe@
|
||||
configfile=@ub_conf_file@
|
||||
|
||||
YACC=@YACC@
|
||||
LEX=@LEX@
|
||||
CC=@CC@
|
||||
CPPFLAGS=-I. @CPPFLAGS@ @DEFS@
|
||||
CFLAGS=-I. @CFLAGS@
|
||||
CPPFLAGS=-I$(srcdir) -I. @CPPFLAGS@ @DEFS@
|
||||
CFLAGS=@CFLAGS@
|
||||
LDFLAGS=@LDFLAGS@
|
||||
LIBS=@LIBS@
|
||||
LIBOBJS=@LIBOBJS@
|
||||
@@ -46,67 +47,109 @@ endif
|
||||
BUILD=build/
|
||||
|
||||
LINT=splint
|
||||
LINTFLAGS=+quiet -weak -warnposix -unrecog -Din_addr_t=uint32_t -Du_int=unsigned -Du_char=uint8_t -preproc -Drlimit=rlimit64
|
||||
LINTFLAGS=+quiet -weak -warnposix -unrecog -Din_addr_t=uint32_t -Du_int=unsigned -Du_char=uint8_t -preproc -Drlimit=rlimit64 -D__gnuc_va_list=va_list
|
||||
# compat with openssl linux edition.
|
||||
LINTFLAGS+="-DBN_ULONG=unsigned long" -Dkrb5_int32=int "-Dkrb5_ui_4=unsigned int" -DPQ_64BIT=uint64_t
|
||||
LINTFLAGS+="-DBN_ULONG=unsigned long" -Dkrb5_int32=int "-Dkrb5_ui_4=unsigned int" -DPQ_64BIT=uint64_t -DRC4_INT=unsigned
|
||||
|
||||
INSTALL=$(srcdir)/install-sh
|
||||
|
||||
COMMON_SRC=$(wildcard services/*.c services/cache/*.c util/*.c \
|
||||
util/data/*.c util/storage/*.c iterator/*.c) util/configparser.c \
|
||||
util/configlexer.c testcode/checklocks.c
|
||||
COMMON_SRC=$(patsubst $(srcdir)/%,%, $(wildcard $(srcdir)/services/*.c \
|
||||
$(srcdir)/services/cache/*.c $(srcdir)/util/*.c \
|
||||
$(srcdir)/util/data/*.c $(srcdir)/util/storage/*.c \
|
||||
$(srcdir)/iterator/*.c $(srcdir)/validator/*.c)) \
|
||||
util/configparser.c util/configlexer.c testcode/checklocks.c
|
||||
COMMON_OBJ=$(addprefix $(BUILD),$(COMMON_SRC:.c=.o))
|
||||
COMPAT_OBJ=$(addprefix $(BUILD)compat/,$(LIBOBJS))
|
||||
UNITTEST_SRC=$(wildcard testcode/unit*.c) testcode/readhex.c $(COMMON_SRC)
|
||||
UNITTEST_SRC=$(patsubst $(srcdir)/%,%, \
|
||||
$(wildcard $(srcdir)/testcode/unit*.c)) \
|
||||
testcode/readhex.c testcode/ldns-testpkts.c checkconf/worker_cb.c \
|
||||
$(COMMON_SRC)
|
||||
UNITTEST_OBJ=$(addprefix $(BUILD),$(UNITTEST_SRC:.c=.o)) $(COMPAT_OBJ)
|
||||
DAEMON_SRC=$(wildcard daemon/*.c) $(COMMON_SRC)
|
||||
DAEMON_SRC=$(patsubst $(srcdir)/%,%, $(wildcard $(srcdir)/daemon/*.c)) \
|
||||
$(COMMON_SRC)
|
||||
DAEMON_OBJ=$(addprefix $(BUILD),$(DAEMON_SRC:.c=.o)) $(COMPAT_OBJ)
|
||||
CHECKCONF_SRC=checkconf/unbound-checkconf.c checkconf/worker_cb.c $(COMMON_SRC)
|
||||
CHECKCONF_OBJ=$(addprefix $(BUILD),$(CHECKCONF_SRC:.c=.o)) $(COMPAT_OBJ)
|
||||
TESTBOUND_SRC=testcode/testbound.c testcode/ldns-testpkts.c \
|
||||
daemon/worker.c daemon/daemon.c daemon/stats.c testcode/replay.c \
|
||||
testcode/fake_event.c $(filter-out util/netevent.c \
|
||||
services/listen_dnsport.c services/outside_network.c, $(COMMON_SRC))
|
||||
TESTBOUND_OBJ=$(addprefix $(BUILD),$(TESTBOUND_SRC:.c=.o)) $(COMPAT_OBJ)
|
||||
LOCKVERIFY_SRC=testcode/lock_verify.c $(COMMON_SRC)
|
||||
LOCKVERIFY_SRC=testcode/lock_verify.c checkconf/worker_cb.c $(COMMON_SRC)
|
||||
LOCKVERIFY_OBJ=$(addprefix $(BUILD),$(LOCKVERIFY_SRC:.c=.o)) $(COMPAT_OBJ)
|
||||
PKTVIEW_SRC=testcode/pktview.c testcode/readhex.c $(COMMON_SRC)
|
||||
PKTVIEW_SRC=testcode/pktview.c testcode/readhex.c checkconf/worker_cb.c \
|
||||
$(COMMON_SRC)
|
||||
PKTVIEW_OBJ=$(addprefix $(BUILD),$(PKTVIEW_SRC:.c=.o)) $(COMPAT_OBJ)
|
||||
SIGNIT_SRC=testcode/signit.c checkconf/worker_cb.c $(COMMON_SRC)
|
||||
SIGNIT_OBJ=$(addprefix $(BUILD),$(SIGNIT_SRC:.c=.o)) $(COMPAT_OBJ)
|
||||
MEMSTATS_SRC=testcode/memstats.c checkconf/worker_cb.c $(COMMON_SRC)
|
||||
MEMSTATS_OBJ=$(addprefix $(BUILD),$(MEMSTATS_SRC:.c=.o)) $(COMPAT_OBJ)
|
||||
ALL_SRC=$(COMMON_SRC) $(UNITTEST_SRC) $(DAEMON_SRC) \
|
||||
$(TESTBOUND_SRC) $(LOCKVERIFY_SRC)
|
||||
$(TESTBOUND_SRC) $(LOCKVERIFY_SRC) $(PKTVIEW_SRC) $(SIGNIT_SRC) \
|
||||
$(MEMSTATS_SRC) $(CHECKCONF_SRC)
|
||||
ALL_OBJ=$(addprefix $(BUILD),$(ALL_SRC:.c=.o) \
|
||||
$(addprefix compat/,$(LIBOBJS))) $(COMPAT_OBJ)
|
||||
|
||||
COMPILE=$(LIBTOOL) --tag=CC --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS)
|
||||
LINK=$(LIBTOOL) --tag=CC --mode=link $(CC) $(staticexe) $(CFLAGS) $(LDFLAGS)
|
||||
LINK=$(LIBTOOL) --tag=CC --mode=link $(CC) $(staticexe) $(RUNTIME_PATH) $(CFLAGS) $(LDFLAGS)
|
||||
LINK_LIB=$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -release $(VERSION)
|
||||
|
||||
.PHONY: clean realclean doc lint all install uninstall tests test download_ldns strip
|
||||
|
||||
$(BUILD)%.o: $(srcdir)/%.c
|
||||
$(INFO) Build $<
|
||||
@if test ! -z "$(ldnsdir)" -a ! -e $(ldnsdir)/include/ldns/ldns.h; \
|
||||
then (cd $(ldnsdir); $(MAKE) copy-headers); fi
|
||||
@if test ! -d $(dir $@); then $(INSTALL) -d $(patsubst %/,%,$(dir $@)); fi
|
||||
$Q$(COMPILE) -c $< -o $@
|
||||
|
||||
.PHONY: clean realclean doc lint all install uninstall
|
||||
all: $(COMMON_OBJ) unbound unbound-checkconf
|
||||
|
||||
all: $(COMMON_OBJ) unbound unittest testbound lock-verify pktview
|
||||
tests: all unittest testbound lock-verify pktview signit memstats
|
||||
|
||||
unbound: $(DAEMON_OBJ)
|
||||
test: tests
|
||||
bash testcode/do-tests.sh
|
||||
|
||||
ifeq ($(patsubst ldns-src%,ldns-src,$(ldnsdir)),ldns-src)
|
||||
ldnslib=$(ldnsdir)/lib/libldns.a
|
||||
$(ldnslib):
|
||||
@if test ! -z "$(ldnsdir)"; \
|
||||
then (cd $(ldnsdir) && $(MAKE)); fi
|
||||
else
|
||||
ldnslib=
|
||||
endif
|
||||
|
||||
unbound: $(DAEMON_OBJ) $(ldnslib)
|
||||
$(INFO) Link $@
|
||||
$Q$(LINK) -o $@ $^ $(LIBS)
|
||||
$Q$(LINK) -o $@ $(sort $(DAEMON_OBJ)) $(LIBS)
|
||||
|
||||
unittest: $(UNITTEST_OBJ)
|
||||
unbound-checkconf: $(CHECKCONF_OBJ) $(ldnslib)
|
||||
$(INFO) Link $@
|
||||
$Q$(LINK) -o $@ $^ $(LIBS)
|
||||
$Q$(LINK) -o $@ $(sort $(CHECKCONF_OBJ)) $(LIBS)
|
||||
|
||||
testbound: $(TESTBOUND_OBJ)
|
||||
unittest: $(UNITTEST_OBJ) $(ldnslib)
|
||||
$(INFO) Link $@
|
||||
$Q$(LINK) -o $@ $^ $(LIBS)
|
||||
$Q$(LINK) -o $@ $(sort $(UNITTEST_OBJ)) $(LIBS)
|
||||
|
||||
lock-verify: $(LOCKVERIFY_OBJ)
|
||||
testbound: $(TESTBOUND_OBJ) $(ldnslib)
|
||||
$(INFO) Link $@
|
||||
$Q$(LINK) -o $@ $^ $(LIBS)
|
||||
$Q$(LINK) -o $@ $(sort $(TESTBOUND_OBJ)) $(LIBS)
|
||||
|
||||
pktview: $(PKTVIEW_OBJ)
|
||||
lock-verify: $(LOCKVERIFY_OBJ) $(ldnslib)
|
||||
$(INFO) Link $@
|
||||
$Q$(LINK) -o $@ $^ $(LIBS)
|
||||
$Q$(LINK) -o $@ $(sort $(LOCKVERIFY_OBJ)) $(LIBS)
|
||||
|
||||
pktview: $(PKTVIEW_OBJ) $(ldnslib)
|
||||
$(INFO) Link $@
|
||||
$Q$(LINK) -o $@ $(sort $(PKTVIEW_OBJ)) $(LIBS)
|
||||
|
||||
signit: $(SIGNIT_OBJ) $(ldnslib)
|
||||
$(INFO) Link $@
|
||||
$Q$(LINK) -o $@ $(sort $(SIGNIT_OBJ)) $(LIBS)
|
||||
|
||||
memstats: $(MEMSTATS_OBJ) $(ldnslib)
|
||||
$(INFO) Link $@
|
||||
$Q$(LINK) -o $@ $(sort $(MEMSTATS_OBJ)) $(LIBS)
|
||||
|
||||
#testcode/ldns-testpkts.c: $(ldnsdir)/examples/ldns-testpkts.c \
|
||||
# $(ldnsdir)/examples/ldns-testpkts.h
|
||||
@@ -116,9 +159,13 @@ pktview: $(PKTVIEW_OBJ)
|
||||
util/config_file.c: util/configparser.h
|
||||
util/configlexer.c: $(srcdir)/util/configlexer.lex util/configparser.h
|
||||
$(INFO) Lex $<
|
||||
ifeq "$(strip $(LEX))" ":"
|
||||
$Qecho "rebuild lexer, but no lex program, skipped"
|
||||
else
|
||||
@if test ! -d util; then $(INSTALL) -d util; fi
|
||||
$Qecho "#include \"util/configyyrename.h\"" > $@
|
||||
$Q$(LEX) -t $< >> $@
|
||||
endif
|
||||
|
||||
util/configparser.c util/configparser.h: $(srcdir)/util/configparser.y
|
||||
$(INFO) Yacc $<
|
||||
@@ -133,6 +180,7 @@ realclean: clean
|
||||
rm -f config.status config.log config.h.in config.h
|
||||
rm -f configure config.sub config.guess ltmain.sh aclocal.m4 libtool
|
||||
rm -f util/configlexer.c util/configparser.c util/configparser.h
|
||||
if test -d ldns-src; then rm -rf ldns-src; fi
|
||||
rm -f Makefile
|
||||
|
||||
$(BUILD)%.lint: $(srcdir)/%.c
|
||||
@@ -151,22 +199,39 @@ ifdef doxygen
|
||||
$(doxygen) $(srcdir)/doc/unbound.doxygen
|
||||
endif
|
||||
|
||||
strip:
|
||||
strip unbound
|
||||
strip unbound-checkconf
|
||||
|
||||
install:
|
||||
$(INSTALL) -d $(bindir)
|
||||
$(INSTALL) -d $(mandir)
|
||||
$(INSTALL) -d $(mandir)/man8
|
||||
$(INSTALL) -d $(mandir)/man5
|
||||
$(LIBTOOL) --mode=install cp unbound $(bindir)/unbound
|
||||
$(LIBTOOL) --mode=install cp unbound-checkconf $(bindir)/unbound-checkconf
|
||||
$(INSTALL) -c -m 644 $(srcdir)/doc/unbound.8 $(mandir)/man8
|
||||
$(INSTALL) -c -m 644 $(srcdir)/doc/unbound-checkconf.8 $(mandir)/man8
|
||||
$(INSTALL) -c -m 644 $(srcdir)/doc/unbound.conf.5 $(mandir)/man5
|
||||
if test ! -e $(configfile); then $(INSTALL) -d `dirname $(configfile)`; $(INSTALL) -c -m 644 $(srcdir)/doc/example.conf $(configfile); fi
|
||||
|
||||
uninstall:
|
||||
rm -f -- $(bindir)/unbound
|
||||
rm -f -- $(mandir)/man8/unbound.8 $(mandir)/man5/unbound.conf.5
|
||||
rm -f -- $(bindir)/unbound $(bindir)/unbound-checkconf
|
||||
rm -f -- $(mandir)/man8/unbound.8 $(mandir)/man8/unbound-checkconf.8 $(mandir)/man5/unbound.conf.5
|
||||
@echo
|
||||
@echo "You still need to remove `dirname $(configfile)` , $(configfile) by hand"
|
||||
|
||||
download_ldns:
|
||||
svn export https://www.nlnetlabs.nl/ldns/svn/trunk/makedist.sh ldns_makedist.sh
|
||||
./ldns_makedist.sh -s -d https://www.nlnetlabs.nl/ldns/svn/trunk
|
||||
mv ldns-*_pre_*.tar.gz ldns-src.tar.gz
|
||||
rm ldns-*_pre_*.tar.gz.sha1 ldns_makedist.sh
|
||||
|
||||
# Automatic dependencies.
|
||||
$(BUILD)%.d: $(srcdir)/%.c
|
||||
$(INFO) Depend $<
|
||||
@if test ! -z "$(ldnsdir)" -a ! -e $(ldnsdir)/include/ldns/ldns.h; \
|
||||
then (cd $(ldnsdir); $(MAKE) copy-headers); fi
|
||||
@if test ! -d $(dir $@); then $(INSTALL) -d $(patsubst %/,%,$(dir $@)); fi
|
||||
$Q$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $(CFLAGS) $< \
|
||||
| sed '\''s!\(.*\)\.o[ :]*!$(dir $@)\1.o $@ : !g'\'' > $@; \
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
Unbound README
|
||||
* ./configure && make && make install
|
||||
* on BSDs and Solaris use gmake (GNU make).
|
||||
* If it complains that no libevent can be found; libevent is useful when
|
||||
using many (10000) outgoing ports. By default 16 ports are used and the
|
||||
builtin alternative is equally capable.
|
||||
* More detailed README, README.svn, README.tests in doc directory
|
||||
* manual pages can be found in doc directory, and are installed, unbound(8).
|
||||
* example configuration file doc/example.conf
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* checkconf/unbound-checkconf.c - config file checker for unbound.conf file.
|
||||
*
|
||||
* Copyright (c) 2007, 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
|
||||
*
|
||||
* The config checker checks for syntax and other errors in the unbound.conf
|
||||
* file, and can be used to check for errors before the server is started
|
||||
* or sigHUPped.
|
||||
* Exit status 1 means an error.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "util/log.h"
|
||||
#include "util/config_file.h"
|
||||
#include "util/module.h"
|
||||
#include "util/net_help.h"
|
||||
#include "util/regional.h"
|
||||
#include "iterator/iterator.h"
|
||||
#include "validator/validator.h"
|
||||
#include <pwd.h>
|
||||
|
||||
/** Give checkconf usage, and exit (1). */
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
printf("Usage: unbound-checkconf [file]\n");
|
||||
printf(" Checks unbound configuration file for errors.\n");
|
||||
printf("file if omitted %s is used.\n", CONFIGFILE);
|
||||
printf("-h show this usage help.\n");
|
||||
printf("Version %s\n", PACKAGE_VERSION);
|
||||
printf("BSD licensed, see LICENSE in source package for details.\n");
|
||||
printf("Report bugs to %s\n", PACKAGE_BUGREPORT);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/** check if module works with config */
|
||||
static void
|
||||
check_mod(struct config_file* cfg, struct module_func_block* fb)
|
||||
{
|
||||
struct module_env env;
|
||||
memset(&env, 0, sizeof(env));
|
||||
env.cfg = cfg;
|
||||
env.scratch = regional_create();
|
||||
env.scratch_buffer = ldns_buffer_new(BUFSIZ);
|
||||
if(!env.scratch || !env.scratch_buffer)
|
||||
fatal_exit("out of memory");
|
||||
if(!(*fb->init)(&env, 0)) {
|
||||
fatal_exit("bad config for %s module", fb->name);
|
||||
}
|
||||
(*fb->deinit)(&env, 0);
|
||||
ldns_buffer_free(env.scratch_buffer);
|
||||
regional_destroy(env.scratch);
|
||||
}
|
||||
|
||||
/** check configuration for errors */
|
||||
static void
|
||||
morechecks(struct config_file* cfg)
|
||||
{
|
||||
int i;
|
||||
struct sockaddr_storage a;
|
||||
socklen_t alen;
|
||||
for(i=0; i<cfg->num_ifs; i++) {
|
||||
if(!ipstrtoaddr(cfg->ifs[i], UNBOUND_DNS_PORT, &a, &alen)) {
|
||||
fatal_exit("cannot parse interface specified as '%s'",
|
||||
cfg->ifs[i]);
|
||||
}
|
||||
}
|
||||
for(i=0; i<cfg->num_out_ifs; i++) {
|
||||
if(!ipstrtoaddr(cfg->out_ifs[i], UNBOUND_DNS_PORT,
|
||||
&a, &alen)) {
|
||||
fatal_exit("cannot parse outgoing-interface "
|
||||
"specified as '%s'", cfg->out_ifs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if(cfg->verbosity < 0)
|
||||
fatal_exit("verbosity value < 0");
|
||||
if(cfg->num_threads < 0 || cfg->num_threads > 10000)
|
||||
fatal_exit("num_threads value weird");
|
||||
if(!cfg->do_ip4 && !cfg->do_ip6)
|
||||
fatal_exit("ip4 and ip6 are both disabled, pointless");
|
||||
if(!cfg->do_udp && !cfg->do_tcp)
|
||||
fatal_exit("udp and tcp are both disabled, pointless");
|
||||
|
||||
if(cfg->chrootdir && strncmp(cfg->chrootdir, cfg->directory,
|
||||
strlen(cfg->chrootdir)) != 0)
|
||||
fatal_exit("working directory %s not in chrootdir %s",
|
||||
cfg->directory, cfg->chrootdir);
|
||||
if(cfg->chrootdir && cfg->pidfile && cfg->pidfile[0] &&
|
||||
strncmp(cfg->chrootdir, cfg->pidfile,
|
||||
strlen(cfg->chrootdir)) != 0)
|
||||
fatal_exit("pid file %s not in chrootdir %s",
|
||||
cfg->pidfile, cfg->chrootdir);
|
||||
if(cfg->chrootdir && cfg->logfile && cfg->logfile[0] &&
|
||||
strncmp(cfg->chrootdir, cfg->logfile,
|
||||
strlen(cfg->chrootdir)) != 0)
|
||||
fatal_exit("log file %s not in chrootdir %s",
|
||||
cfg->logfile, cfg->chrootdir);
|
||||
|
||||
if(strcmp(cfg->module_conf, "iterator") != 0 &&
|
||||
strcmp(cfg->module_conf, "validator iterator") != 0) {
|
||||
fatal_exit("module conf %s is not known to work",
|
||||
cfg->module_conf);
|
||||
}
|
||||
|
||||
if(cfg->username && cfg->username[0]) {
|
||||
struct passwd *pwd;
|
||||
if((pwd = getpwnam(cfg->username)) == NULL)
|
||||
fatal_exit("user '%s' does not exist.", cfg->username);
|
||||
endpwent();
|
||||
}
|
||||
}
|
||||
|
||||
/** check config file */
|
||||
static void
|
||||
checkconf(char* cfgfile)
|
||||
{
|
||||
struct config_file* cfg = config_create();
|
||||
if(!cfg)
|
||||
fatal_exit("out of memory");
|
||||
if(!config_read(cfg, cfgfile)) {
|
||||
/* config_read prints messages to stderr */
|
||||
config_delete(cfg);
|
||||
exit(1);
|
||||
}
|
||||
morechecks(cfg);
|
||||
check_mod(cfg, iter_get_funcblock());
|
||||
check_mod(cfg, val_get_funcblock());
|
||||
config_delete(cfg);
|
||||
printf("unbound-checkconf: no errors in %s\n", cfgfile);
|
||||
}
|
||||
|
||||
/** 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 routine for checkconf */
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int c;
|
||||
char* f;
|
||||
log_ident_set("unbound-checkconf");
|
||||
log_init(NULL, 0, NULL);
|
||||
checklock_start();
|
||||
/* parse the options */
|
||||
while( (c=getopt(argc, argv, "h")) != -1) {
|
||||
switch(c) {
|
||||
case '?':
|
||||
case 'h':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if(argc != 0 && argc != 1)
|
||||
usage();
|
||||
if(argc == 1)
|
||||
f = argv[0];
|
||||
else f = CONFIGFILE;
|
||||
checkconf(f);
|
||||
checklock_stop();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* checkconf/worker_cb.c - fake callback routines to make fptr_wlist work
|
||||
*
|
||||
* Copyright (c) 2007, 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 file contains fake callback functions, so that the symbols exist
|
||||
* and the fptr_wlist continues to work even if the daemon/worker is not
|
||||
* linked into the resulting program.
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "util/log.h"
|
||||
struct comm_reply;
|
||||
struct comm_point;
|
||||
struct module_qstate;
|
||||
|
||||
int worker_handle_control_cmd(struct comm_point* ATTR_UNUSED(c),
|
||||
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
||||
struct comm_reply* ATTR_UNUSED(reply_info))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int worker_handle_request(struct comm_point* ATTR_UNUSED(c),
|
||||
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
||||
struct comm_reply* ATTR_UNUSED(repinfo))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int worker_handle_reply(struct comm_point* ATTR_UNUSED(c),
|
||||
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
||||
struct comm_reply* ATTR_UNUSED(reply_info))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int worker_handle_service_reply(struct comm_point* ATTR_UNUSED(c),
|
||||
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
||||
struct comm_reply* ATTR_UNUSED(reply_info))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void worker_sighandler(int ATTR_UNUSED(sig), void* ATTR_UNUSED(arg))
|
||||
{
|
||||
log_assert(0);
|
||||
}
|
||||
|
||||
int worker_send_packet(ldns_buffer* ATTR_UNUSED(pkt),
|
||||
struct sockaddr_storage* ATTR_UNUSED(addr),
|
||||
socklen_t ATTR_UNUSED(addrlen), int ATTR_UNUSED(timeout),
|
||||
struct module_qstate* ATTR_UNUSED(q), int ATTR_UNUSED(use_tcp))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct outbound_entry* worker_send_query(uint8_t* ATTR_UNUSED(qname),
|
||||
size_t ATTR_UNUSED(qnamelen), uint16_t ATTR_UNUSED(qtype),
|
||||
uint16_t ATTR_UNUSED(qclass), uint16_t ATTR_UNUSED(flags),
|
||||
int ATTR_UNUSED(dnssec), struct sockaddr_storage* ATTR_UNUSED(addr),
|
||||
socklen_t ATTR_UNUSED(addrlen), struct module_qstate* ATTR_UNUSED(q))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
worker_alloc_cleanup(void* ATTR_UNUSED(arg))
|
||||
{
|
||||
log_assert(0);
|
||||
}
|
||||
+1500
File diff suppressed because it is too large
Load Diff
+426
@@ -0,0 +1,426 @@
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Pathname to the Unbound configuration file */
|
||||
#undef CONFIGFILE
|
||||
|
||||
/* Define if you want to use debug lock checking (slow). */
|
||||
#undef ENABLE_LOCK_CHECKS
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#undef HAVE_ARPA_INET_H
|
||||
|
||||
/* Whether the C compiler accepts the "format" attribute */
|
||||
#undef HAVE_ATTR_FORMAT
|
||||
|
||||
/* Whether the C compiler accepts the "unused" attribute */
|
||||
#undef HAVE_ATTR_UNUSED
|
||||
|
||||
/* Define to 1 if your system has a working `chown' function. */
|
||||
#undef HAVE_CHOWN
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have the `event_base_free' function. */
|
||||
#undef HAVE_EVENT_BASE_FREE
|
||||
|
||||
/* Define to 1 if you have the `event_base_once' function. */
|
||||
#undef HAVE_EVENT_BASE_ONCE
|
||||
|
||||
/* Define to 1 if you have the <event.h> header file. */
|
||||
#undef HAVE_EVENT_H
|
||||
|
||||
/* Define to 1 if you have the `fork' function. */
|
||||
#undef HAVE_FORK
|
||||
|
||||
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
|
||||
#undef HAVE_FSEEKO
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
#undef HAVE_GETADDRINFO
|
||||
|
||||
/* Define to 1 if you have the <getopt.h> header file. */
|
||||
#undef HAVE_GETOPT_H
|
||||
|
||||
/* Define to 1 if you have the `inet_aton' function. */
|
||||
#undef HAVE_INET_ATON
|
||||
|
||||
/* Define to 1 if you have the `inet_ntop' function. */
|
||||
#undef HAVE_INET_NTOP
|
||||
|
||||
/* Define to 1 if you have the `inet_pton' function. */
|
||||
#undef HAVE_INET_PTON
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||
#undef HAVE_LIBCRYPTO
|
||||
|
||||
/* Define to 1 if you have the `nsl' library (-lnsl). */
|
||||
#undef HAVE_LIBNSL
|
||||
|
||||
/* Define to 1 if you have the `rt' library (-lrt). */
|
||||
#undef HAVE_LIBRT
|
||||
|
||||
/* Define to 1 if you have the `socket' library (-lsocket). */
|
||||
#undef HAVE_LIBSOCKET
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#undef HAVE_MALLOC
|
||||
|
||||
/* Define to 1 if you have the `memmove' function. */
|
||||
#undef HAVE_MEMMOVE
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#undef HAVE_NETINET_IN_H
|
||||
|
||||
/* Define to 1 if you have the <openssl/err.h> header file. */
|
||||
#undef HAVE_OPENSSL_ERR_H
|
||||
|
||||
/* Define to 1 if you have the <openssl/ssl.h> header file. */
|
||||
#undef HAVE_OPENSSL_SSL_H
|
||||
|
||||
/* Define if you have POSIX threads libraries and header files. */
|
||||
#undef HAVE_PTHREAD
|
||||
|
||||
/* Define to 1 if the system has the type `pthread_rwlock_t'. */
|
||||
#undef HAVE_PTHREAD_RWLOCK_T
|
||||
|
||||
/* Define to 1 if the system has the type `pthread_spinlock_t'. */
|
||||
#undef HAVE_PTHREAD_SPINLOCK_T
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#undef HAVE_SNPRINTF
|
||||
|
||||
/* Using Solaris threads */
|
||||
#undef HAVE_SOLARIS_THREADS
|
||||
|
||||
/* Define if you have the SSL libraries installed. */
|
||||
#undef HAVE_SSL
|
||||
|
||||
/* Define to 1 if you have the <stdarg.h> header file. */
|
||||
#undef HAVE_STDARG_H
|
||||
|
||||
/* Define to 1 if you have the <stdbool.h> header file. */
|
||||
#undef HAVE_STDBOOL_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the `strlcpy' function. */
|
||||
#undef HAVE_STRLCPY
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
#undef HAVE_SYSLOG_H
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#undef HAVE_SYS_PARAM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#undef HAVE_SYS_SOCKET_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <sys/uio.h> header file. */
|
||||
#undef HAVE_SYS_UIO_H
|
||||
|
||||
/* Define to 1 if you have the <time.h> header file. */
|
||||
#undef HAVE_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define to 1 if you have the `vfork' function. */
|
||||
#undef HAVE_VFORK
|
||||
|
||||
/* Define to 1 if you have the <vfork.h> header file. */
|
||||
#undef HAVE_VFORK_H
|
||||
|
||||
/* Define to 1 if `fork' works. */
|
||||
#undef HAVE_WORKING_FORK
|
||||
|
||||
/* Define to 1 if `vfork' works. */
|
||||
#undef HAVE_WORKING_VFORK
|
||||
|
||||
/* Define to the maximum message length to pass to syslog. */
|
||||
#undef MAXSYSLOGMSGLEN
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define to necessary symbol if this constant uses a non-standard name on
|
||||
your system. */
|
||||
#undef PTHREAD_CREATE_JOINABLE
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define to 'int' or type of struct msghdr.msg_iovlen. */
|
||||
#undef TYPE_MSGIOVLEN
|
||||
|
||||
/* use statistics for allocs and frees, for debug use */
|
||||
#undef UNBOUND_ALLOC_STATS
|
||||
|
||||
/* Define if you want to use internal select based events */
|
||||
#undef USE_MINI_EVENT
|
||||
|
||||
/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
|
||||
`char[]'. */
|
||||
#undef YYTEXT_POINTER
|
||||
|
||||
/* Define to 1 if on AIX 3.
|
||||
System headers sometimes define this.
|
||||
We just want to avoid a redefinition error message. */
|
||||
#ifndef _ALL_SOURCE
|
||||
# undef _ALL_SOURCE
|
||||
#endif
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
#undef _FILE_OFFSET_BITS
|
||||
|
||||
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
|
||||
#undef _LARGEFILE_SOURCE
|
||||
|
||||
/* Define for large files, on AIX-style hosts. */
|
||||
#undef _LARGE_FILES
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
#undef const
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef gid_t
|
||||
|
||||
/* in_addr_t */
|
||||
#undef in_addr_t
|
||||
|
||||
/* in_port_t */
|
||||
#undef in_port_t
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
|
||||
/* Define to `short' if <sys/types.h> does not define. */
|
||||
#undef int16_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef int32_t
|
||||
|
||||
/* Define to `long long' if <sys/types.h> does not define. */
|
||||
#undef int64_t
|
||||
|
||||
/* Define to `char' if <sys/types.h> does not define. */
|
||||
#undef int8_t
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
#undef malloc
|
||||
|
||||
/* Define to `long int' if <sys/types.h> does not define. */
|
||||
#undef off_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef pid_t
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
|
||||
/* Define to 'int' if not defined */
|
||||
#undef socklen_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef ssize_t
|
||||
|
||||
/* Define to `unsigned char' if <sys/types.h> does not define. */
|
||||
#undef u_char
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef uid_t
|
||||
|
||||
/* Define to `unsigned short' if <sys/types.h> does not define. */
|
||||
#undef uint16_t
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef uint32_t
|
||||
|
||||
/* Define to `unsigned long long' if <sys/types.h> does not define. */
|
||||
#undef uint64_t
|
||||
|
||||
/* Define to `unsigned char' if <sys/types.h> does not define. */
|
||||
#undef uint8_t
|
||||
|
||||
/* Define as `fork' if `vfork' does not work. */
|
||||
#undef vfork
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#if STDC_HEADERS
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_UIO_H
|
||||
#include <sys/uio.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENSSL_ERR_H
|
||||
#include <openssl/err.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ATTR_FORMAT
|
||||
# define ATTR_FORMAT(archetype, string_index, first_to_check) \
|
||||
__attribute__ ((format (archetype, string_index, first_to_check)))
|
||||
#else /* !HAVE_ATTR_FORMAT */
|
||||
# define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */
|
||||
#endif /* !HAVE_ATTR_FORMAT */
|
||||
#if defined(DOXYGEN)
|
||||
# define ATTR_UNUSED(x) x
|
||||
#elif defined(__cplusplus)
|
||||
# define ATTR_UNUSED(x)
|
||||
#elif defined(HAVE_ATTR_UNUSED)
|
||||
# define ATTR_UNUSED(x) x __attribute__((unused))
|
||||
#else /* !HAVE_ATTR_UNUSED */
|
||||
# define ATTR_UNUSED(x) x
|
||||
#endif /* !HAVE_ATTR_UNUSED */
|
||||
#ifndef HAVE_FSEEKO
|
||||
#define fseeko fseek
|
||||
#define ftello ftell
|
||||
#endif /* HAVE_FSEEKO */
|
||||
#if defined(HAVE_EVENT_H) && !defined(HAVE_EVENT_BASE_ONCE) && (defined(HAVE_PTHREAD) || defined(HAVE_SOLARIS_THREADS))
|
||||
/* using version of libevent that is not threadsafe. */
|
||||
# define LIBEVENT_SIGNAL_PROBLEM 1
|
||||
#endif
|
||||
|
||||
#ifndef RAND_MAX
|
||||
#define RAND_MAX 2147483647
|
||||
#endif
|
||||
|
||||
#ifndef IPV6_MIN_MTU
|
||||
#define IPV6_MIN_MTU 1280
|
||||
#endif /* IPV6_MIN_MTU */
|
||||
|
||||
#ifndef CHECKED_INET6
|
||||
# define CHECKED_INET6
|
||||
# ifdef AF_INET6
|
||||
# define INET6
|
||||
# else
|
||||
# define AF_INET6 28
|
||||
# endif
|
||||
#endif /* CHECKED_INET6 */
|
||||
|
||||
/* maximum nesting of included files */
|
||||
#define MAXINCLUDES 10
|
||||
|
||||
#ifndef HAVE_SNPRINTF
|
||||
#include <stdarg.h>
|
||||
int snprintf (char *str, size_t count, const char *fmt, ...);
|
||||
int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
|
||||
#endif /* HAVE_SNPRINTF */
|
||||
#ifndef HAVE_INET_PTON
|
||||
int inet_pton(int af, const char* src, void* dst);
|
||||
#endif /* HAVE_INET_PTON */
|
||||
#ifndef HAVE_INET_NTOP
|
||||
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
|
||||
#endif
|
||||
#ifndef HAVE_INET_ATON
|
||||
int inet_aton(const char *cp, struct in_addr *addr);
|
||||
#endif
|
||||
#ifndef HAVE_MEMMOVE
|
||||
void *memmove(void *dest, const void *src, size_t n);
|
||||
#endif
|
||||
#ifndef HAVE_STRLCPY
|
||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
#endif
|
||||
#ifndef HAVE_GETADDRINFO
|
||||
struct sockaddr_storage;
|
||||
#include "compat/fake-rfc2553.h"
|
||||
#endif
|
||||
|
||||
#include "ldns/ldns.h"
|
||||
|
||||
#ifdef UNBOUND_ALLOC_STATS
|
||||
# define malloc(s) unbound_stat_malloc_log(s, __FILE__, __LINE__, __func__)
|
||||
# define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
|
||||
# define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
|
||||
# define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
|
||||
void *unbound_stat_malloc(size_t size);
|
||||
void *unbound_stat_calloc(size_t nmemb, size_t size);
|
||||
void unbound_stat_free(void *ptr);
|
||||
void *unbound_stat_realloc(void *ptr, size_t size);
|
||||
void *unbound_stat_malloc_log(size_t size, const char* file, int line,
|
||||
const char* func);
|
||||
void *unbound_stat_calloc_log(size_t nmemb, size_t size, const char* file,
|
||||
int line, const char* func);
|
||||
void unbound_stat_free_log(void *ptr, const char* file, int line,
|
||||
const char* func);
|
||||
void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
|
||||
int line, const char* func);
|
||||
#endif /* UNBOUND_ALLOC_STATS */
|
||||
|
||||
/** default port for DNS traffic. */
|
||||
#define UNBOUND_DNS_PORT 53
|
||||
|
||||
+1616
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+151
-26
@@ -2,11 +2,40 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
AC_PREREQ(2.57)
|
||||
|
||||
AC_INIT(unbound, 0.4, wouter@nlnetlabs.nl, unbound)
|
||||
AC_INIT(unbound, 0.7.2, unbound-bugs@nlnetlabs.nl, unbound)
|
||||
|
||||
CFLAGS=
|
||||
AC_AIX
|
||||
|
||||
dnl
|
||||
dnl By default set $sysconfdir to /etc and $localstatedir to /var
|
||||
dnl
|
||||
case "$prefix" in
|
||||
NONE)
|
||||
case "$sysconfdir" in
|
||||
'${prefix}/etc')
|
||||
sysconfdir=/etc
|
||||
;;
|
||||
esac
|
||||
case "$localstatedir" in
|
||||
'${prefix}/var')
|
||||
localstatedir=/var
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# Determine configuration file
|
||||
ub_conf_file=${sysconfdir}/unbound/unbound.conf
|
||||
AC_ARG_WITH([conf_file],
|
||||
AC_HELP_STRING([--with-conf-file=path], [Pathname to the Unbound configuration file]),
|
||||
[ub_conf_file=$withval])
|
||||
AC_SUBST(ub_conf_file)
|
||||
# the eval is to evaluate shell expansion twice, once
|
||||
# for $nsd_conf_file and once for the ${prefix} within it.
|
||||
AC_DEFINE_UNQUOTED(CONFIGFILE, ["`eval echo $ub_conf_file`"], [Pathname to the Unbound configuration file])
|
||||
|
||||
dnl routine to help check for compiler flags.
|
||||
AC_DEFUN([CHECK_COMPILER_FLAG],
|
||||
[
|
||||
@@ -251,6 +280,15 @@ if test "$srcdir" != "."; then
|
||||
CPPFLAGS="$CPPFLAGS -I$srcdir";
|
||||
fi
|
||||
|
||||
# skip these tests, we do not need them.
|
||||
AC_DEFUN([AC_PROG_F77], [:])
|
||||
AC_DEFUN([AC_PROG_FC], [:])
|
||||
AC_DEFUN([AC_PROG_CXX], [:])
|
||||
AC_DEFUN([AC_PROG_CXXCPP], [:])
|
||||
AC_DEFUN([AC_PROG_OBJC], [:])
|
||||
AC_DEFUN([AC_PROG_OBJCCPP], [:])
|
||||
AC_DEFUN([AC_LIBTOOL_CXX], [:])
|
||||
AC_DEFUN([AC_LIBTOOL_F77], [:])
|
||||
# Use libtool
|
||||
AC_CHECK_PROGS(libtool, [glibtool libtool15 libtool], [./libtool])
|
||||
AC_PATH_TOOL(AR, ar, [false])
|
||||
@@ -269,7 +307,7 @@ AC_PROG_LIBTOOL
|
||||
|
||||
# Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([stdarg.h stdbool.h netinet/in.h sys/param.h sys/socket.h sys/uio.h arpa/inet.h],,, [AC_INCLUDES_DEFAULT])
|
||||
AC_CHECK_HEADERS([stdarg.h stdbool.h netinet/in.h sys/param.h sys/socket.h sys/uio.h arpa/inet.h syslog.h],,, [AC_INCLUDES_DEFAULT])
|
||||
|
||||
# check for types
|
||||
AC_CHECK_TYPE(int8_t, char)
|
||||
@@ -356,17 +394,23 @@ fi
|
||||
|
||||
CHECK_YYUNPUT
|
||||
|
||||
# add option to disable the evil rpath
|
||||
dnl Check whether to use rpath or not
|
||||
AC_ARG_ENABLE(rpath,
|
||||
[ --disable-rpath disable hardcoded rpath (default=enabled)],
|
||||
enable_rpath=$enableval, enable_rpath=yes)
|
||||
|
||||
# Checks for libraries.
|
||||
AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname],
|
||||
[enable SSL (will check /usr/local/ssl
|
||||
/usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr/sfw /usr)]),[
|
||||
/usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr)]),[
|
||||
],[
|
||||
withval="yes"
|
||||
])
|
||||
if test x_$withval != x_no; then
|
||||
AC_MSG_CHECKING(for SSL)
|
||||
if test x_$withval = x_ -o x_$withval = x_yes; then
|
||||
withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr/sfw /usr"
|
||||
withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /opt/local /usr/sfw /usr"
|
||||
fi
|
||||
for dir in $withval; do
|
||||
ssldir="$dir"
|
||||
@@ -383,7 +427,9 @@ AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname],
|
||||
AC_MSG_RESULT(found in $ssldir)
|
||||
HAVE_SSL=yes
|
||||
LDFLAGS="$LDFLAGS -L$ssldir/lib";
|
||||
RUNTIME_PATH="$RUNTIME_PATH -R$ssldir/lib"
|
||||
if test "x$enable_rpath" = xyes; then
|
||||
RUNTIME_PATH="$RUNTIME_PATH -R$ssldir/lib"
|
||||
fi
|
||||
AC_CHECK_LIB(crypto, HMAC_CTX_init,, [
|
||||
AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required])
|
||||
])
|
||||
@@ -392,10 +438,11 @@ AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname],
|
||||
AC_SUBST(RUNTIME_PATH)
|
||||
fi
|
||||
AC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT])
|
||||
AC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT])
|
||||
|
||||
# check for thread library.
|
||||
AC_ARG_WITH(pthreads, AC_HELP_STRING([--with-pthreads],
|
||||
[use pthreads library, or --without--pthreads to disable threading support.]),
|
||||
[use pthreads library, or --without-pthreads to disable threading support.]),
|
||||
[ ],[ withval="yes" ])
|
||||
ub_have_pthreads=no
|
||||
if test x_$withval != x_no; then
|
||||
@@ -406,7 +453,7 @@ if test x_$withval != x_no; then
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
||||
CC="$PTHREAD_CC"
|
||||
ub_have_pthreads=yes
|
||||
AC_CHECK_TYPES(pthread_spinlock_t,,,[#include <pthread.h>])
|
||||
AC_CHECK_TYPES([pthread_spinlock_t, pthread_rwlock_t],,,[#include <pthread.h>])
|
||||
])
|
||||
fi
|
||||
|
||||
@@ -429,14 +476,16 @@ if test x_$withval != x_no; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# check for library used by libevent after 1.3c
|
||||
AC_CHECK_LIB(rt, clock_gettime)
|
||||
# check for libevent
|
||||
AC_ARG_WITH(libevent, AC_HELP_STRING([--with-libevent=pathname],
|
||||
[set path to libevent (will check /usr/local /usr/lib /usr/pkg /usr/sfw /usr)]),
|
||||
[set path to libevent (will check /usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr)]),
|
||||
[ ],[ withval="yes" ])
|
||||
if test x_$withval != x_no; then
|
||||
AC_MSG_CHECKING(for libevent)
|
||||
if test x_$withval = x_ -o x_$withval = x_yes; then
|
||||
withval="/usr/local /usr/lib /usr/pkg /usr/sfw /usr";
|
||||
withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr";
|
||||
fi
|
||||
for dir in $withval; do
|
||||
thedir="$dir"
|
||||
@@ -453,12 +502,17 @@ if test x_$withval != x_no; then
|
||||
CPPFLAGS="$CPPFLAGS -I$thedir";
|
||||
LDFLAGS="$thedir/.libs/*.o $LDFLAGS";
|
||||
else
|
||||
AC_MSG_ERROR(Cannot find the libevent library in $withval)
|
||||
AC_MSG_ERROR([Cannot find the libevent library in $withval
|
||||
You can restart ./configure --with-libevent=no to use a builtin alternative.
|
||||
Please note that this alternative is not as capable as libevent when using
|
||||
many outgoing ports. ])
|
||||
fi
|
||||
else
|
||||
AC_MSG_RESULT(found in $thedir)
|
||||
LDFLAGS="$LDFLAGS -L$thedir/lib";
|
||||
RUNTIME_PATH="$RUNTIME_PATH -R$thedir/lib"
|
||||
if test "x$enable_rpath" = xyes; then
|
||||
RUNTIME_PATH="$RUNTIME_PATH -R$thedir/lib"
|
||||
fi
|
||||
fi
|
||||
AC_SUBST(RUNTIME_PATH)
|
||||
AC_SEARCH_LIBS(event_set, [event])
|
||||
@@ -479,29 +533,34 @@ if test x_$enable_static_exe = x_yes; then
|
||||
staticexe="-static"
|
||||
fi
|
||||
|
||||
# set lock checking if requested
|
||||
AC_ARG_ENABLE(lock_checks, AC_HELP_STRING([--enable-lock-checks],
|
||||
[ enable to check lock and unlock calls, for debug purposes ]),
|
||||
, )
|
||||
if test x_$enable_lock_checks = x_yes; then
|
||||
AC_DEFINE(ENABLE_LOCK_CHECKS, 1, [Define if you want to use debug lock checking (slow).])
|
||||
fi
|
||||
|
||||
# set memory allocation checking if requested
|
||||
AC_ARG_ENABLE(alloc-checks, AC_HELP_STRING([--enable-alloc-checks],
|
||||
[ enable to check memory allocation, for debug purposes ]),
|
||||
, )
|
||||
if test x_$enable_alloc_checks = x_yes; then
|
||||
AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use])
|
||||
else
|
||||
AC_FUNC_MALLOC
|
||||
fi
|
||||
|
||||
# check to see if libraries are needed for these functions.
|
||||
AC_CHECK_LIB(socket, socket)
|
||||
AC_CHECK_LIB(nsl, inet_pton)
|
||||
|
||||
AC_FUNC_CHOWN
|
||||
AC_FUNC_FORK
|
||||
AC_FUNC_MALLOC
|
||||
AC_TYPE_SIGNAL
|
||||
AC_FUNC_FSEEKO
|
||||
AC_SYS_LARGEFILE
|
||||
|
||||
AC_REPLACE_FUNCS(inet_aton)
|
||||
AC_REPLACE_FUNCS(inet_pton)
|
||||
AC_REPLACE_FUNCS(inet_ntop)
|
||||
AC_REPLACE_FUNCS(snprintf)
|
||||
AC_REPLACE_FUNCS(strlcpy)
|
||||
AC_REPLACE_FUNCS(memmove)
|
||||
|
||||
AC_CHECK_FUNCS([getaddrinfo])
|
||||
if test $ac_cv_func_getaddrinfo = no; then
|
||||
AC_LIBOBJ([fake-rfc2553])
|
||||
fi
|
||||
|
||||
# check this after all other compilation checks, since the linking of the lib
|
||||
# may break checks after this.
|
||||
AC_ARG_WITH(ldns,
|
||||
@@ -513,9 +572,52 @@ AC_ARG_WITH(ldns,
|
||||
AC_SUBST(ldnsdir)
|
||||
])
|
||||
|
||||
AC_CHECK_LIB(ldns, ldns_rr_new,, [AC_MSG_ERROR([Can't find ldns library])])
|
||||
AC_CHECK_LIB(ldns, ldns_rr_new, [
|
||||
dnl ldns was found, check compat functions
|
||||
AC_REPLACE_FUNCS(inet_aton)
|
||||
AC_REPLACE_FUNCS(inet_pton)
|
||||
AC_REPLACE_FUNCS(inet_ntop)
|
||||
AC_REPLACE_FUNCS(snprintf)
|
||||
AC_REPLACE_FUNCS(strlcpy)
|
||||
AC_REPLACE_FUNCS(memmove)
|
||||
|
||||
AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [512], [Define to the maximum message length to pass to syslog.])
|
||||
AC_CHECK_FUNCS([getaddrinfo])
|
||||
if test $ac_cv_func_getaddrinfo = no; then
|
||||
AC_LIBOBJ([fake-rfc2553])
|
||||
fi
|
||||
|
||||
] , [
|
||||
dnl use the builtin ldns-src.tar.gz file to build ldns.
|
||||
if test ! -f $srcdir/ldns-src.tar.gz; then
|
||||
AC_MSG_ERROR([No ldns library found and no ldns-src.tar.gz, use --with-ldns=path.])
|
||||
fi
|
||||
echo "****************************************************************"
|
||||
echo "*** ***"
|
||||
echo "*** ldns library not found (--with-ldns= to specify by hand) ***"
|
||||
echo "*** Building ldns library from package included in this one. ***"
|
||||
echo "*** ***"
|
||||
echo "****************************************************************"
|
||||
if test -d ldns-src; then rm -rf ldns-src; fi
|
||||
mkdir ldns-src; cp $srcdir/ldns-src.tar.gz ldns-src/ldns-src.tar.gz; (cd ldns-src; gzip -cd ldns-src.tar.gz | tar xf -); rm -f ldns-src/ldns-src.tar.gz
|
||||
ldnsdir=`ls -d ldns-src/ldns*`
|
||||
AC_MSG_NOTICE([Configure $ldnsdir])
|
||||
echo "(cd $ldnsdir; ./configure)"
|
||||
(cd $ldnsdir; ./configure)
|
||||
AC_MSG_NOTICE([Finished $ldnsdir configure])
|
||||
CPPFLAGS="$CPPFLAGS -I$ldnsdir/include"
|
||||
LDFLAGS="$LDFLAGS $ldnsdir/lib/*.o"
|
||||
AC_SUBST(ldnsdir)
|
||||
dnl use ldns compat functions
|
||||
AC_DEFINE(HAVE_INET_ATON)
|
||||
AC_DEFINE(HAVE_INET_PTON)
|
||||
AC_DEFINE(HAVE_INET_NTOP)
|
||||
AC_DEFINE(HAVE_SNPRINTF)
|
||||
AC_DEFINE(HAVE_STRLCPY)
|
||||
AC_DEFINE(HAVE_MEMMOVE)
|
||||
AC_DEFINE(HAVE_GETADDRINFO)
|
||||
])
|
||||
|
||||
AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [5120], [Define to the maximum message length to pass to syslog.])
|
||||
|
||||
AH_BOTTOM([
|
||||
#include <stdio.h>
|
||||
@@ -558,6 +660,10 @@ AH_BOTTOM([
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENSSL_ERR_H
|
||||
#include <openssl/err.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ATTR_FORMAT
|
||||
# define ATTR_FORMAT(archetype, string_index, first_to_check) \
|
||||
__attribute__ ((format (archetype, string_index, first_to_check)))
|
||||
@@ -629,6 +735,25 @@ struct sockaddr_storage;
|
||||
|
||||
#include "ldns/ldns.h"
|
||||
|
||||
#ifdef UNBOUND_ALLOC_STATS
|
||||
# define malloc(s) unbound_stat_malloc_log(s, __FILE__, __LINE__, __func__)
|
||||
# define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
|
||||
# define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
|
||||
# define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
|
||||
void *unbound_stat_malloc(size_t size);
|
||||
void *unbound_stat_calloc(size_t nmemb, size_t size);
|
||||
void unbound_stat_free(void *ptr);
|
||||
void *unbound_stat_realloc(void *ptr, size_t size);
|
||||
void *unbound_stat_malloc_log(size_t size, const char* file, int line,
|
||||
const char* func);
|
||||
void *unbound_stat_calloc_log(size_t nmemb, size_t size, const char* file,
|
||||
int line, const char* func);
|
||||
void unbound_stat_free_log(void *ptr, const char* file, int line,
|
||||
const char* func);
|
||||
void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
|
||||
int line, const char* func);
|
||||
#endif /* UNBOUND_ALLOC_STATS */
|
||||
|
||||
/** default port for DNS traffic. */
|
||||
#define UNBOUND_DNS_PORT 53
|
||||
])
|
||||
|
||||
+118
-22
@@ -39,9 +39,6 @@
|
||||
* The daemon consists of global settings and a number of workers.
|
||||
*/
|
||||
|
||||
/** buffer size for network connections */
|
||||
#define BUFSZ 65552
|
||||
|
||||
#include "config.h"
|
||||
#include "daemon/daemon.h"
|
||||
#include "daemon/worker.h"
|
||||
@@ -54,6 +51,8 @@
|
||||
#include "services/cache/infra.h"
|
||||
#include "util/module.h"
|
||||
#include "iterator/iterator.h"
|
||||
#include "validator/validator.h"
|
||||
#include "util/fptr_wlist.h"
|
||||
#include <signal.h>
|
||||
|
||||
/** How many quit requests happened. */
|
||||
@@ -69,6 +68,8 @@ static int sig_record_reload = 0;
|
||||
static RETSIGTYPE record_sigh(int sig)
|
||||
{
|
||||
#ifdef LIBEVENT_SIGNAL_PROBLEM
|
||||
verbose(VERB_OPS, "quit on signal, no cleanup and statistics, "
|
||||
"because installed libevent version is not threadsafe");
|
||||
exit(0);
|
||||
#endif
|
||||
switch(sig)
|
||||
@@ -107,10 +108,10 @@ signal_handling_record()
|
||||
static void
|
||||
signal_handling_playback(struct worker* wrk)
|
||||
{
|
||||
if(sig_record_quit)
|
||||
worker_sighandler(SIGTERM, wrk);
|
||||
if(sig_record_reload)
|
||||
worker_sighandler(SIGHUP, wrk);
|
||||
if(sig_record_quit)
|
||||
worker_sighandler(SIGTERM, wrk);
|
||||
sig_record_quit = 0;
|
||||
sig_record_reload = 0;
|
||||
}
|
||||
@@ -124,6 +125,7 @@ daemon_init()
|
||||
return NULL;
|
||||
signal_handling_record();
|
||||
checklock_start();
|
||||
ERR_load_crypto_strings();
|
||||
daemon->need_to_exit = 0;
|
||||
daemon->num_modules = 0;
|
||||
if(!(daemon->env = (struct module_env*)calloc(1,
|
||||
@@ -148,6 +150,93 @@ daemon_open_shared_ports(struct daemon* daemon)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** count number of modules (words) in the string */
|
||||
static int
|
||||
count_modules(const char* s)
|
||||
{
|
||||
int num = 0;
|
||||
if(!s)
|
||||
return 0;
|
||||
while(*s) {
|
||||
/* skip whitespace */
|
||||
while(*s && isspace((int)*s))
|
||||
s++;
|
||||
if(*s && !isspace((int)*s)) {
|
||||
/* skip identifier */
|
||||
num++;
|
||||
while(*s && !isspace((int)*s))
|
||||
s++;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get funcblock for module name
|
||||
* @param str: string with module name. Advanced to next value on success.
|
||||
* @return funcblock or NULL on error.
|
||||
*/
|
||||
static struct module_func_block*
|
||||
daemon_module_factory(const char** str)
|
||||
{
|
||||
/* these are the modules available */
|
||||
int num = 2;
|
||||
const char* names[] = {"iterator", "validator", NULL};
|
||||
struct module_func_block* (*fb[])(void) =
|
||||
{&iter_get_funcblock, &val_get_funcblock, NULL};
|
||||
|
||||
int i;
|
||||
const char* s = *str;
|
||||
while(*s && isspace((int)*s))
|
||||
s++;
|
||||
for(i=0; i<num; i++) {
|
||||
if(strncmp(names[i], s, strlen(names[i])) == 0) {
|
||||
s += strlen(names[i]);
|
||||
*str = s;
|
||||
return (*fb[i])();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read config file module settings and set up the modfunc block
|
||||
* @param daemon: the daemon.
|
||||
* @return false on error
|
||||
*/
|
||||
static int
|
||||
daemon_config_modules(struct daemon* daemon)
|
||||
{
|
||||
const char* str = daemon->cfg->module_conf;
|
||||
int i;
|
||||
verbose(VERB_DETAIL, "module config: \"%s\"", str);
|
||||
daemon->num_modules = count_modules(str);
|
||||
if(daemon->num_modules == 0) {
|
||||
log_err("error: no modules specified");
|
||||
return 0;
|
||||
}
|
||||
if(daemon->num_modules > MAX_MODULE) {
|
||||
log_err("error: too many modules (%d max %d)",
|
||||
daemon->num_modules, MAX_MODULE);
|
||||
return 0;
|
||||
}
|
||||
daemon->modfunc = (struct module_func_block**)calloc((size_t)
|
||||
daemon->num_modules, sizeof(struct module_func_block*));
|
||||
if(!daemon->modfunc) {
|
||||
log_err("out of memory");
|
||||
return 0;
|
||||
}
|
||||
for(i=0; i<daemon->num_modules; i++) {
|
||||
daemon->modfunc[i] = daemon_module_factory(&str);
|
||||
if(!daemon->modfunc[i]) {
|
||||
log_err("Unknown value for first module in: '%s'",
|
||||
str);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Desetup the modules, deinit, delete.
|
||||
* @param daemon: the daemon.
|
||||
@@ -157,6 +246,8 @@ daemon_desetup_modules(struct daemon* daemon)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<daemon->num_modules; i++) {
|
||||
log_assert(fptr_whitelist_mod_deinit(
|
||||
daemon->modfunc[i]->deinit));
|
||||
(*daemon->modfunc[i]->deinit)(daemon->env, i);
|
||||
}
|
||||
daemon->num_modules = 0;
|
||||
@@ -174,20 +265,16 @@ static void daemon_setup_modules(struct daemon* daemon)
|
||||
if(daemon->num_modules != 0)
|
||||
daemon_desetup_modules(daemon);
|
||||
/* fixed setup of the modules */
|
||||
daemon->num_modules = 1;
|
||||
daemon->modfunc = (struct module_func_block**)calloc((size_t)
|
||||
daemon->num_modules, sizeof(struct module_func_block*));
|
||||
if(!daemon->modfunc) {
|
||||
fatal_exit("malloc failure allocating function callbacks");
|
||||
if(!daemon_config_modules(daemon)) {
|
||||
fatal_exit("failed to setup modules");
|
||||
}
|
||||
daemon->modfunc[0] = iter_get_funcblock();
|
||||
daemon->env->cfg = daemon->cfg;
|
||||
daemon->env->alloc = &daemon->superalloc;
|
||||
daemon->env->worker = NULL;
|
||||
daemon->env->send_packet = &worker_send_packet;
|
||||
daemon->env->send_query = &worker_send_query;
|
||||
daemon->env->need_to_validate = 0; /* set by module init below */
|
||||
for(i=0; i<daemon->num_modules; i++) {
|
||||
log_info("init module %d: %s", i, daemon->modfunc[i]->name);
|
||||
log_assert(fptr_whitelist_mod_init(daemon->modfunc[i]->init));
|
||||
if(!(*daemon->modfunc[i]->init)(daemon->env, i)) {
|
||||
fatal_exit("module init for module %s failed",
|
||||
daemon->modfunc[i]->name);
|
||||
@@ -252,8 +339,7 @@ thread_start(void* arg)
|
||||
worker->cmd_send_fd = -1;
|
||||
close_other_pipes(worker->daemon, worker->thread_num);
|
||||
#endif
|
||||
if(!worker_init(worker, worker->daemon->cfg, worker->daemon->ports,
|
||||
BUFSZ, 0))
|
||||
if(!worker_init(worker, worker->daemon->cfg, worker->daemon->ports, 0))
|
||||
fatal_exit("Could not initialize thread");
|
||||
|
||||
worker_work(worker);
|
||||
@@ -298,7 +384,7 @@ daemon_stop_others(struct daemon* daemon)
|
||||
worker_send_cmd(daemon->workers[i],
|
||||
daemon->workers[0]->front->udp_buff, worker_cmd_quit);
|
||||
}
|
||||
/** wait for them to quit */
|
||||
/* wait for them to quit */
|
||||
for(i=1; i<daemon->num; i++) {
|
||||
/* join it to make sure its dead */
|
||||
verbose(VERB_ALGO, "join %d", i);
|
||||
@@ -328,8 +414,7 @@ daemon_fork(struct daemon* daemon)
|
||||
/* Special handling for the main thread. This is the thread
|
||||
* that handles signals.
|
||||
*/
|
||||
if(!worker_init(daemon->workers[0], daemon->cfg, daemon->ports,
|
||||
BUFSZ, 1))
|
||||
if(!worker_init(daemon->workers[0], daemon->cfg, daemon->ports, 1))
|
||||
fatal_exit("Could not initialize main thread");
|
||||
signal_handling_playback(daemon->workers[0]);
|
||||
|
||||
@@ -340,9 +425,7 @@ daemon_fork(struct daemon* daemon)
|
||||
/* we exited! a signal happened! Stop other threads */
|
||||
daemon_stop_others(daemon);
|
||||
|
||||
if(daemon->workers[0]->need_to_restart)
|
||||
daemon->need_to_exit = 0;
|
||||
else daemon->need_to_exit = 1;
|
||||
daemon->need_to_exit = daemon->workers[0]->need_to_exit;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -354,6 +437,13 @@ daemon_cleanup(struct daemon* daemon)
|
||||
don't die on multiple reload signals for example. */
|
||||
signal_handling_record();
|
||||
log_thread_set(NULL);
|
||||
/* clean up caches because
|
||||
* a) RRset IDs will be recycled after a reload, causing collisions
|
||||
* b) validation config can change, thus rrset, msg, keycache clear
|
||||
* The infra cache is kept, the timing and edns info is still valid */
|
||||
slabhash_clear(&daemon->env->rrset_cache->table);
|
||||
slabhash_clear(daemon->env->msg_cache);
|
||||
/* key cache is cleared by module desetup during next daemon_init() */
|
||||
for(i=0; i<daemon->num; i++)
|
||||
worker_delete(daemon->workers[i]);
|
||||
free(daemon->workers);
|
||||
@@ -375,9 +465,15 @@ daemon_delete(struct daemon* daemon)
|
||||
infra_delete(daemon->env->infra_cache);
|
||||
}
|
||||
alloc_clear(&daemon->superalloc);
|
||||
free(daemon->cwd);
|
||||
free(daemon->pidfile);
|
||||
free(daemon->env);
|
||||
free(daemon);
|
||||
/* libcrypto cleanup */
|
||||
/* CONF_modules_unload(1); */
|
||||
EVP_cleanup();
|
||||
/* ENGINE_cleanup(); */
|
||||
CRYPTO_cleanup_all_ex_data(); /* safe, no more threads right now */
|
||||
ERR_remove_state(0);
|
||||
ERR_free_strings();
|
||||
checklock_stop();
|
||||
}
|
||||
|
||||
@@ -58,8 +58,6 @@ struct rrset_cache;
|
||||
struct daemon {
|
||||
/** The config settings */
|
||||
struct config_file* cfg;
|
||||
/** current working directory */
|
||||
char* cwd;
|
||||
/** pidfile that is used */
|
||||
char* pidfile;
|
||||
/** port number that has ports opened. */
|
||||
|
||||
+69
-35
@@ -55,15 +55,19 @@
|
||||
#include <pwd.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
/** global debug value to keep track of heap memory allocation */
|
||||
void* unbound_start_brk = 0;
|
||||
|
||||
/** print usage. */
|
||||
static void usage()
|
||||
{
|
||||
printf("usage: unbound [options]\n");
|
||||
printf("usage: unbound [options]\n");
|
||||
printf(" start unbound daemon DNS resolver.\n");
|
||||
printf("-h this help\n");
|
||||
printf("-c file config file to read, unbound.conf(5).\n");
|
||||
printf("-c file config file to read instead of %s\n", CONFIGFILE);
|
||||
printf(" file format is described in unbound.conf(5).\n");
|
||||
printf("-d do not fork into the background.\n");
|
||||
printf("-v verbose (multiple times increase verbosity)\n");
|
||||
printf("-v verbose (more times to increase verbosity)\n");
|
||||
printf("Version %s\n", PACKAGE_VERSION);
|
||||
printf("BSD licensed, see LICENSE in source package for details.\n");
|
||||
printf("Report bugs to %s\n", PACKAGE_BUGREPORT);
|
||||
@@ -74,10 +78,12 @@ static void
|
||||
checkrlimits(struct config_file* cfg)
|
||||
{
|
||||
int list = ((cfg->do_ip4?1:0) + (cfg->do_ip6?1:0)) *
|
||||
((cfg->do_udp?1:0) + (cfg->do_tcp?1 + TCP_ACCEPT_COUNT:0));
|
||||
((cfg->do_udp?1:0) + (cfg->do_tcp?1 +
|
||||
(int)cfg->incoming_num_tcp:0));
|
||||
size_t ifs = (size_t)(cfg->num_ifs==0?1:cfg->num_ifs);
|
||||
size_t listen_num = list*ifs;
|
||||
size_t outnum = cfg->outgoing_num_ports*ifs + cfg->outgoing_num_tcp;
|
||||
size_t out_ifs = (size_t)(cfg->num_out_ifs==0?1:cfg->num_out_ifs);
|
||||
size_t outnum = cfg->outgoing_num_ports*out_ifs + cfg->outgoing_num_tcp;
|
||||
size_t misc = 4; /* logfile, pidfile, stdout... */
|
||||
size_t perthread = listen_num + outnum + 2/*cmdpipe*/ + 2/*libevent*/
|
||||
+ misc;
|
||||
@@ -105,24 +111,15 @@ checkrlimits(struct config_file* cfg)
|
||||
}
|
||||
}
|
||||
|
||||
/** to changedir, logfile */
|
||||
/** set verbosity, check rlimits, cache settings */
|
||||
static void
|
||||
apply_dir(struct daemon* daemon, struct config_file* cfg, int cmdline_verbose)
|
||||
apply_settings(struct daemon* daemon, struct config_file* cfg,
|
||||
int cmdline_verbose)
|
||||
{
|
||||
/* apply if they have changed */
|
||||
daemon->cfg = cfg;
|
||||
verbosity = cmdline_verbose + cfg->verbosity;
|
||||
if(cfg->directory && cfg->directory[0]) {
|
||||
if(!daemon->cwd || strcmp(daemon->cwd, cfg->directory) != 0) {
|
||||
if(chdir(cfg->directory)) {
|
||||
log_err("Could not chdir to %s: %s",
|
||||
cfg->directory, strerror(errno));
|
||||
}
|
||||
free(daemon->cwd);
|
||||
if(!(daemon->cwd = strdup(cfg->directory)))
|
||||
log_err("cwd: malloc failed");
|
||||
}
|
||||
}
|
||||
config_apply(cfg);
|
||||
if(!daemon->env->msg_cache ||
|
||||
cfg->msg_cache_size != slabhash_get_size(daemon->env->msg_cache) ||
|
||||
cfg->msg_cache_slabs != daemon->env->msg_cache->size) {
|
||||
@@ -179,7 +176,8 @@ readpid (const char* file)
|
||||
return -1;
|
||||
}
|
||||
|
||||
pid = strtol(pidbuf, &t, 10);
|
||||
pidbuf[sizeof(pidbuf)-1] = 0;
|
||||
pid = (pid_t)strtol(pidbuf, &t, 10);
|
||||
|
||||
if (*t && *t != '\n') {
|
||||
return -1;
|
||||
@@ -216,7 +214,12 @@ static void
|
||||
checkoldpid(struct config_file* cfg)
|
||||
{
|
||||
pid_t old;
|
||||
if((old = readpid(cfg->pidfile)) != -1) {
|
||||
char* file = cfg->pidfile;
|
||||
if(cfg->chrootdir && cfg->chrootdir[0] &&
|
||||
strncmp(file, cfg->chrootdir, strlen(cfg->chrootdir))==0) {
|
||||
file += strlen(cfg->chrootdir);
|
||||
}
|
||||
if((old = readpid(file)) != -1) {
|
||||
/* see if it is still alive */
|
||||
if(kill(old, 0) == 0 || errno == EPERM)
|
||||
log_warn("unbound is already running as pid %u.",
|
||||
@@ -258,35 +261,62 @@ detach(struct config_file* cfg)
|
||||
static void
|
||||
do_chroot(struct daemon* daemon, struct config_file* cfg, int debug_mode)
|
||||
{
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
/* initialize, but not to 0 (root) */
|
||||
memset(&uid, -12, sizeof(uid));
|
||||
memset(&gid, -12, sizeof(gid));
|
||||
log_assert(cfg);
|
||||
|
||||
/* daemonize last to be able to print error to user */
|
||||
if(cfg->chrootdir && cfg->chrootdir[0])
|
||||
if(chroot(cfg->chrootdir))
|
||||
fatal_exit("unable to chroot: %s", strerror(errno));
|
||||
if(cfg->directory && cfg->directory[0]) {
|
||||
if(chdir(cfg->directory)) {
|
||||
fatal_exit("Could not chdir to %s: %s",
|
||||
cfg->directory, strerror(errno));
|
||||
}
|
||||
verbose(VERB_DETAIL, "chdir to %s", cfg->directory);
|
||||
}
|
||||
if(cfg->username && cfg->username[0]) {
|
||||
struct passwd *pwd;
|
||||
if((pwd = getpwnam(cfg->username)) == NULL)
|
||||
fatal_exit("user '%s' does not exist.", cfg->username);
|
||||
if(setgid(pwd->pw_gid) != 0)
|
||||
fatal_exit("unable to set group id: %s", strerror(errno));
|
||||
if(setuid(pwd->pw_uid) != 0)
|
||||
fatal_exit("unable to set user id: %s", strerror(errno));
|
||||
uid = pwd->pw_uid;
|
||||
gid = pwd->pw_gid;
|
||||
endpwent();
|
||||
}
|
||||
if(cfg->chrootdir && cfg->chrootdir[0]) {
|
||||
if(chroot(cfg->chrootdir))
|
||||
fatal_exit("unable to chroot to %s: %s",
|
||||
cfg->chrootdir, strerror(errno));
|
||||
verbose(VERB_DETAIL, "chroot to %s", cfg->chrootdir);
|
||||
}
|
||||
if(cfg->username && cfg->username[0]) {
|
||||
if(setgid(gid) != 0)
|
||||
fatal_exit("unable to set group id of %s: %s",
|
||||
cfg->username, strerror(errno));
|
||||
if(setuid(uid) != 0)
|
||||
fatal_exit("unable to set user id of %s: %s",
|
||||
cfg->username, strerror(errno));
|
||||
verbose(VERB_DETAIL, "drop user privileges, run as %s",
|
||||
cfg->username);
|
||||
}
|
||||
/* check old pid file before forking */
|
||||
if(cfg->pidfile && cfg->pidfile[0]) {
|
||||
checkoldpid(cfg);
|
||||
}
|
||||
|
||||
/* init logfile just before fork */
|
||||
log_init(cfg->logfile);
|
||||
log_init(cfg->logfile, cfg->use_syslog, cfg->chrootdir);
|
||||
if(!debug_mode && cfg->do_daemonize) {
|
||||
detach(cfg);
|
||||
}
|
||||
if(cfg->pidfile && cfg->pidfile[0]) {
|
||||
writepid(cfg->pidfile, getpid());
|
||||
if(!(daemon->pidfile = strdup(cfg->pidfile)))
|
||||
char* pf = cfg->pidfile;
|
||||
if(cfg->chrootdir && cfg->chrootdir[0] &&
|
||||
strncmp(pf, cfg->chrootdir, strlen(cfg->chrootdir))==0)
|
||||
pf += strlen(cfg->chrootdir);
|
||||
writepid(pf, getpid());
|
||||
if(!(daemon->pidfile = strdup(pf)))
|
||||
log_err("pidf: malloc failed");
|
||||
}
|
||||
}
|
||||
@@ -299,7 +329,7 @@ do_chroot(struct daemon* daemon, struct config_file* cfg, int debug_mode)
|
||||
* @param debug_mode: if set, do not daemonize.
|
||||
*/
|
||||
static void
|
||||
run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode)
|
||||
run_daemon(char* cfgfile, int cmdline_verbose, int debug_mode)
|
||||
{
|
||||
struct config_file* cfg = NULL;
|
||||
struct daemon* daemon = NULL;
|
||||
@@ -317,7 +347,7 @@ run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode)
|
||||
fatal_exit("Could not alloc config defaults");
|
||||
if(!config_read(cfg, cfgfile))
|
||||
fatal_exit("Could not read config file: %s", cfgfile);
|
||||
apply_dir(daemon, cfg, cmdline_verbose);
|
||||
apply_settings(daemon, cfg, cmdline_verbose);
|
||||
|
||||
/* prepare */
|
||||
if(!daemon_open_shared_ports(daemon))
|
||||
@@ -325,7 +355,7 @@ run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode)
|
||||
if(!done_chroot) {
|
||||
do_chroot(daemon, cfg, debug_mode);
|
||||
done_chroot = 1;
|
||||
}
|
||||
} else log_init(cfg->logfile, cfg->use_syslog, cfg->chrootdir);
|
||||
/* work */
|
||||
daemon_fork(daemon);
|
||||
|
||||
@@ -355,11 +385,14 @@ int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
int c;
|
||||
const char* cfgfile = NULL;
|
||||
char* cfgfile = CONFIGFILE;
|
||||
int cmdline_verbose = 0;
|
||||
int debug_mode = 0;
|
||||
|
||||
log_init(NULL);
|
||||
/* take debug snapshot of heap */
|
||||
unbound_start_brk = sbrk(0);
|
||||
|
||||
log_init(NULL, 0, NULL);
|
||||
/* parse the options */
|
||||
while( (c=getopt(argc, argv, "c:dhv")) != -1) {
|
||||
switch(c) {
|
||||
@@ -389,5 +422,6 @@ main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
run_daemon(cfgfile, cmdline_verbose, debug_mode);
|
||||
log_init(NULL, 0, NULL); /* close logfile */
|
||||
return 0;
|
||||
}
|
||||
|
||||
+335
-87
@@ -48,17 +48,19 @@
|
||||
#include "util/netevent.h"
|
||||
#include "util/config_file.h"
|
||||
#include "util/module.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/storage/slabhash.h"
|
||||
#include "services/listen_dnsport.h"
|
||||
#include "services/outside_network.h"
|
||||
#include "services/outbound_list.h"
|
||||
#include "services/cache/rrset.h"
|
||||
#include "services/cache/infra.h"
|
||||
#include "services/cache/dns.h"
|
||||
#include "services/mesh.h"
|
||||
#include "util/data/msgparse.h"
|
||||
#include "util/data/msgencode.h"
|
||||
#include "util/data/dname.h"
|
||||
#include "util/fptr_wlist.h"
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
@@ -69,32 +71,97 @@
|
||||
/** Size of an UDP datagram */
|
||||
#define NORMAL_UDP_SIZE 512 /* bytes */
|
||||
|
||||
/** Report on memory usage by this thread and global */
|
||||
#ifdef UNBOUND_ALLOC_STATS
|
||||
/** measure memory leakage */
|
||||
static void
|
||||
worker_mem_report(struct worker* worker)
|
||||
debug_memleak(size_t accounted, size_t heap,
|
||||
size_t total_alloc, size_t total_free)
|
||||
{
|
||||
static int init = 0;
|
||||
static size_t base_heap, base_accounted, base_alloc, base_free;
|
||||
size_t base_af, cur_af, grow_af, grow_acc;
|
||||
if(!init) {
|
||||
init = 1;
|
||||
base_heap = heap;
|
||||
base_accounted = accounted;
|
||||
base_alloc = total_alloc;
|
||||
base_free = total_free;
|
||||
}
|
||||
base_af = base_alloc - base_free;
|
||||
cur_af = total_alloc - total_free;
|
||||
grow_af = cur_af - base_af;
|
||||
grow_acc = accounted - base_accounted;
|
||||
log_info("Leakage: %d leaked. growth: %u use, %u acc, %u heap",
|
||||
(int)(grow_af - grow_acc), (unsigned)grow_af,
|
||||
(unsigned)grow_acc, (unsigned)(heap - base_heap));
|
||||
}
|
||||
|
||||
/** give debug heap size indication */
|
||||
static void
|
||||
debug_total_mem(size_t calctotal)
|
||||
{
|
||||
extern void* unbound_start_brk;
|
||||
extern size_t unbound_mem_alloc, unbound_mem_freed;
|
||||
void* cur = sbrk(0);
|
||||
int total = cur-unbound_start_brk;
|
||||
log_info("Total heap memory estimate: %u total-alloc: %u "
|
||||
"total-free: %u", (unsigned)total,
|
||||
(unsigned)unbound_mem_alloc, (unsigned)unbound_mem_freed);
|
||||
debug_memleak(calctotal, (size_t)total,
|
||||
unbound_mem_alloc, unbound_mem_freed);
|
||||
}
|
||||
#endif /* UNBOUND_ALLOC_STATS */
|
||||
|
||||
/** Report on memory usage by this thread and global */
|
||||
void
|
||||
worker_mem_report(struct worker* ATTR_UNUSED(worker),
|
||||
struct serviced_query* ATTR_UNUSED(cur_serv))
|
||||
{
|
||||
#ifdef UNBOUND_ALLOC_STATS
|
||||
/* debug func in validator module */
|
||||
size_t total, front, back, mesh, msg, rrset, infra, ac, superac;
|
||||
size_t me;
|
||||
size_t me, iter, val;
|
||||
int i;
|
||||
if(verbosity < VERB_ALGO)
|
||||
return;
|
||||
front = listen_get_mem(worker->front);
|
||||
back = outnet_get_mem(worker->back);
|
||||
msg = slabhash_get_mem(worker->env.msg_cache);
|
||||
rrset = slabhash_get_mem(&worker->env.rrset_cache->table);
|
||||
infra = slabhash_get_mem(worker->env.infra_cache->hosts);
|
||||
infra = infra_get_mem(worker->env.infra_cache);
|
||||
mesh = mesh_get_mem(worker->env.mesh);
|
||||
ac = alloc_get_mem(&worker->alloc);
|
||||
superac = alloc_get_mem(&worker->daemon->superalloc);
|
||||
iter = 0;
|
||||
val = 0;
|
||||
for(i=0; i<worker->env.mesh->num_modules; i++) {
|
||||
log_assert(fptr_whitelist_mod_get_mem(worker->env.mesh->
|
||||
modfunc[i]->get_mem));
|
||||
if(strcmp(worker->env.mesh->modfunc[i]->name, "validator")==0)
|
||||
val += (*worker->env.mesh->modfunc[i]->get_mem)
|
||||
(&worker->env, i);
|
||||
else iter += (*worker->env.mesh->modfunc[i]->get_mem)
|
||||
(&worker->env, i);
|
||||
}
|
||||
me = sizeof(*worker) + sizeof(*worker->base) + sizeof(*worker->comsig)
|
||||
+ comm_point_get_mem(worker->cmd_com) +
|
||||
sizeof(worker->rndstate) + region_get_mem(worker->scratchpad);
|
||||
total = front+back+mesh+msg+rrset+infra+ac+superac+me;
|
||||
+ comm_point_get_mem(worker->cmd_com)
|
||||
+ sizeof(worker->rndstate)
|
||||
+ regional_get_mem(worker->scratchpad)
|
||||
+ sizeof(*worker->env.scratch_buffer)
|
||||
+ ldns_buffer_capacity(worker->env.scratch_buffer);
|
||||
if(cur_serv) {
|
||||
me += serviced_get_mem(cur_serv);
|
||||
}
|
||||
total = front+back+mesh+msg+rrset+infra+iter+val+ac+superac+me;
|
||||
log_info("Memory conditions: %u front=%u back=%u mesh=%u msg=%u "
|
||||
"rrset=%u infra=%u alloccache=%u globalalloccache=%u me=%u",
|
||||
"rrset=%u infra=%u iter=%u val=%u "
|
||||
"alloccache=%u globalalloccache=%u me=%u",
|
||||
(unsigned)total, (unsigned)front, (unsigned)back,
|
||||
(unsigned)mesh, (unsigned)msg, (unsigned)rrset,
|
||||
(unsigned)infra, (unsigned)ac, (unsigned)superac,
|
||||
(unsigned)me);
|
||||
(unsigned)infra, (unsigned)iter, (unsigned)val, (unsigned)ac,
|
||||
(unsigned)superac, (unsigned)me);
|
||||
debug_total_mem(total);
|
||||
#endif /* UNBOUND_ALLOC_STATS */
|
||||
}
|
||||
|
||||
void
|
||||
@@ -111,8 +178,7 @@ worker_send_cmd(struct worker* worker, ldns_buffer* buffer,
|
||||
log_err("write socket: %s", strerror(errno));
|
||||
}
|
||||
|
||||
/** process incoming replies from the network */
|
||||
static int
|
||||
int
|
||||
worker_handle_reply(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* reply_info)
|
||||
{
|
||||
@@ -124,7 +190,7 @@ worker_handle_reply(struct comm_point* c, void* arg, int error,
|
||||
|
||||
if(error != 0) {
|
||||
mesh_report_reply(worker->env.mesh, &e, 0, reply_info);
|
||||
worker_mem_report(worker);
|
||||
worker_mem_report(worker, NULL);
|
||||
return 0;
|
||||
}
|
||||
/* sanity check. */
|
||||
@@ -135,26 +201,26 @@ worker_handle_reply(struct comm_point* c, void* arg, int error,
|
||||
/* error becomes timeout for the module as if this reply
|
||||
* never arrived. */
|
||||
mesh_report_reply(worker->env.mesh, &e, 0, reply_info);
|
||||
worker_mem_report(worker);
|
||||
worker_mem_report(worker, NULL);
|
||||
return 0;
|
||||
}
|
||||
mesh_report_reply(worker->env.mesh, &e, 1, reply_info);
|
||||
worker_mem_report(worker);
|
||||
worker_mem_report(worker, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** process incoming serviced query replies from the network */
|
||||
static int
|
||||
int
|
||||
worker_handle_service_reply(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* reply_info)
|
||||
{
|
||||
struct outbound_entry* e = (struct outbound_entry*)arg;
|
||||
struct worker* worker = e->qstate->env->worker;
|
||||
struct serviced_query *sq = e->qsent;
|
||||
|
||||
verbose(VERB_ALGO, "worker scvd callback for qstate %p", e->qstate);
|
||||
verbose(VERB_ALGO, "worker svcd callback for qstate %p", e->qstate);
|
||||
if(error != 0) {
|
||||
mesh_report_reply(worker->env.mesh, e, 0, reply_info);
|
||||
worker_mem_report(worker);
|
||||
worker_mem_report(worker, sq);
|
||||
return 0;
|
||||
}
|
||||
/* sanity check. */
|
||||
@@ -166,11 +232,11 @@ worker_handle_service_reply(struct comm_point* c, void* arg, int error,
|
||||
* never arrived. */
|
||||
verbose(VERB_ALGO, "worker: bad reply handled as timeout");
|
||||
mesh_report_reply(worker->env.mesh, e, 0, reply_info);
|
||||
worker_mem_report(worker);
|
||||
worker_mem_report(worker, sq);
|
||||
return 0;
|
||||
}
|
||||
mesh_report_reply(worker->env.mesh, e, 1, reply_info);
|
||||
worker_mem_report(worker);
|
||||
worker_mem_report(worker, sq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -222,13 +288,7 @@ worker_check_request(ldns_buffer* pkt, struct worker* worker)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** process control messages from the main thread.
|
||||
* @param c: comm point to read from.
|
||||
* @param arg: worker.
|
||||
* @param error: error status of comm point.
|
||||
* @param reply_info: not used.
|
||||
*/
|
||||
static int
|
||||
int
|
||||
worker_handle_control_cmd(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* ATTR_UNUSED(reply_info))
|
||||
{
|
||||
@@ -257,6 +317,131 @@ worker_handle_control_cmd(struct comm_point* c, void* arg, int error,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** check if a delegation is secure */
|
||||
static enum sec_status
|
||||
check_delegation_secure(struct reply_info *rep)
|
||||
{
|
||||
/* return smallest security status */
|
||||
size_t i;
|
||||
enum sec_status sec = sec_status_secure;
|
||||
enum sec_status s;
|
||||
size_t num = rep->an_numrrsets + rep->ns_numrrsets;
|
||||
/* check if answer and authority are OK */
|
||||
for(i=0; i<num; i++) {
|
||||
s = ((struct packed_rrset_data*)rep->rrsets[i]->entry.data)
|
||||
->security;
|
||||
if(s < sec)
|
||||
sec = s;
|
||||
}
|
||||
/* in additional, only unchecked triggers revalidation */
|
||||
for(i=num; i<rep->rrset_count; i++) {
|
||||
s = ((struct packed_rrset_data*)rep->rrsets[i]->entry.data)
|
||||
->security;
|
||||
if(s == sec_status_unchecked)
|
||||
return s;
|
||||
}
|
||||
return sec;
|
||||
}
|
||||
|
||||
/** remove nonsecure from a delegation referral additional section */
|
||||
static void
|
||||
deleg_remove_nonsecure_additional(struct reply_info* rep)
|
||||
{
|
||||
/* we can simply edit it, since we are working in the scratch region */
|
||||
size_t i;
|
||||
enum sec_status s;
|
||||
|
||||
for(i = rep->an_numrrsets+rep->ns_numrrsets; i<rep->rrset_count; i++) {
|
||||
s = ((struct packed_rrset_data*)rep->rrsets[i]->entry.data)
|
||||
->security;
|
||||
if(s != sec_status_secure) {
|
||||
memmove(rep->rrsets+i, rep->rrsets+i+1,
|
||||
sizeof(struct ub_packed_rrset_key*)*
|
||||
(rep->rrset_count - i - 1));
|
||||
rep->ar_numrrsets--;
|
||||
rep->rrset_count--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** answer nonrecursive query from the cache */
|
||||
static int
|
||||
answer_norec_from_cache(struct worker* worker, struct query_info* qinfo,
|
||||
uint16_t id, uint16_t flags, struct comm_reply* repinfo,
|
||||
struct edns_data* edns)
|
||||
{
|
||||
/* for a nonrecursive query return either:
|
||||
* o an error (servfail; we try to avoid this)
|
||||
* o a delegation (closest we have; this routine tries that)
|
||||
* o the answer (checked by answer_from_cache)
|
||||
*
|
||||
* So, grab a delegation from the rrset cache.
|
||||
* Then check if it needs validation, if so, this routine fails,
|
||||
* so that iterator can prime and validator can verify rrsets.
|
||||
*/
|
||||
uint16_t udpsize = edns->udp_size;
|
||||
int secure = 0;
|
||||
uint32_t timenow = (uint32_t)time(0);
|
||||
int must_validate = !(flags&BIT_CD) && worker->env.need_to_validate;
|
||||
struct dns_msg *msg = NULL;
|
||||
struct delegpt *dp;
|
||||
|
||||
dp = dns_cache_find_delegation(&worker->env, qinfo->qname,
|
||||
qinfo->qname_len, qinfo->qtype, qinfo->qclass,
|
||||
worker->scratchpad, &msg, timenow);
|
||||
if(!dp) { /* no delegation, need to reprime */
|
||||
regional_free_all(worker->scratchpad);
|
||||
return 0;
|
||||
}
|
||||
if(must_validate) {
|
||||
switch(check_delegation_secure(msg->rep)) {
|
||||
case sec_status_unchecked:
|
||||
/* some rrsets have not been verified yet, go and
|
||||
* let validator do that */
|
||||
regional_free_all(worker->scratchpad);
|
||||
return 0;
|
||||
case sec_status_bogus:
|
||||
/* some rrsets are bogus, reply servfail */
|
||||
edns->edns_version = EDNS_ADVERTISED_VERSION;
|
||||
edns->udp_size = EDNS_ADVERTISED_SIZE;
|
||||
edns->ext_rcode = 0;
|
||||
edns->bits &= EDNS_DO;
|
||||
error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL,
|
||||
&msg->qinfo, id, flags, edns);
|
||||
regional_free_all(worker->scratchpad);
|
||||
return 1;
|
||||
case sec_status_secure:
|
||||
/* all rrsets are secure */
|
||||
/* remove non-secure rrsets from the add. section*/
|
||||
if(worker->env.cfg->val_clean_additional)
|
||||
deleg_remove_nonsecure_additional(msg->rep);
|
||||
secure = 1;
|
||||
break;
|
||||
case sec_status_indeterminate:
|
||||
case sec_status_insecure:
|
||||
default:
|
||||
/* not secure */
|
||||
secure = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* return this delegation from the cache */
|
||||
edns->edns_version = EDNS_ADVERTISED_VERSION;
|
||||
edns->udp_size = EDNS_ADVERTISED_SIZE;
|
||||
edns->ext_rcode = 0;
|
||||
edns->bits &= EDNS_DO;
|
||||
msg->rep->flags |= BIT_QR|BIT_RA;
|
||||
if(!reply_info_answer_encode(&msg->qinfo, msg->rep, id, flags,
|
||||
repinfo->c->buffer, 0, 1, worker->scratchpad,
|
||||
udpsize, edns, (int)(edns->bits & EDNS_DO), secure)) {
|
||||
error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL,
|
||||
&msg->qinfo, id, flags, edns);
|
||||
}
|
||||
regional_free_all(worker->scratchpad);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** check cname chain in cache reply */
|
||||
static int
|
||||
check_cache_chain(struct reply_info* rep) {
|
||||
@@ -282,6 +467,18 @@ check_cache_chain(struct reply_info* rep) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** check security status in cache reply */
|
||||
static int
|
||||
all_rrsets_secure(struct reply_info* rep) {
|
||||
size_t i;
|
||||
for(i=0; i<rep->rrset_count; i++) {
|
||||
if( ((struct packed_rrset_data*)rep->rrsets[i]->entry.data)
|
||||
->security != sec_status_secure )
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** answer query from the cache */
|
||||
static int
|
||||
answer_from_cache(struct worker* worker, struct lruhash_entry* e, uint16_t id,
|
||||
@@ -291,6 +488,8 @@ answer_from_cache(struct worker* worker, struct lruhash_entry* e, uint16_t id,
|
||||
struct reply_info* rep = (struct reply_info*)e->data;
|
||||
uint32_t timenow = time(0);
|
||||
uint16_t udpsize = edns->udp_size;
|
||||
int secure;
|
||||
int must_validate = !(flags&BIT_CD) && worker->env.need_to_validate;
|
||||
/* see if it is possible */
|
||||
if(rep->ttl <= timenow) {
|
||||
/* the rrsets may have been updated in the meantime.
|
||||
@@ -299,10 +498,6 @@ answer_from_cache(struct worker* worker, struct lruhash_entry* e, uint16_t id,
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
edns->edns_version = EDNS_ADVERTISED_VERSION;
|
||||
edns->udp_size = EDNS_ADVERTISED_SIZE;
|
||||
edns->ext_rcode = 0;
|
||||
edns->bits &= EDNS_DO;
|
||||
if(!rrset_array_lock(rep->ref, rep->rrset_count, timenow))
|
||||
return 0;
|
||||
/* locked and ids and ttls are OK. */
|
||||
@@ -311,15 +506,52 @@ answer_from_cache(struct worker* worker, struct lruhash_entry* e, uint16_t id,
|
||||
htons(LDNS_RR_TYPE_CNAME) || rep->rrsets[0]->rk.type ==
|
||||
htons(LDNS_RR_TYPE_DNAME))) {
|
||||
if(!check_cache_chain(rep)) {
|
||||
/* cname chain invalid, redo iterator steps */
|
||||
verbose(VERB_ALGO, "Cache reply: cname chain broken");
|
||||
bail_out:
|
||||
rrset_array_unlock_touch(worker->env.rrset_cache,
|
||||
worker->scratchpad, rep->ref, rep->rrset_count);
|
||||
region_free_all(worker->scratchpad);
|
||||
regional_free_all(worker->scratchpad);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* check security status of the cached answer */
|
||||
if( rep->security == sec_status_bogus && must_validate) {
|
||||
/* BAD cached */
|
||||
edns->edns_version = EDNS_ADVERTISED_VERSION;
|
||||
edns->udp_size = EDNS_ADVERTISED_SIZE;
|
||||
edns->ext_rcode = 0;
|
||||
edns->bits &= EDNS_DO;
|
||||
error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL,
|
||||
&mrentry->key, id, flags, edns);
|
||||
rrset_array_unlock_touch(worker->env.rrset_cache,
|
||||
worker->scratchpad, rep->ref, rep->rrset_count);
|
||||
regional_free_all(worker->scratchpad);
|
||||
return 1;
|
||||
} else if( rep->security == sec_status_unchecked && must_validate) {
|
||||
verbose(VERB_ALGO, "Cache reply: unchecked entry needs "
|
||||
"validation");
|
||||
goto bail_out; /* need to validate cache entry first */
|
||||
} else if(rep->security == sec_status_secure) {
|
||||
if(all_rrsets_secure(rep))
|
||||
secure = 1;
|
||||
else {
|
||||
if(must_validate) {
|
||||
verbose(VERB_ALGO, "Cache reply: secure entry"
|
||||
" changed status");
|
||||
goto bail_out; /* rrset changed, re-verify */
|
||||
}
|
||||
secure = 0;
|
||||
}
|
||||
} else secure = 0;
|
||||
|
||||
edns->edns_version = EDNS_ADVERTISED_VERSION;
|
||||
edns->udp_size = EDNS_ADVERTISED_SIZE;
|
||||
edns->ext_rcode = 0;
|
||||
edns->bits &= EDNS_DO;
|
||||
if(!reply_info_answer_encode(&mrentry->key, rep, id, flags,
|
||||
repinfo->c->buffer, timenow, 1, worker->scratchpad,
|
||||
udpsize, edns, (int)(edns->bits & EDNS_DO) )) {
|
||||
udpsize, edns, (int)(edns->bits & EDNS_DO), secure)) {
|
||||
error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL,
|
||||
&mrentry->key, id, flags, edns);
|
||||
}
|
||||
@@ -327,7 +559,7 @@ answer_from_cache(struct worker* worker, struct lruhash_entry* e, uint16_t id,
|
||||
* is bad while holding locks. */
|
||||
rrset_array_unlock_touch(worker->env.rrset_cache, worker->scratchpad,
|
||||
rep->ref, rep->rrset_count);
|
||||
region_free_all(worker->scratchpad);
|
||||
regional_free_all(worker->scratchpad);
|
||||
/* go and return this buffer to the client */
|
||||
return 1;
|
||||
}
|
||||
@@ -394,10 +626,11 @@ answer_chaos(struct worker* w, struct query_info* qinfo,
|
||||
if(cfg->hide_identity)
|
||||
return 0;
|
||||
if(cfg->identity==NULL || cfg->identity[0]==0) {
|
||||
char buf[MAXHOSTNAMELEN];
|
||||
if (gethostname(buf, MAXHOSTNAMELEN) == 0)
|
||||
char buf[MAXHOSTNAMELEN+1];
|
||||
if (gethostname(buf, MAXHOSTNAMELEN) == 0) {
|
||||
buf[MAXHOSTNAMELEN] = 0;
|
||||
chaos_replystr(pkt, buf, edns);
|
||||
else {
|
||||
} else {
|
||||
log_err("gethostname: %s", strerror(errno));
|
||||
chaos_replystr(pkt, "no hostname", edns);
|
||||
}
|
||||
@@ -420,8 +653,7 @@ answer_chaos(struct worker* w, struct query_info* qinfo,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** handles callbacks from listening event interface */
|
||||
static int
|
||||
int
|
||||
worker_handle_request(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* repinfo)
|
||||
{
|
||||
@@ -433,7 +665,8 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
|
||||
struct edns_data edns;
|
||||
|
||||
if(error != NETEVENT_NOERROR) {
|
||||
log_err("handle request called with err=%d", error);
|
||||
/* some bad tcp query DNS formats give these error calls */
|
||||
verbose(VERB_ALGO, "handle request called with err=%d", error);
|
||||
return 0;
|
||||
}
|
||||
if((ret=worker_check_request(c->buffer, worker)) != 0) {
|
||||
@@ -494,6 +727,8 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
|
||||
LDNS_RCODE_SET(ldns_buffer_begin(c->buffer),
|
||||
LDNS_RCODE_SERVFAIL);
|
||||
ldns_buffer_set_position(c->buffer, LDNS_HEADER_SIZE);
|
||||
ldns_buffer_write_at(c->buffer, 4,
|
||||
(uint8_t*)"\0\0\0\0\0\0\0\0", 8);
|
||||
ldns_buffer_flip(c->buffer);
|
||||
return 1;
|
||||
}
|
||||
@@ -501,7 +736,6 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
|
||||
edns.udp_size = 65535; /* max size for TCP replies */
|
||||
if(qinfo.qclass == LDNS_RR_CLASS_CH && answer_chaos(worker, &qinfo,
|
||||
&edns, c->buffer)) {
|
||||
verbose(VERB_ALGO, "class CH reply");
|
||||
return 1;
|
||||
}
|
||||
h = query_info_hash(&qinfo);
|
||||
@@ -514,63 +748,63 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
|
||||
lock_rw_unlock(&e->lock);
|
||||
return 1;
|
||||
}
|
||||
verbose(VERB_DETAIL, "answer from the cache -- data has timed out");
|
||||
verbose(VERB_ALGO, "answer from the cache failed");
|
||||
lock_rw_unlock(&e->lock);
|
||||
}
|
||||
if(!LDNS_RD_WIRE(ldns_buffer_begin(c->buffer))) {
|
||||
if(answer_norec_from_cache(worker, &qinfo,
|
||||
*(uint16_t*)ldns_buffer_begin(c->buffer),
|
||||
ldns_buffer_read_u16_at(c->buffer, 2), repinfo,
|
||||
&edns)) {
|
||||
return 1;
|
||||
}
|
||||
verbose(VERB_ALGO, "answer norec from cache -- "
|
||||
"need to validate or not primed");
|
||||
}
|
||||
ldns_buffer_rewind(c->buffer);
|
||||
server_stats_querymiss(&worker->stats, worker);
|
||||
|
||||
/* grab a work request structure for this new request */
|
||||
if(worker->env.mesh->all.count > worker->request_size) {
|
||||
/* we could get this due to a slow tcp incoming query,
|
||||
that started before we performed listen_pushback */
|
||||
verbose(VERB_DETAIL, "worker: too many incoming requests "
|
||||
"active. dropping incoming query.");
|
||||
verbose(VERB_ALGO, "currently servicing %d of %d queries",
|
||||
(int)worker->env.mesh->all.count,
|
||||
(int)worker->request_size);
|
||||
verbose(VERB_ALGO, "Too many requests active. "
|
||||
"dropping incoming query.");
|
||||
worker->stats.num_query_list_exceeded++;
|
||||
comm_point_drop_reply(repinfo);
|
||||
query_info_clear(&qinfo);
|
||||
return 0;
|
||||
}
|
||||
mesh_new_client(worker->env.mesh, &qinfo,
|
||||
ldns_buffer_read_u16_at(c->buffer, 2),
|
||||
&edns, repinfo, *(uint16_t*)ldns_buffer_begin(c->buffer));
|
||||
|
||||
if(worker->env.mesh->all.count == worker->request_size) {
|
||||
/* the max request number has been reached, stop accepting */
|
||||
listen_pushback(worker->front);
|
||||
}
|
||||
worker_mem_report(worker);
|
||||
worker_mem_report(worker, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** worker signal callback */
|
||||
void
|
||||
worker_sighandler(int sig, void* arg)
|
||||
{
|
||||
/* note that log, print, syscalls here give race conditions. */
|
||||
/* we still print DETAIL logs, because this is extensive per message
|
||||
* logging anyway, and the operator may then have an interest
|
||||
* in the cause for unbound to exit */
|
||||
struct worker* worker = (struct worker*)arg;
|
||||
switch(sig) {
|
||||
case SIGHUP:
|
||||
log_info("caught signal SIGHUP");
|
||||
worker->need_to_restart = 1;
|
||||
verbose(VERB_DETAIL, "caught signal SIGHUP");
|
||||
comm_base_exit(worker->base);
|
||||
break;
|
||||
case SIGINT:
|
||||
log_info("caught signal SIGINT");
|
||||
worker->need_to_restart = 0;
|
||||
verbose(VERB_DETAIL, "caught signal SIGINT");
|
||||
worker->need_to_exit = 1;
|
||||
comm_base_exit(worker->base);
|
||||
break;
|
||||
case SIGQUIT:
|
||||
log_info("caught signal SIGQUIT");
|
||||
worker->need_to_restart = 0;
|
||||
verbose(VERB_DETAIL, "caught signal SIGQUIT");
|
||||
worker->need_to_exit = 1;
|
||||
comm_base_exit(worker->base);
|
||||
break;
|
||||
case SIGTERM:
|
||||
log_info("caught signal SIGTERM");
|
||||
worker->need_to_restart = 0;
|
||||
verbose(VERB_DETAIL, "caught signal SIGTERM");
|
||||
worker->need_to_exit = 1;
|
||||
comm_base_exit(worker->base);
|
||||
break;
|
||||
default:
|
||||
@@ -612,11 +846,11 @@ worker_create(struct daemon* daemon, int id)
|
||||
|
||||
int
|
||||
worker_init(struct worker* worker, struct config_file *cfg,
|
||||
struct listen_port* ports, size_t buffer_size, int do_sigs)
|
||||
struct listen_port* ports, int do_sigs)
|
||||
{
|
||||
unsigned int seed;
|
||||
int startport;
|
||||
worker->need_to_restart = 0;
|
||||
worker->need_to_exit = 0;
|
||||
worker->base = comm_base_create();
|
||||
if(!worker->base) {
|
||||
log_err("could not create event handling base");
|
||||
@@ -654,12 +888,15 @@ worker_init(struct worker* worker, struct config_file *cfg,
|
||||
(((unsigned int)worker->thread_num)<<17);
|
||||
/* shift thread_num so it does not match out pid bits */
|
||||
if(!ub_initstate(seed, worker->rndstate, RND_STATE_SIZE)) {
|
||||
seed = 0;
|
||||
log_err("could not init random numbers.");
|
||||
worker_delete(worker);
|
||||
return 0;
|
||||
}
|
||||
seed = 0;
|
||||
worker->front = listen_create(worker->base, ports,
|
||||
buffer_size, worker_handle_request, worker);
|
||||
cfg->msg_buffer_size, (int)cfg->incoming_num_tcp,
|
||||
worker_handle_request, worker);
|
||||
if(!worker->front) {
|
||||
log_err("could not create listening sockets");
|
||||
worker_delete(worker);
|
||||
@@ -668,29 +905,28 @@ worker_init(struct worker* worker, struct config_file *cfg,
|
||||
startport = cfg->outgoing_base_port +
|
||||
cfg->outgoing_num_ports * worker->thread_num;
|
||||
worker->back = outside_network_create(worker->base,
|
||||
buffer_size, (size_t)cfg->outgoing_num_ports, cfg->ifs,
|
||||
cfg->num_ifs, cfg->do_ip4, cfg->do_ip6, startport,
|
||||
cfg->do_tcp?cfg->outgoing_num_tcp:0,
|
||||
cfg->msg_buffer_size, (size_t)cfg->outgoing_num_ports,
|
||||
cfg->out_ifs, cfg->num_out_ifs, cfg->do_ip4, cfg->do_ip6,
|
||||
startport, cfg->do_tcp?cfg->outgoing_num_tcp:0,
|
||||
worker->daemon->env->infra_cache, worker->rndstate);
|
||||
if(!worker->back) {
|
||||
log_err("could not create outgoing sockets");
|
||||
worker_delete(worker);
|
||||
return 0;
|
||||
}
|
||||
outside_network_set_secondary_buffer(worker->back,
|
||||
worker->front->udp_buff);
|
||||
if(worker->thread_num != 0) {
|
||||
/* start listening to commands */
|
||||
if(!(worker->cmd_com=comm_point_create_local(worker->base,
|
||||
worker->cmd_recv_fd, buffer_size,
|
||||
worker->cmd_recv_fd, cfg->msg_buffer_size,
|
||||
worker_handle_control_cmd, worker))) {
|
||||
log_err("could not create control compt.");
|
||||
worker_delete(worker);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
worker->scratchpad = region_create_custom(malloc, free,
|
||||
65536, 8192, 32, 1);
|
||||
/* we use the msg_buffer_size as a good estimate for what the
|
||||
* user wants for memory usage sizes */
|
||||
worker->scratchpad = regional_create_custom(cfg->msg_buffer_size);
|
||||
if(!worker->scratchpad) {
|
||||
log_err("malloc failure");
|
||||
worker_delete(worker);
|
||||
@@ -701,8 +937,11 @@ worker_init(struct worker* worker, struct config_file *cfg,
|
||||
server_stats_init(&worker->stats);
|
||||
alloc_init(&worker->alloc, &worker->daemon->superalloc,
|
||||
worker->thread_num);
|
||||
alloc_set_id_cleanup(&worker->alloc, &worker_alloc_cleanup, worker);
|
||||
worker->env = *worker->daemon->env;
|
||||
worker->env.worker = worker;
|
||||
worker->env.send_packet = &worker_send_packet;
|
||||
worker->env.send_query = &worker_send_query;
|
||||
worker->env.alloc = &worker->alloc;
|
||||
worker->env.rnd = worker->rndstate;
|
||||
worker->env.scratch = worker->scratchpad;
|
||||
@@ -711,14 +950,13 @@ worker_init(struct worker* worker, struct config_file *cfg,
|
||||
worker->env.detach_subs = &mesh_detach_subs;
|
||||
worker->env.attach_sub = &mesh_attach_sub;
|
||||
worker->env.kill_sub = &mesh_state_delete;
|
||||
worker->env.query_done = &mesh_query_done;
|
||||
worker->env.walk_supers = &mesh_walk_supers;
|
||||
worker->env.detect_cycle = &mesh_detect_cycle;
|
||||
if(!worker->env.mesh) {
|
||||
worker->env.scratch_buffer = ldns_buffer_new(cfg->msg_buffer_size);
|
||||
if(!worker->env.mesh || !worker->env.scratch_buffer) {
|
||||
worker_delete(worker);
|
||||
return 0;
|
||||
}
|
||||
worker_mem_report(worker);
|
||||
worker_mem_report(worker, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -733,10 +971,12 @@ worker_delete(struct worker* worker)
|
||||
{
|
||||
if(!worker)
|
||||
return;
|
||||
mesh_stats(worker->env.mesh, "mesh has");
|
||||
if(worker->env.mesh)
|
||||
mesh_stats(worker->env.mesh, "mesh has");
|
||||
server_stats_log(&worker->stats, worker->thread_num);
|
||||
worker_mem_report(worker);
|
||||
worker_mem_report(worker, NULL);
|
||||
mesh_delete(worker->env.mesh);
|
||||
ldns_buffer_free(worker->env.scratch_buffer);
|
||||
listen_delete(worker->front);
|
||||
outside_network_delete(worker->back);
|
||||
comm_signal_delete(worker->comsig);
|
||||
@@ -753,7 +993,7 @@ worker_delete(struct worker* worker)
|
||||
close(worker->cmd_recv_fd);
|
||||
worker->cmd_recv_fd = -1;
|
||||
alloc_clear(&worker->alloc);
|
||||
region_destroy(worker->scratchpad);
|
||||
regional_destroy(worker->scratchpad);
|
||||
free(worker);
|
||||
}
|
||||
|
||||
@@ -790,7 +1030,8 @@ worker_send_query(uint8_t* qname, size_t qnamelen, uint16_t qtype,
|
||||
struct module_qstate* q)
|
||||
{
|
||||
struct worker* worker = q->env->worker;
|
||||
struct outbound_entry* e = (struct outbound_entry*)malloc(sizeof(*e));
|
||||
struct outbound_entry* e = (struct outbound_entry*)regional_alloc(
|
||||
q->region, sizeof(*e));
|
||||
if(!e)
|
||||
return NULL;
|
||||
e->qstate = q;
|
||||
@@ -799,8 +1040,15 @@ worker_send_query(uint8_t* qname, size_t qnamelen, uint16_t qtype,
|
||||
worker_handle_service_reply, e, worker->back->udp_buff,
|
||||
&outbound_entry_compare);
|
||||
if(!e->qsent) {
|
||||
free(e);
|
||||
return NULL;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
void
|
||||
worker_alloc_cleanup(void* arg)
|
||||
{
|
||||
struct worker* worker = (struct worker*)arg;
|
||||
slabhash_clear(&worker->env.rrset_cache->table);
|
||||
slabhash_clear(worker->env.msg_cache);
|
||||
}
|
||||
|
||||
+31
-7
@@ -57,7 +57,7 @@ struct config_file;
|
||||
struct daemon;
|
||||
struct listen_port;
|
||||
struct ub_randstate;
|
||||
struct region;
|
||||
struct regional;
|
||||
|
||||
/** size of table used for random numbers. large to be more secure. */
|
||||
#define RND_STATE_SIZE 256
|
||||
@@ -99,14 +99,14 @@ struct worker {
|
||||
|
||||
/** random() table for this worker. */
|
||||
struct ub_randstate* rndstate;
|
||||
/** do we need to restart (instead of exit) ? */
|
||||
int need_to_restart;
|
||||
/** do we need to restart or quit (on signal) */
|
||||
int need_to_exit;
|
||||
/** allocation cache for this thread */
|
||||
struct alloc_cache alloc;
|
||||
/** per thread statistics */
|
||||
struct server_stats stats;
|
||||
/** thread scratch region */
|
||||
struct region* scratchpad;
|
||||
/** thread scratch regional */
|
||||
struct regional* scratchpad;
|
||||
|
||||
/** module environment passed to modules, changed for this thread */
|
||||
struct module_env env;
|
||||
@@ -127,12 +127,11 @@ struct worker* worker_create(struct daemon* daemon, int id);
|
||||
* @param worker: worker to initialize, created with worker_create.
|
||||
* @param cfg: configuration settings.
|
||||
* @param ports: list of shared query ports.
|
||||
* @param buffer_size: size of datagram buffer.
|
||||
* @param do_sigs: if true, worker installs signal handlers.
|
||||
* @return: false on error.
|
||||
*/
|
||||
int worker_init(struct worker* worker, struct config_file *cfg,
|
||||
struct listen_port* ports, size_t buffer_size, int do_sigs);
|
||||
struct listen_port* ports, int do_sigs);
|
||||
|
||||
/**
|
||||
* Make worker work.
|
||||
@@ -193,4 +192,29 @@ struct outbound_entry* worker_send_query(uint8_t* qname, size_t qnamelen,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen,
|
||||
struct module_qstate* q);
|
||||
|
||||
/**
|
||||
* process control messages from the main thread.
|
||||
* @param c: comm point to read from.
|
||||
* @param arg: worker.
|
||||
* @param error: error status of comm point.
|
||||
* @param reply_info: not used.
|
||||
*/
|
||||
int worker_handle_control_cmd(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* reply_info);
|
||||
|
||||
/** handles callbacks from listening event interface */
|
||||
int worker_handle_request(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* repinfo);
|
||||
|
||||
/** process incoming replies from the network */
|
||||
int worker_handle_reply(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* reply_info);
|
||||
|
||||
/** process incoming serviced query replies from the network */
|
||||
int worker_handle_service_reply(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* reply_info);
|
||||
|
||||
/** cleanup the cache to remove all rrset IDs from it, arg is worker */
|
||||
void worker_alloc_cleanup(void* arg);
|
||||
|
||||
#endif /* DAEMON_WORKER_H */
|
||||
|
||||
@@ -5,3 +5,5 @@ from the University of California and from Verisign. The Java prototype
|
||||
was made in further cooperation with Geoff Sisson and Roy Arends from Nominet.
|
||||
|
||||
At NLnet Labs, Jelte Jansen and Mark Santcroos reviewed the unbound C sources.
|
||||
|
||||
Jakob Schlyter - for advice on secure settings, random numbers and blacklists.
|
||||
|
||||
+562
@@ -1,5 +1,567 @@
|
||||
3 December 2007: Wouter
|
||||
- Fixup building in a subdirectory. (for 0.7.2)
|
||||
|
||||
19 November 2007: Wouter
|
||||
- version 0.7.1:
|
||||
* includes tpkg fixes to kill daemons at end of test
|
||||
* includes NSEC/RRSIG not downcasing fixup from
|
||||
dnssec-bis-updates draft-06.
|
||||
* README file updated.
|
||||
* nice libevent not found error.
|
||||
* README talks about gnu make.
|
||||
- for 0.7.2:
|
||||
* fixup for donotq matching.
|
||||
|
||||
15 November 2007: Wouter
|
||||
- review fixups from Jelte.
|
||||
|
||||
14 November 2007: Wouter
|
||||
- testbed script does not recreate configure, since its in svn now.
|
||||
- fixup checkconf test so that it does not test
|
||||
/etc/unbound/unbound.conf.
|
||||
- tag 0.6.
|
||||
|
||||
13 November 2007: Wouter
|
||||
- remove debug print.
|
||||
- fixup testbound exit when LIBEVENT_SIGNAL_PROBLEM exists.
|
||||
|
||||
12 November 2007: Wouter
|
||||
- fixup signal handling where SIGTERM could be ignored if a SIGHUP
|
||||
arrives later on.
|
||||
- bugreports to unbound-bugs@nlnetlabs.nl
|
||||
- fixup testbound so it exits cleanly.
|
||||
- cleanup the caches on a reload, so that rrsetID numbers won't clash.
|
||||
|
||||
9 November 2007: Wouter
|
||||
- took ldns snapshot in repo.
|
||||
- default config file is /etc/unbound/unbound.conf.
|
||||
If it doesn't exist, it is installed with the doc/example.conf file.
|
||||
The file is not deleted on uninstall.
|
||||
- default listening is not all, but localhost interfaces.
|
||||
|
||||
8 November 2007: Wouter
|
||||
- Fixup chroot and drop user privileges.
|
||||
- new L root ip address in default hints.
|
||||
|
||||
1 November 2007: Wouter
|
||||
- Fixup of crash on reload, due to anchors in env not NULLed after
|
||||
dealloc during deinit.
|
||||
- Fixup of chroot call. Happens after privileges are dropped, so
|
||||
that checking the passwd entry still works.
|
||||
- minor touch up of clear() hashtable function.
|
||||
- VERB_DETAIL prints out what chdir, username, chroot is being done.
|
||||
- when id numbers run out, caches are cleared, as in design notes.
|
||||
Tested with a mock setup with very few bits in id, it worked.
|
||||
- harden-dnssec-stripped: yes is now default. It insists on dnssec
|
||||
data for trust anchors. Included tests for the feature.
|
||||
|
||||
31 October 2007: Wouter
|
||||
- cache-max-ttl config option.
|
||||
- building outside sourcedir works again.
|
||||
- defaults more secure:
|
||||
username: "unbound"
|
||||
chroot: "/etc/unbound"
|
||||
The operator can override them to be less secure ("") if necessary.
|
||||
- fix horrible oversight in sorting rrset references in a message,
|
||||
sort per reference key pointer, not on referencepointer itself.
|
||||
- pidfile: "/etc/unbound/unbound.pid" is now the default.
|
||||
- tests changed to reflect the updated default.
|
||||
- created hashtable clear() function that respects locks.
|
||||
|
||||
30 October 2007: Wouter
|
||||
- fixup assertion failure that relied on compressed names to be
|
||||
smaller than uncompressed names. A packet from comrite.com was seen
|
||||
to be compressed to a larger size. Added it as unit test.
|
||||
- quieter logging at low verbosity level for common tcp messages.
|
||||
- no greedy TTL update.
|
||||
|
||||
23 October 2007: Wouter
|
||||
- fixup (grand-)parent problem for dnssec-lameness detection.
|
||||
- fixup tests to do additional section processing for lame replies,
|
||||
since the detection needs that.
|
||||
- no longer trust in query section in reply during dnssec lame detect.
|
||||
- dnssec lameness does not make the server never ever queried, but
|
||||
non-preferred. If no other servers exist or answer, the dnssec lame
|
||||
server is used; the fastest dnssec lame server is chosen.
|
||||
- added test then when trust anchor cannot be primed (nodata), the
|
||||
insecure mode from unbound works.
|
||||
- Fixup max queries per thread, any more are dropped.
|
||||
|
||||
22 October 2007: Wouter
|
||||
- added donotquerylocalhost config option. Can be turned off for
|
||||
out test cases.
|
||||
- ISO C compat changes.
|
||||
- detect RA-no-AA lameness, as LAME.
|
||||
- DNSSEC-lameness detection, as LAME.
|
||||
See notes in requirements.txt for choices made.
|
||||
- tests for lameness detection.
|
||||
- added all to make test target; need unbound for fwd tests.
|
||||
- testbound does not pollute /etc/unbound.
|
||||
|
||||
19 October 2007: Wouter
|
||||
- added configure (and its files) to svn, so that the trunk is easier
|
||||
to use. ./configure, config.guess, config.sub, ltmain.sh,
|
||||
and config.h.in.
|
||||
- added yacc/lex generated files, util/configlexer.c,
|
||||
util/configparser.c util/configparser.h, to svn.
|
||||
- without lex no attempt to use it.
|
||||
- unsecure response validation collated into one block.
|
||||
- remove warning about const cast of cfgfile name.
|
||||
- outgoing-interfaces can be different from service interfaces.
|
||||
- ldns-src configure is done during unbound configure and
|
||||
ldns-src make is done during unbound make, and so inherits the
|
||||
make arguments from the unbound make invocation.
|
||||
- nicer error when libevent problem causes instant exit on signal.
|
||||
- read root hints from a root hint file (like BIND does).
|
||||
|
||||
18 October 2007: Wouter
|
||||
- addresses are logged with errors.
|
||||
- fixup testcode fake event to remove pending before callback
|
||||
since the callback may create new pending items.
|
||||
- tests updated because retries are now in iterator module.
|
||||
- ldns-testpkts code is checked for differences between unbound
|
||||
and ldns by makedist.sh.
|
||||
- ldns trunk from today added in svn repo for fallback in case
|
||||
no ldns is installed on the system.
|
||||
make download_ldns refreshes the tarball with ldns svn trunk.
|
||||
- ldns-src.tar.gz is used if no ldns is found on the system, and
|
||||
statically linked into unbound.
|
||||
- start of regional allocator code.
|
||||
- regional uses less memory and variables, simplified code.
|
||||
- remove of region-allocator.
|
||||
- alloc cache keeps a cache of recently released regional blocks,
|
||||
up to a maximum.
|
||||
- make unit test cleanly free memory.
|
||||
|
||||
17 October 2007: Wouter
|
||||
- fixup another cycle detect and ns-addr timeout resolution bug.
|
||||
This time by refusing delegations from the cache without addresses
|
||||
when resolving a mandatory-glue nameserver-address for that zone.
|
||||
We're going to have to ask a TLD server anyway; might as well be
|
||||
the TLD server for this name. And this resolves a lot of cases where
|
||||
the other nameserver names lead to cycles or are not available.
|
||||
- changed random generator from random(3) clone to arc4random wrapped
|
||||
for thread safety. The random generator is initialised with
|
||||
entropy from the system.
|
||||
- fix crash where failure to prime DNSKEY tried to print null pointer
|
||||
in the log message.
|
||||
- removed some debug prints, only verb_algo (4) enables them.
|
||||
- fixup test; new random generator took new paths; such as one
|
||||
where no scripted answer was available.
|
||||
- mark insecure RRs as insecure.
|
||||
- fixup removal of nonsecure items from the additional.
|
||||
- reduced timeout values to more realistic, 376 msec (262 msec has
|
||||
90% of roundtrip times, 512 msec has 99% of roundtrip times.)
|
||||
- server selection failover to next server after timeout (376 msec).
|
||||
|
||||
16 October 2007: Wouter
|
||||
- no malloc in log_hex.
|
||||
- assertions around system calls.
|
||||
- protect against gethostname without ending zero.
|
||||
- ntop output is null terminated by unbound.
|
||||
- pidfile content null termination
|
||||
- various snprintf use sizeof(stringbuf) instead of fixed constant.
|
||||
- changed loopdetect % 8 with & 0x7 since % can become negative for
|
||||
weird negative input and particular interpretation of integer math.
|
||||
- dname_pkt_copy checks length of result, to protect result buffers.
|
||||
prints an error, this should not happen. Bad strings should have
|
||||
been rejected earlier in the program.
|
||||
- remove a size_t underflow from msgreply size func.
|
||||
|
||||
15 October 2007: Wouter
|
||||
- nicer warning.
|
||||
- fix IP6 TCP, wrong definition check. With test package.
|
||||
- fixup the fact that the query section was not compressed to,
|
||||
the code was there but was called by value instead of by reference.
|
||||
And test for the case, uses xxd and nc.
|
||||
- more portable ip6 check for sockaddr types.
|
||||
|
||||
8 October 2007: Wouter
|
||||
- --disable-rpath option in configure for 64bit systems with
|
||||
several dynamic lib dirs.
|
||||
|
||||
7 October 2007: Wouter
|
||||
- fixup tests for no AD bit in non-DO queries.
|
||||
- test that makes sure AD bit is not set on non-DO query.
|
||||
|
||||
6 October 2007: Wouter
|
||||
- removed logfile open early. It did not have the proper permissions;
|
||||
it was opened as root instead of the user. And we cannot change user
|
||||
id yet, since chroot and bind ports need to be done.
|
||||
- callback checks for event callbacks done from mini_event. Because
|
||||
of deletions cannot do this from netevent. This means when using
|
||||
libevent the protection does not work on event-callbacks.
|
||||
- fixup too small reply (did not zero counts).
|
||||
- fixup reply no longer AD bit when query without DO bit.
|
||||
|
||||
5 October 2007: Wouter
|
||||
- function pointer whitelist.
|
||||
|
||||
4 October 2007: Wouter
|
||||
- overwrite sensitive random seed value after use.
|
||||
- switch to logfile very soon if not -d (console attached).
|
||||
- error messages do not reveal the trustanchor contents.
|
||||
- start work on function pointer whitelists.
|
||||
|
||||
3 October 2007: Wouter
|
||||
- fix for multiple empty nonterminals, after multiple DSes in the
|
||||
chain of trust.
|
||||
- mesh checks if modules are looping, and stops them.
|
||||
- refetch with CNAMEd nameserver address regression test added.
|
||||
- fixup line count bug in testcode, so testbound prints correct line
|
||||
number with parse errors.
|
||||
- unit test for multiple ENT case.
|
||||
- fix for cname out of validated unsec zone.
|
||||
- fixup nasty id=0 reuse. Also added assertions to detect its
|
||||
return (the assertion catches in the existing test cases).
|
||||
|
||||
1 October 2007: Wouter
|
||||
- skip F77, CXX, objC tests in configure step.
|
||||
- fixup crash in refetch glue after a CNAME.
|
||||
and protection against similar failures (with error print).
|
||||
|
||||
28 September 2007: Wouter
|
||||
- test case for unbound-checkconf, fixed so it also checks the
|
||||
interface: statements.
|
||||
|
||||
26 September 2007: Wouter
|
||||
- SIGHUP will reopen the log file.
|
||||
- Option to log to syslog.
|
||||
- please lint, fixup tests (that went to syslog on open, oops).
|
||||
- config check program.
|
||||
|
||||
25 September 2007: Wouter
|
||||
- tests for NSEC3. Fixup bitmap checks for NSEC3.
|
||||
- positive ANY response needs to check if wildcard expansion, and
|
||||
check that original data did not exist.
|
||||
- tests for NSEC3 that wrong use of OPTOUT is bad. For insecure
|
||||
delegation, for abuse of child zone apex nsec3.
|
||||
- create 0.5 release tag.
|
||||
|
||||
24 September 2007: Wouter
|
||||
- do not make test programs by default.
|
||||
- But 'make test' will perform all of the tests.
|
||||
- Advertise builtin select libevent alternative when no libevent
|
||||
is found.
|
||||
- signit can generate NSEC3 hashes, for generating tests.
|
||||
- multiple nsec3 paramaters in message test.
|
||||
- too high nsec3 iterations becomes insecure test.
|
||||
|
||||
21 September 2007: Wouter
|
||||
- fixup empty_DS_name allocated in wrong region (port DEC Alpha).
|
||||
- fixup testcode lock safety (port FreeBSD).
|
||||
- removes subscript has type char warnings (port Solaris 9).
|
||||
- fixup of field with format type to int (port MacOS/X intel).
|
||||
- added test for infinite loop case in nonRD answer validation.
|
||||
It was a more general problem, but hard to reproduce. When an
|
||||
unsigned rrset is being validated and the key fetched, the DS
|
||||
sequence is followed, but if the final name has no DS, then no
|
||||
proof is possible - the signature has been stripped off.
|
||||
|
||||
20 September 2007: Wouter
|
||||
- fixup and test for NSEC wildcard with empty nonterminals.
|
||||
- makedist.sh fixup for svn info.
|
||||
- acl features request in plan.
|
||||
- improved DS empty nonterminal handling.
|
||||
- compat with ANS nxdomain for empty nonterminals. Attempts the nodata
|
||||
proof anyway, which succeeds in ANS failure case.
|
||||
- striplab protection in case it becomes -1.
|
||||
- plans for static and blacklist config.
|
||||
|
||||
19 September 2007: Wouter
|
||||
- comments about non-packed usage.
|
||||
- plan for overload support in 0.6.
|
||||
- added testbound tests for a failed resolution from the logs
|
||||
and for failed prime when missing glue.
|
||||
- fixup so useless delegation points are not returned from the
|
||||
cache. Also the safety belt is used if priming fails to complete.
|
||||
- fixup NSEC rdata not to be lowercased, bind compat.
|
||||
|
||||
18 September 2007: Wouter
|
||||
- wildcard nsec3 testcases, and fixup to get correct wildcard name.
|
||||
- validator prints subtype classification for debug.
|
||||
|
||||
17 September 2007: Wouter
|
||||
- NSEC3 hash cache unit test.
|
||||
- validator nsec3 nameerror test.
|
||||
|
||||
14 September 2007: Wouter
|
||||
- nsec3 nodata proof, nods proof, wildcard proof.
|
||||
- nsec3 support for cname chain ending in noerror or nodata.
|
||||
- validator calls nsec3 proof routines if no NSECs prove anything.
|
||||
- fixup iterator bug where it stored the answer to a cname under
|
||||
the wrong qname into the cache. When prepending the cnames, the
|
||||
qname has to be reset to the original qname.
|
||||
|
||||
13 September 2007: Wouter
|
||||
- nsec3 find matching and covering, ce proof, prove namerror msg.
|
||||
|
||||
12 September 2007: Wouter
|
||||
- fixup of manual page warnings, like for NSD bugreport.
|
||||
- nsec3 work, config, max iterations, filter, and hash cache.
|
||||
|
||||
6 September 2007: Wouter
|
||||
- fixup to find libevent on mac port install.
|
||||
- fixup size_t vs unsigned portability in validator/sigcrypt.
|
||||
- please compiler on different platforms, for unreachable code.
|
||||
- val_nsec3 file.
|
||||
- pthread_rwlock type is optional, in case of old pthread libs.
|
||||
|
||||
5 September 2007: Wouter
|
||||
- cname, name error validator tests.
|
||||
- logging of qtype ANY works.
|
||||
- ANY type answers get RRSIG in answer section of replies (but not
|
||||
in other sections, unless DO bit is on).
|
||||
- testbound can replay a TCP query (set MATCH TCP in the QUERY).
|
||||
- DS and noDS referral validation test.
|
||||
- if you configure many trust anchors, parent trust anchors can
|
||||
securely deny existance of child trust anchors, if validated.
|
||||
- not all *.name NSECs are present because a wildcard was matched,
|
||||
and *.name NSECs can prove nodata for empty nonterminals.
|
||||
Also, for wildcard name NSECs, check they are not from the parent
|
||||
zone (for wildcarded zone cuts), and check absence of CNAME bit,
|
||||
for a nodata proof.
|
||||
- configure option for memory allocation debugging.
|
||||
- port configure option for memory allocation to solaris10.
|
||||
|
||||
4 September 2007: Wouter
|
||||
- fixup of Leakage warning when serviced queries processed multiple
|
||||
callbacks for the same query from the same server.
|
||||
- testbound removes config file from /tmp on failed exit.
|
||||
- fixup for referral cleanup of the additional section.
|
||||
- tests for cname, referral validation.
|
||||
- neater testbound tpkg output.
|
||||
- DNAMEs no longer match their apex when synthesized from the cache.
|
||||
- find correct signer name for DNAME responses.
|
||||
- wildcarded DNAME test and fixup code to detect.
|
||||
- prepend NSEC and NSEC3 rrsets in the iterator while chasing CNAMEs.
|
||||
So that wildcarded CNAMEs get their NSEC with them to the answer.
|
||||
- test for a CNAME to a DNAME to a CNAME to an answer, all from
|
||||
different domains, for key fetching and signature checking of
|
||||
CNAME'd messages.
|
||||
|
||||
3 September 2007: Wouter
|
||||
- Fixed error in iterator that would cause assertion failure in
|
||||
validator. CNAME to a NXDOMAIN response was collated into a response
|
||||
with both a CNAME and the NXDOMAIN rcode. Added a test that the
|
||||
rcode is changed to NOERROR (because of the CNAME).
|
||||
- timeout on tcp does not lead to spurious leakage detect.
|
||||
- account memory for name of lame zones, so that memory leakages does
|
||||
not show lame cache growth as a leakage growth.
|
||||
- config setting for lameness cache expressed in bytes, instead of
|
||||
number of entries.
|
||||
- tool too summarize allocations per code line.
|
||||
|
||||
31 August 2007: Wouter
|
||||
- can read bind trusted-keys { ... }; files, in a compatibility mode.
|
||||
- iterator should not detach target queries that it still could need.
|
||||
the protection against multiple outstanding queries is moved to a
|
||||
current_query num check.
|
||||
- validator nodata, positive, referral tests.
|
||||
- dname print can print '*' wildcard.
|
||||
|
||||
30 August 2007: Wouter
|
||||
- fixup override date config option.
|
||||
- config options to control memory usage.
|
||||
- caught bad free of un-alloced data in worker_send error case.
|
||||
- memory accounting for key cache (trust anchors and temporary cache).
|
||||
- memory accounting fixup for outside network tcp pending waits.
|
||||
- memory accounting fixup for outside network tcp callbacks.
|
||||
- memory accounting for iterator fixed storage.
|
||||
- key cache size and slabs config options.
|
||||
- lib crypto cleanups at exit.
|
||||
|
||||
29 August 2007: Wouter
|
||||
- test tool to sign rrsets for testing validator with.
|
||||
- added RSA and DSA test keys, public and private pairs, 512 bits.
|
||||
- default configuration is with validation enabled.
|
||||
Only a trust-anchor needs to be configured for DNSSEC to work.
|
||||
- do not convert to DER for DSA signature verification.
|
||||
- validator replay test file, for a DS to DNSKEY DSA key prime and
|
||||
positive response.
|
||||
|
||||
28 August 2007: Wouter
|
||||
- removed double use for udp buffers, that could fail,
|
||||
instead performs a malloc to do the backup.
|
||||
- validator validates referral messages, by validating all the rrsets
|
||||
and stores the rrsets in the cache. Further referral (nonRD queries)
|
||||
replies are made from the rrset cache directly. Unless unchecked
|
||||
rrsets are encountered, there are then validated.
|
||||
- enforce that signing is done by a parent domain (or same domain).
|
||||
- adjust TTL downwards if rrset TTL bigger than signature allows.
|
||||
- permissive mode feature, sets AD bit for secure, but bogus does
|
||||
not give servfail (bogus is changed into indeterminate).
|
||||
- optimization of rrset verification. rr canonical sorting is reused,
|
||||
for the same rrset. canonical rrset image in buffer is reused for
|
||||
the same signature.
|
||||
- if the rrset is too big (64k exactly + large owner name) the
|
||||
canonicalization routine will fail if it does not fit in buffer.
|
||||
- faster verification for large sigsets.
|
||||
- verb_detail mode reports validation failures, but not the entire
|
||||
algorithm for validation. Key prime failures are reported as
|
||||
verb_ops level.
|
||||
|
||||
27 August 2007: Wouter
|
||||
- do not garble the edns if a cache answer fails.
|
||||
- answer norecursive from cache if possible.
|
||||
- honor clean_additional setting when returning secure non-recursive
|
||||
referrals.
|
||||
- do not store referral in msg cache for nonRD queries.
|
||||
- store verification status in the rrset cache to speed up future
|
||||
verification.
|
||||
- mark rrsets indeterminate and insecure if they are found to be so.
|
||||
and store this in the cache.
|
||||
|
||||
24 August 2007: Wouter
|
||||
- message is bogus if unsecure authority rrsets are present.
|
||||
- val-clean-additional option, so you can turn it off.
|
||||
- move rrset verification out of the specific proof types into one
|
||||
routine. This makes the proof routines prettier.
|
||||
- fixup cname handling in validator, cname-to-positive and cname-to-
|
||||
nodata work.
|
||||
- Do not synthesize DNSKEY and DS responses from the rrset cache if
|
||||
the rrset is from the additional section. Signatures may have
|
||||
fallen off the packet, and cause validation failure.
|
||||
- more verbose signature date errors (with the date attached).
|
||||
- increased default infrastructure cache size. It is important for
|
||||
performance, and 1000 entries are only 212k (or a 400 k total cache
|
||||
size). To 10000 entries (for 2M entries, 4M cache size).
|
||||
|
||||
23 August 2007: Wouter
|
||||
- CNAME handling - move needs_validation to before val_new().
|
||||
val_new() setups the chase-reply to be an edited copy of the msg.
|
||||
new classification, and find signer can find for it.
|
||||
removal of unsigned crap from additional, and query restart for
|
||||
cname.
|
||||
- refuse to follow wildcarded DNAMEs when validating.
|
||||
But you can query for qtype ANY, or qtype DNAME and validate that.
|
||||
|
||||
22 August 2007: Wouter
|
||||
- bogus TTL.
|
||||
- review - use val_error().
|
||||
|
||||
21 August 2007: Wouter
|
||||
- ANY response validation.
|
||||
- store security status in cache.
|
||||
- check cache security status and either send the query to be
|
||||
validated, return the query to client, or send servfail to client.
|
||||
Sets AD bit on validated replies.
|
||||
- do not examine security status on an error reply in mesh_done.
|
||||
- construct DS, DNSKEY messages from rrset cache.
|
||||
- manual page entry for override-date.
|
||||
|
||||
20 August 2007: Wouter
|
||||
- validate and positive validation, positive wildcard NSEC validation.
|
||||
- nodata validation, nxdomain validation.
|
||||
|
||||
18 August 2007: Wouter
|
||||
- process DNSKEY response in FINDKEY state.
|
||||
|
||||
17 August 2007: Wouter
|
||||
- work on DS2KE routine.
|
||||
- val_nsec.c for validator NSEC proofs.
|
||||
- unit test for NSEC bitmap reading.
|
||||
- dname iswild and canonical_compare with unit tests.
|
||||
|
||||
16 August 2007: Wouter
|
||||
- DS sig unit test.
|
||||
- latest release libevent 1.3c and 1.3d have threading fixed.
|
||||
- key entry fixup data pointer and ttl absolute.
|
||||
- This makes a key-prime succeed in validator, with DS or DNSKEY as
|
||||
trust-anchor.
|
||||
- fixup canonical compare byfield routine, fix bug and also neater.
|
||||
- fixed iterator response type classification for queries of type
|
||||
ANY and NS.
|
||||
dig ANY gives sometimes NS rrset in AN and NS section, and parser
|
||||
removes the NS section duplicate. dig NS gives sometimes the NS
|
||||
in the answer section, as referral.
|
||||
- validator FINDKEY state.
|
||||
|
||||
15 August 2007: Wouter
|
||||
- crypto calls to verify signatures.
|
||||
- unit test for rrsig verification.
|
||||
|
||||
14 August 2007: Wouter
|
||||
- default outgoing ports changed to avoid port 2049 by default.
|
||||
This port is widely blocked by firewalls.
|
||||
- count infra lameness cache in memory size.
|
||||
- accounting of memory improved
|
||||
- outbound entries are allocated in the query region they are for.
|
||||
- extensive debugging for memory allocations.
|
||||
- --enable-lock-checks can be used to enable lock checking.
|
||||
- protect undefs in config.h from autoheaders ministrations.
|
||||
- print all received udp packets. log hex will print on multiple
|
||||
lines if needed.
|
||||
- fixed error in parser with backwards rrsig references.
|
||||
- mark cycle targets for iterator did not have CD flag so failed
|
||||
its task.
|
||||
|
||||
13 August 2007: Wouter
|
||||
- fixup makefile, if lexer is missing give nice error and do not
|
||||
mess up the dependencies.
|
||||
- canonical compare routine updated.
|
||||
- canonical hinfo compare.
|
||||
- printout list of the queries that the mesh is working on.
|
||||
|
||||
10 August 2007: Wouter
|
||||
- malloc and free overrides that track total allocation and frees.
|
||||
for memory debugging.
|
||||
- work on canonical sort.
|
||||
|
||||
9 August 2007: Wouter
|
||||
- canonicalization, signature checks
|
||||
- dname signature label count and unit test.
|
||||
- added debug heap size print to memory printout.
|
||||
- typo fixup in worker.c
|
||||
- -R needed on solaris.
|
||||
- validator override option for date check testing.
|
||||
|
||||
8 August 2007: Wouter
|
||||
- ldns _raw routines created (in ldns trunk).
|
||||
- sigcrypt DS digest routines
|
||||
- val_utils uses sigcrypt to perform signature cryptography.
|
||||
- sigcrypt keyset processing
|
||||
|
||||
7 August 2007: Wouter
|
||||
- security status type.
|
||||
- security status is copied when rdata is equal for rrsets.
|
||||
- rrset id is updated to invalidate all the message cache entries
|
||||
that refer to NSEC, NSEC3, DNAME rrsets that have changed.
|
||||
- val_util work
|
||||
- val_sigcrypt file for validator signature checks.
|
||||
|
||||
6 August 2007: Wouter
|
||||
- key cache for validator.
|
||||
- moved isroot and dellabel to own dname routines, with unit test.
|
||||
|
||||
3 August 2007: Wouter
|
||||
- replanning.
|
||||
- scrubber check section of lame NS set.
|
||||
- trust anchors can be in config file or read from zone file,
|
||||
DS and DNSKEY entries.
|
||||
- unit test trust anchor storage.
|
||||
- trust anchors converted to packed rrsets.
|
||||
- key entry definition.
|
||||
|
||||
2 August 2007: Wouter
|
||||
- configure change for latest libevent trunk version (needs -lrt).
|
||||
- query_done and walk_supers are moved out of module interface.
|
||||
- fixup delegation point duplicates.
|
||||
- fixup iterator scrubber; lame NS set is let through the scrubber
|
||||
so that the classification is lame.
|
||||
- validator module exists, and does nothing but pass through,
|
||||
with calling of next module and return.
|
||||
- validator work.
|
||||
|
||||
1 August 2007: Wouter
|
||||
- set version to 0.5
|
||||
- module work for module to module interconnections.
|
||||
- config of modules.
|
||||
- detect cycle takes flags.
|
||||
|
||||
31 July 2007: Wouter
|
||||
- updated plan
|
||||
- release 0.4 tag.
|
||||
|
||||
30 July 2007: Wouter
|
||||
- changed random state init, so that sequential process IDs are not
|
||||
|
||||
+22
-4
@@ -9,29 +9,47 @@ This software is under BSD license, see LICENSE for details.
|
||||
or get a beta version from the svn repository at
|
||||
http://unbound.net/svn/
|
||||
|
||||
* Needs the following libraries
|
||||
* Uses the following libraries;
|
||||
* ldns http://www.nlnetlabs.nl/ldns/ (BSD license)
|
||||
* libevent http://www.monkey.org/~provos/libevent/ (BSD license)
|
||||
|
||||
* Create build environment
|
||||
* run libtoolize -c if config.sub is missing.
|
||||
* run libtoolize -c if config.sub is missing, or run glibtoolize.
|
||||
* autoreconf (autoheader && autoconf), if ./configure is missing.
|
||||
|
||||
* Make and install: ./configure; make; make install
|
||||
* Use GNU make; default on linux, often called 'gmake' on BSD and Solaris.
|
||||
* --with-ldns=/path/to/ldns
|
||||
If ldns is not detected on the system, a prepackaged tarball
|
||||
of the ldns library is used to compile and statically link against.
|
||||
If detected on the system, it will dynamically link against it.
|
||||
* --with-libevent=/path/to/libevent
|
||||
Can be set to either the system install or the build directory.
|
||||
--with-libevent=no gives a builtin alternative implementation.
|
||||
libevent is useful when having many (thousands) of outgoing ports.
|
||||
This improves randomization and spoof resistance. For the default
|
||||
of 16 ports the builtin alternative works well.
|
||||
* --without-pthreads
|
||||
This disables pthreads, and uses Solaris thr library or no threading.
|
||||
Without this option the pthreads library is detected automatically.
|
||||
* --enable-static-exe
|
||||
This enables a debug option to statically link, against ldns and
|
||||
libevent libraries.
|
||||
* --enable-lock-checks
|
||||
This enables a debug option to check lock and unlock calls. It needs
|
||||
a recent pthreads library to work.
|
||||
* --enable-alloc-checks
|
||||
This enables a debug option to check malloc (calloc, realloc, free).
|
||||
The server periodically checks if the amount of memory used fits with
|
||||
the amount of memory it thinks it should be using, and reports
|
||||
memory usage in detail.
|
||||
|
||||
* 'make test' attempts to run a series of tests, depending on the support
|
||||
programs that are installed.
|
||||
|
||||
Known issues
|
||||
------------
|
||||
o If libevent is older (1.3 and before), unbound will exit instead of reload
|
||||
o If libevent is older (before 1.3c), unbound will exit instead of reload
|
||||
on sighup. On a restart 'did not exit gracefully last time' warning is
|
||||
printed. Perform ./configure --with-libevent=no or update libevent, rerun
|
||||
configure and recompile unbound to make sighup work correctly.
|
||||
@@ -45,4 +63,4 @@ o Other code origins are from the NSD (NLnet Labs) and LDNS (NLnet Labs)
|
||||
projects. Such as buffer, region-allocator and red-black tree code.
|
||||
o See Credits file for contributors.
|
||||
|
||||
* mailto:wouter@nlnetlabs.nl
|
||||
* mailto:unbound-bugs@nlnetlabs.nl
|
||||
|
||||
+5
-2
@@ -1,6 +1,9 @@
|
||||
README unbound tests
|
||||
|
||||
There is a test setup for unbound.
|
||||
There is a test setup for unbound. Use
|
||||
make test
|
||||
To make and run the tests. The results are summarized at the end.
|
||||
You can also run ./unittest by hand, if the system lacks other debug tools.
|
||||
|
||||
testdata/ contains the data for tests.
|
||||
testcode/ contains scripts and c code for the tests.
|
||||
@@ -8,4 +11,4 @@ testcode/ contains scripts and c code for the tests.
|
||||
do-tests.sh : runs all the tests in the testdata directory.
|
||||
testbed.sh : compiles on a set of (user specific) hosts and runs do-tests.
|
||||
|
||||
Tests are run using tpkg.
|
||||
Tests are run using testcode/mini_tpkg.sh.
|
||||
|
||||
@@ -23,8 +23,36 @@ o memory profile; and if needed put serviced queries under qstate->region
|
||||
o check query, option to enforce presence of qdsection in noerror answers.
|
||||
o configuration option where port 53 is used for send and receive, no other
|
||||
ports are used.
|
||||
o prime sequence in multiple queries, if glue missing from prime sequence.
|
||||
o (option) to not send replies to clients after a timeout of (say 5 secs) has
|
||||
passed, but keep task active for later retries by client.
|
||||
o private TTL feature
|
||||
o pretend-dnssec-unaware, and pretend-edns-unaware modes for debug/workshops.
|
||||
o delegpt use rbtree for ns-list, to avoid slowdown for very large NS sets.
|
||||
o be able to have different listen and query-to addresses to bind to,
|
||||
so you can listen to localhost and query-to to the internet.
|
||||
o reprime and refresh oft used data before timeout.
|
||||
o retain prime results in a overlaid roothints file.
|
||||
o store primed key data in a overlaid keyhints file (sort of like drafttimers).
|
||||
o windows version, auto update feature, a query to check for the version.
|
||||
o autoreport of problems
|
||||
o logrotation, syslog
|
||||
o command the server with TSIG inband. get-config, clearcache,
|
||||
get stats, get memstats, get ..., reload, clear one zone from cache
|
||||
o watch for spoof nearmisses.
|
||||
o improve compression of DNS packets by first puttig uncompressible rrs, then
|
||||
compress to their rdata.
|
||||
o if one server is not responsive do not spend 75 secs on that server, but
|
||||
try other servers with lower rtt.
|
||||
o NSID rfc 5001 support.
|
||||
o timers rfc 5011 support.
|
||||
o Treat YXDOMAIN from a DNAME properly, in iterator (not throwaway), validator.
|
||||
o grab ports nonconsequtive and change the set after a while (change within
|
||||
a given range). Could be bad for OS if wrong port. unsure if it helps secure.
|
||||
o make timeout backoffs randomized (a couple percent random) to spread traffic.
|
||||
o inspect date on executable, then warn user in log if its more than 1 year.
|
||||
o proactively prime root, stubs and trust anchors, feature.
|
||||
early failure, faster on first query, but more traffic.
|
||||
o use privilege separation, to change privilege options during reload securely
|
||||
not needed.
|
||||
o check if for PowerDNS(2.9.21) CNAME in Answer section & rcode=NXDOMAIN needs
|
||||
to be fixed up to be rcode=NOERROR?
|
||||
|
||||
+112
-13
@@ -13,14 +13,16 @@ server:
|
||||
# whitespace is not necessary, but looks cleaner.
|
||||
|
||||
# verbosity number, 0 is least verbose. 1 is default.
|
||||
verbosity: 2
|
||||
|
||||
verbosity: 1
|
||||
|
||||
# number of threads to create. 1 disables threading.
|
||||
# num-threads: 1
|
||||
|
||||
# specify the interfaces to answer queries from by ip-address.
|
||||
# If you give none the default (all) interface is used.
|
||||
# The default is to listen to localhost (127.0.0.1 and ::1).
|
||||
# specify 0.0.0.0 and ::0 to bind to all available interfaces.
|
||||
# specify every interface on a new 'interface:' labelled line.
|
||||
# The listen interfaces are not changed on reload, only on restart.
|
||||
# interface: 192.0.2.153
|
||||
# interface: 192.0.2.154
|
||||
# interface: 2001:DB8::5
|
||||
@@ -28,6 +30,13 @@ server:
|
||||
# port to answer queries from
|
||||
# port: 53
|
||||
|
||||
# specify the interfaces to send outgoing queries to authoritative
|
||||
# server from by ip-address. If none, the default (all) interface
|
||||
# is used. Specify every interface on a 'outgoing-interface:' line.
|
||||
# outgoing-interface: 192.0.2.153
|
||||
# outgoing-interface: 2001:DB8::5
|
||||
# outgoing-interface: 2001:DB8::6
|
||||
|
||||
# unbound needs to send packets to authoritative nameservers.
|
||||
# it uses a range of ports for that.
|
||||
# the start number of the port range
|
||||
@@ -42,6 +51,13 @@ server:
|
||||
# number of outgoing simultaneous tcp buffers to hold per thread.
|
||||
# outgoing-num-tcp: 10
|
||||
|
||||
# number of incoming simultaneous tcp buffers to hold per thread.
|
||||
# incoming-num-tcp: 10
|
||||
|
||||
# buffer size for handling DNS data. No messages larger than this
|
||||
# size can be sent or received, by UDP or TCP. In bytes.
|
||||
# msg-buffer-size: 65552
|
||||
|
||||
# the amount of memory to use for the message cache.
|
||||
# in bytes. default is 4 Mb
|
||||
# msg-cache-size: 4194304
|
||||
@@ -62,6 +78,10 @@ server:
|
||||
# the number of slabs must be a power of 2.
|
||||
# more slabs reduce lock contention, but fragment memory usage.
|
||||
# rrset-cache-slabs: 4
|
||||
|
||||
# the time to live (TTL) value cap for RRsets and messages in the
|
||||
# cache. Items are not cached for longer. In seconds.
|
||||
# cache-max-ttl: 864000
|
||||
|
||||
# the time to live (TTL) value for cached roundtrip times and
|
||||
# EDNS version information for hosts. In seconds.
|
||||
@@ -76,10 +96,10 @@ server:
|
||||
# infra-cache-slabs: 4
|
||||
|
||||
# the maximum number of hosts that are cached (roundtrip times, EDNS).
|
||||
# infra-cache-numhosts: 1000
|
||||
# infra-cache-numhosts: 10000
|
||||
|
||||
# the maximum number of lame zones per host that are cached.
|
||||
# infra-cache-numlame: 1000
|
||||
# the maximum size of the lame zones cached per host. in bytes.
|
||||
# infra-cache-lame-size: 10240
|
||||
|
||||
# Enable IPv4, "yes" or "no".
|
||||
# do-ip4: yes
|
||||
@@ -96,20 +116,31 @@ server:
|
||||
# if given, a chroot(2) is done to the given directory.
|
||||
# i.e. you can chroot to the working directory, for example,
|
||||
# for extra security, but make sure all files are in that directory.
|
||||
# chroot: "/some/directory"
|
||||
# If you give "" no chroot is performed.
|
||||
# chroot: "/etc/unbound"
|
||||
|
||||
# if given, user privileges are dropped (after binding port),
|
||||
# and the given username is assumed. Default is nothing "".
|
||||
# and the given username is assumed. Default is user "unbound".
|
||||
# If you give "" no priviliges are dropped.
|
||||
# username: "unbound"
|
||||
|
||||
# the working directory.
|
||||
# directory: "/etc/unbound"
|
||||
|
||||
# the log file, "" means log to stderr.
|
||||
# the log file, "" means log to stderr.
|
||||
# Use of this option sets use-syslog to "no".
|
||||
# logfile: ""
|
||||
|
||||
# Log to syslog(3) if yes. The log facility LOG_DAEMON is used to
|
||||
# log to, with identity "unbound". If yes, it overrides the logfile.
|
||||
# use-syslog: yes
|
||||
|
||||
# the pid file.
|
||||
# pidfile: "unbound.pid"
|
||||
# pidfile: "/etc/unbound/unbound.pid"
|
||||
|
||||
# file to read root hints from.
|
||||
# get one from ftp://FTP.INTERNIC.NET/domain/named.cache
|
||||
# root-hints: ""
|
||||
|
||||
# enable to not answer id.server and hostname.bind queries.
|
||||
# hide-identity: no
|
||||
@@ -142,11 +173,79 @@ server:
|
||||
# Harden against out of zone rrsets, to avoid spoofing attempts.
|
||||
# harden-glue: yes
|
||||
|
||||
# Harden against receiving dnssec-stripped data. If you turn it
|
||||
# off, failing to validate dnskey data for a trustanchor will
|
||||
# trigger insecure mode for that zone (like without a trustanchor).
|
||||
# Default on, which insists on dnssec data for trust-anchored zones.
|
||||
# harden-dnssec-stripped: yes
|
||||
|
||||
# Do not query the following addresses. No DNS queries are sent there.
|
||||
# List one address per entry. To block other ports than the default
|
||||
# DNS port, use "1.2.3.4@123" to block port 123 for 1.2.3.4.
|
||||
# do-not-query-address: 127.0.0.1
|
||||
# List one address per entry. List classless netblocks with /size,
|
||||
# do-not-query-address: 127.0.0.1/8
|
||||
# do-not-query-address: ::1
|
||||
|
||||
# if yes, the above default do-not-query-address entries are present.
|
||||
# if no, localhost can be queried (for testing and debugging).
|
||||
# do-not-query-localhost: yes
|
||||
|
||||
# module configuration of the server. A string with identifiers
|
||||
# separated by spaces. "iterator" or "validator iterator"
|
||||
# module-config: "validator iterator"
|
||||
|
||||
# File with trusted keys for validation. Specify more than one file
|
||||
# with several entries, one file per entry.
|
||||
# Zone file format, with DS and DNSKEY entries.
|
||||
# trust-anchor-file: ""
|
||||
|
||||
# Trusted key for validation. DS or DNSKEY. specify the RR on a
|
||||
# single line, surrounded by "". TTL is ignored. class is IN default.
|
||||
# (These examples are from August 2007 and may not be valid anymore).
|
||||
# trust-anchor: "nlnetlabs.nl. DNSKEY 257 3 5 AQPzzTWMz8qSWIQlfRnPckx2BiVmkVN6LPupO3mbz7FhLSnm26n6iG9N Lby97Ji453aWZY3M5/xJBSOS2vWtco2t8C0+xeO1bc/d6ZTy32DHchpW 6rDH1vp86Ll+ha0tmwyy9QP7y2bVw5zSbFCrefk8qCUBgfHm9bHzMG1U BYtEIQ=="
|
||||
# trust-anchor: "jelte.nlnetlabs.nl. DS 42860 5 1 14D739EB566D2B1A5E216A0BA4D17FA9B038BE4A"
|
||||
|
||||
# File with trusted keys for validation. Specify more than one file
|
||||
# with several entries, one file per entry. Like trust-anchor-file
|
||||
# but has a different file format. Format is BIND-9 style format,
|
||||
# the trusted-keys { name flag proto algo "key"; }; clauses are read.
|
||||
# trusted-keys-file: ""
|
||||
|
||||
# Override the date for validation with a specific fixed date.
|
||||
# Do not set this unless you are debugging signature inception
|
||||
# and expiration. "" or "0" turns the feature off.
|
||||
# val-override-date: ""
|
||||
|
||||
# The time to live for bogus data, rrsets and messages. This avoids
|
||||
# some of the revalidation, until the time interval expires. in secs.
|
||||
# val-bogus-ttl: 900
|
||||
|
||||
# Should additional section of secure message also be kept clean of
|
||||
# unsecure data. Useful to shield the users of this validator from
|
||||
# potential bogus data in the additional section. All unsigned data
|
||||
# in the additional section is removed from secure messages.
|
||||
# val-clean-additional: yes
|
||||
|
||||
# Turn permissive mode on to permit bogus messages. Thus, messages
|
||||
# for which security checks failed will be returned to clients,
|
||||
# instead of SERVFAIL. It still performs the security checks, which
|
||||
# result in interesting log files and possibly the AD bit in
|
||||
# replies if the message is found secure. The default is off.
|
||||
# val-permissive-mode: no
|
||||
|
||||
# It is possible to configure NSEC3 maximum iteration counts per
|
||||
# keysize. Keep this table very short, as linear search is done.
|
||||
# A message with an NSEC3 with larger count is marked insecure.
|
||||
# List in ascending order the keysize and count values.
|
||||
# val-nsec3-keysize-iterations: "1024 150 2048 500 4096 2500"
|
||||
|
||||
# the amount of memory to use for the key cache.
|
||||
# in bytes. default is 4 Mb
|
||||
# key-cache-size: 4194304
|
||||
|
||||
# the number of slabs to use for the key cache.
|
||||
# the number of slabs must be a power of 2.
|
||||
# more slabs reduce lock contention, but fragment memory usage.
|
||||
# key-cache-slabs: 4
|
||||
|
||||
|
||||
# Stub zones.
|
||||
# Create entries like below, to make all queries for 'example.com' and
|
||||
|
||||
@@ -30,16 +30,19 @@ Roughly the boxes are as follows:
|
||||
Twice as long; one box for module layout, one box for iterator module.
|
||||
0.5 Validator - validator module.
|
||||
0.6 Bigger and better - Operational useful features (config, log, memory)
|
||||
0.7 Local zones feature - localzones stubzones fwdzones, no leak rfc1918.
|
||||
0.7 Put to a limited audience.
|
||||
gamma/alpha core functionality test release, to a small audience.
|
||||
partial functionality. For more extensive use and testing.
|
||||
0.8 Local zones feature - localzones stubzones fwdzones, no leak rfc1918.
|
||||
views support; for selective recursive service.
|
||||
0.8 Library use - resolver validator lib (and test apps)
|
||||
0.9 Corner cases - be able to resolve in the wild. Run fuzzers.
|
||||
0.9 Library use - resolver validator lib (and test apps)
|
||||
0.10 Corner cases - be able to resolve in the wild. Run fuzzers.
|
||||
Run as many tests as we can think of.
|
||||
Go through logs and check for long, unresolved cases
|
||||
Use profiler.
|
||||
0.10 Beta release. Run shadow for a resolver in production for several
|
||||
0.11 Beta release. Run shadow for a resolver in production for several
|
||||
weeks.
|
||||
0.11 Features features
|
||||
0.12 Features features
|
||||
aggressive negative caching for NSEC, NSEC3.
|
||||
multiple queries per question, server exploration, server selection.
|
||||
option to use real entropy for randomness (mix it in once in a while).
|
||||
@@ -142,19 +145,63 @@ Styleguide:
|
||||
* Test resolver.
|
||||
* Speed test.
|
||||
|
||||
*** Put to a limited audience
|
||||
* The alpha/gamma core functionality, svn access to limited audience.
|
||||
* Support features and requests as they arise.
|
||||
* Provide real-world experiences.
|
||||
|
||||
*** Bigger and Better
|
||||
* Config file syntax checker program. Tests on checker.
|
||||
* Logging first class feature with config options.
|
||||
X with logfile turnover to avoid Gbs of logs.
|
||||
* use syslog optional.
|
||||
* donotqueryaddresses with trie for blocking entire netblocks.
|
||||
* Memory overhaul, special allocators for hashtable caches, and mesh qstates.
|
||||
* keep a preallocated list of region-chunks per worker thread.
|
||||
* allocate region struct and cleanup list in region itself; use
|
||||
linked list cleanup list. unit test on this. do not call region
|
||||
to avoid name-collision with nsd regions, 'regional'.
|
||||
* read root hints from file.
|
||||
* failover to next server in 1 second, instead of 100 seconds on one server.
|
||||
X failure to return answer, w. reason (donotq, noanswer servers, cannot
|
||||
find servers, validationfail w.classification, error),
|
||||
with threadno, starttime and endtime and qname/type/class, prime/qflags,
|
||||
from-clients, from-internal, has-subrequests, a nice error report,
|
||||
so that an excerpt from those times can be made from the logs.
|
||||
logfileparsing tool that makes these excerpts and emails them.
|
||||
Not done; user can change verbosity and kill -HUP.
|
||||
* clear cache as a callback from the new-rrset-id routine.
|
||||
X make overload mode work; phase 0 all ok, phase 1 some threads close ports,
|
||||
to let other threads pick up work. phase 2, all threads closed, so all open
|
||||
the ports again and drop all non-cache-reply queries.
|
||||
Keep mutexed num-overloaded-threads counter. thread incs it when it hits
|
||||
max number of user queries serviced in mesh. threads decs it when it
|
||||
falls below 90% of the max. if incs, and not all threads closed, phase 1,
|
||||
else, phase 2 start is broadcast over command pipes. if decs, open ports
|
||||
if phase 1, start servicing, phase is 0 again. Make robust against delays.
|
||||
readme: max about 1 second worth of incoming queries, 10k perhaps,
|
||||
or 1/number of seconds it takes start up of 10k.
|
||||
Not done. Implement drop when full.
|
||||
* the source includes a copy of the ldns lib for ease of building by
|
||||
new users. Detect system installed ldns, if installed ldns is OK; use
|
||||
dynamic linking against it, otherwise static linking against packaged ldns.
|
||||
* no greedy TTL algo (and test).
|
||||
* maximum TTL, cap incoming values, and config option.
|
||||
|
||||
*** Local zones feature.
|
||||
* Build in local zone features. First the total stop for1912.
|
||||
* Then 'local content' for minimal serving of localhost.localdomain,
|
||||
and so on.
|
||||
* Remember jakob's diagram.
|
||||
* views support, selective recursive service
|
||||
* Remember jakob's diagram. views support, selective recursive service:
|
||||
* acl for allowed recursion (RD=1), then drop or refused query.
|
||||
like 10.0.0.0/8 allow, 0.0.0.0/0 refuse, ... in-order.
|
||||
perhaps also, same list to disallow RD=0 access, like;
|
||||
allow_recursion, drop_recursion, refuse_recursion, drop_all
|
||||
* static answers for queries, fixed RRs from cfg, option
|
||||
query for that RR returns answer with that RR.
|
||||
* blacklist (return fixed nxdomain for domain and below), option
|
||||
can be used to block AS112 traffic, option to unblock a zone.
|
||||
* after checking acl, do iter: static, blacklist, forwards, recurse.
|
||||
* Forward-local-zone to NSD.
|
||||
- include in package, autoforkexec on localhost to do so.
|
||||
* forward local zone to remote server.
|
||||
@@ -181,6 +228,9 @@ Styleguide:
|
||||
* read a file with cache contents and settings, provide fake
|
||||
environment for module-handle-state-X functions, then check
|
||||
resulting module state structure to correct answer.
|
||||
* speed test cache responses.
|
||||
* using two servers, compare answer differences between bind and unbound.
|
||||
this gives false differences due to changes in the rest of internet.
|
||||
|
||||
*** Beta release.
|
||||
* Run shadow for a resolver in production for several weeks.
|
||||
@@ -194,10 +244,11 @@ Styleguide:
|
||||
* check query, enforce qdsection, checking for forgery-resilience.
|
||||
* NSID support.
|
||||
* support TSIG on queries, for validating resolver deployment.
|
||||
* Be able to prime roots using several queries (like, get only NS first).
|
||||
* Nicer statistics
|
||||
* private TTL, dTLS features.
|
||||
|
||||
* retry-mode, where a bogus result triggers a retry-mode query, where a list
|
||||
of responses over a time interval is collected, and each is validated.
|
||||
* draft-timers, DLV features.
|
||||
|
||||
treeshrew/
|
||||
validator/ *.c *.h
|
||||
@@ -254,10 +305,10 @@ treeshrew/
|
||||
unbound.c for validating caching recursive dns server.
|
||||
scheduler.c for the modules.
|
||||
|
||||
libunbound-all/
|
||||
libunbound/
|
||||
app linkable. Can be configged to do whatever,
|
||||
validator, iterator, validating iterator, forwarding stub.
|
||||
libunbound-fwd/
|
||||
libforwardbound/
|
||||
app linkable forwarding stub. Small lib.
|
||||
|
||||
ask_cachor/ *.c *.h
|
||||
|
||||
@@ -79,3 +79,99 @@ o An authoritative name server.
|
||||
o Too many Features.
|
||||
|
||||
|
||||
5. Choices
|
||||
----------
|
||||
o rfc2181 decourages duplicates RRs in RRsets. unbound does not create
|
||||
duplicates, but when presented with duplicates on the wire from the
|
||||
authoritative servers, does not perform duplicate removal.
|
||||
It does do some rrsig duplicate removal, in the msgparser, for dnssec qtype
|
||||
rrsig and any, because of special rrsig processing in the msgparser.
|
||||
o The harden-glue feature, when yes all out of zone glue is deleted, when
|
||||
no out of zone glue is used for further resolving, is more complicated
|
||||
than that, see below.
|
||||
Main points:
|
||||
* rfc2182 trust handling is used.
|
||||
* data is let through only in very specific cases
|
||||
* spoofability remains possible.
|
||||
Not all glue is let through (despite the name of the option). Only glue
|
||||
which is present in a delegation, of type A and AAAA, where the name is
|
||||
present in the NS record in the authority section is let through.
|
||||
The glue that is let through is stored in the cache (marked as 'from the
|
||||
additional section'). And will then be used for sending queries to. It
|
||||
will not be present in the reply to the client (if RD is off).
|
||||
A direct query for that name will attempt to get a msg into the message
|
||||
cache. Since A and AAAA queries are not synthesized by the unbound cache,
|
||||
this query will be (eventually) sent to the authoritative server and its
|
||||
answer will be put in the cache, marked as 'from the answer section' and
|
||||
thus remove the 'from the additional section' data, and this record is
|
||||
returned to the client.
|
||||
The message has a TTL smaller or equal to the TTL of the answer RR.
|
||||
If the cache memory is low; the answer RR may be dropped, and a glue
|
||||
RR may be inserted, within the message TTL time, and thus return the
|
||||
spoofed glue to a client. When the message expires, it is refetched and
|
||||
the cached RR is updated with the correct content.
|
||||
The server can be spoofed by getting it to visit a especially prepared
|
||||
domain. This domain then inserts an address for another authoritative
|
||||
server into the cache, when visiting that other domain, this address may
|
||||
then be used to send queries to. And fake answers may be returned.
|
||||
If the other domain is signed by DNSSEC, the fakes will be detected.
|
||||
|
||||
In summary, the harden glue feature presents a security risk if
|
||||
disabled. Disabling the feature leads to possible better performance
|
||||
as more glue is present for the recursive service to use. The feature
|
||||
is implemented so as to minimise the security risk, while trying to
|
||||
keep this performance gain.
|
||||
o The method by which dnssec-lameness is detected is not secure. DNSSEC lame
|
||||
is when a server has the zone in question, but lacks dnssec data, such as
|
||||
signatures. The method to detect dnssec lameness looks at nonvalidated
|
||||
data from the parent of a zone. This can be used, by spoofing the parent,
|
||||
to create a false sense of dnssec-lameness in the child, or a false sense
|
||||
or dnssec-non-lameness in the child. The first results in the server marked
|
||||
lame, and not used for 900 seconds, and the second will result in a
|
||||
validator failure (SERVFAIL again), when the query is validated later on.
|
||||
|
||||
Concluding, a spoof of the parent delegation can be used for many cases
|
||||
of denial of service. I.e. a completely different NS set could be returned,
|
||||
or the information withheld. All of these alterations can be caught by
|
||||
the validator if the parent is signed, and result in 900 seconds bogus.
|
||||
The dnssec-lameness detection is used to detect operator failures,
|
||||
before the validator will properly verify the messages.
|
||||
|
||||
Also for zones for which no chain of trust exists, but a DS is given by the
|
||||
parent, dnssec-lameness detection enables. This delivers dnnsec to our
|
||||
clients when possible (for client validators).
|
||||
|
||||
The following issue needs to be resolved:
|
||||
a server that serves both a parent and child zone, where
|
||||
parent is signed, but child is not. The server must not be marked
|
||||
lame for the parent zone, because the child answer is not signed.
|
||||
Instead of a false positive, we want false negatives; failure to
|
||||
detect dnssec-lameness is less of a problem than marking honest
|
||||
servers lame. dnssec-lameness is a config error and deserves the trouble.
|
||||
So, only messages that identify the zone are used to mark the zone
|
||||
lame. The zone is identified by SOA or NS RRsets in the answer/auth.
|
||||
That includes almost all negative responses and also A, AAAA qtypes.
|
||||
That would be most responses from servers.
|
||||
For referrals, delegations that add a single label can be checked to be
|
||||
from their zone, this covers most delegation-centric zones.
|
||||
|
||||
So possibly, for complicated setups, with multiple (parent-child) zones
|
||||
on a server, dnssec-lameness detection does not work - no dnssec-lameness
|
||||
is detected. Instead the zone that is dnssec-lame becomes bogus.
|
||||
|
||||
o authority features.
|
||||
This is a recursive server, and authority features are out of scope.
|
||||
However, some authority features are expected in a recursor. Things like
|
||||
localhost, reverse lookup for 127.0.0.1, or blocking AS112 traffic.
|
||||
Also redirection of domain names with fixed data is needed by service
|
||||
providers. Limited support is added specifically to address this.
|
||||
|
||||
Adding full authority support, requires much more code, and more complex
|
||||
maintenance.
|
||||
|
||||
The limited support allows adding some static data (for localhost and so),
|
||||
and to respond with a fixed rcode (NXDOMAIN) for domains (such as AS112).
|
||||
|
||||
You can put authority data on a separate server, and set the server in
|
||||
unbound.conf as stub for those zones, this allows clients to access data
|
||||
from the server without making unbound authoritative for the zones.
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
.\"
|
||||
.\" unbound-checkconf.8 -- unbound configuration checker manual
|
||||
.\"
|
||||
.\" Copyright (c) 2007, NLnet Labs. All rights reserved.
|
||||
.\"
|
||||
.\" See LICENSE for the license.
|
||||
.\"
|
||||
.\"
|
||||
.Dd @date@
|
||||
.Dt unbound-checkconf 8
|
||||
.Sh NAME
|
||||
unbound-checkconf
|
||||
.Nd Check unbound configuration file for errors.
|
||||
.Sh SYNOPSIS
|
||||
.Nm unbound-checkconf
|
||||
.Op Fl h
|
||||
.Op cfgfile
|
||||
.Sh DESCRIPTION
|
||||
.Ic Unbound-checkconf
|
||||
checks the configuration file for the
|
||||
.Xr unbound 8
|
||||
DNS resolver for syntax and other errors.
|
||||
The config file syntax is
|
||||
described in
|
||||
.Xr unbound.conf 5 .
|
||||
.Pp
|
||||
The available options are:
|
||||
.Bl -tag -width indent
|
||||
.It Fl h
|
||||
Show the version and commandline option help.
|
||||
.It cfgfile
|
||||
The config file to read with settings for unbound. It is checked.
|
||||
If omitted, the config file at the default location is checked.
|
||||
.Sh EXIT CODE
|
||||
The unbound-checkconf program exits with status code 1 on error,
|
||||
0 for a correct config file.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width indent
|
||||
.It Pa /etc/unbound/unbound.conf
|
||||
unbound configuration file.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr unbound.conf 5 ,
|
||||
.Xr unbound 8 .
|
||||
+6
-10
@@ -17,7 +17,6 @@ unbound
|
||||
.Op Fl d
|
||||
.Op Fl v
|
||||
.Op Fl c Ar cfgfile
|
||||
|
||||
.Sh DESCRIPTION
|
||||
.Ic Unbound
|
||||
is an implementation of a DNS resolver, that does caching and
|
||||
@@ -25,27 +24,24 @@ DNSSEC validation.
|
||||
.Pp
|
||||
The available options are:
|
||||
.Bl -tag -width indent
|
||||
|
||||
.It Fl h
|
||||
Show the version and commandline option help.
|
||||
|
||||
.It Fl c Ar cfgfile
|
||||
Set the config file to read with settings for unbound. The syntax is
|
||||
Set the config file with settings for unbound to read instead of the
|
||||
file at default location /etc/unbound/unbound.conf. The syntax is
|
||||
described in
|
||||
.Xr unbound.conf 5 .
|
||||
|
||||
.It Fl d
|
||||
Debug flag, do not fork into the background, but stay attached to the
|
||||
console.
|
||||
|
||||
console. This flag will also delay writing to the logfile until the
|
||||
thread-spawn time. So that most config and setup errors appear on stderr.
|
||||
.It Fl v
|
||||
Increase verbosity. If given multiple times, more information is logged.
|
||||
This is in addition to the verbosity (if any) from the config file.
|
||||
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr unbound.conf 5 .
|
||||
|
||||
.Xr unbound.conf 5 ,
|
||||
.Xr unbound-checkconf 8 .
|
||||
.Sh AUTHORS
|
||||
.Ic Unbound
|
||||
developers are mentioned in the CREDITS file in the distribution.
|
||||
|
||||
+189
-33
@@ -20,11 +20,13 @@ is used to configure
|
||||
.Xr unbound 8 .
|
||||
The file format has attributes and values. Some attributes have attributes inside them.
|
||||
The notation is: attribute: value.
|
||||
|
||||
.Pp
|
||||
Comments start with # and last to the end of line. Empty lines are
|
||||
ignored as is whitespace at the beginning of a line.
|
||||
|
||||
.El
|
||||
.Pp
|
||||
The utility
|
||||
.Xr unbound-checkconf 8
|
||||
can be used to check unbound.conf prior to usage.
|
||||
.Sh EXAMPLE
|
||||
An example config file is shown below. Copy this to /etc/unbound/unbound.conf
|
||||
and start the server with:
|
||||
@@ -37,32 +39,27 @@ Most settings are the defaults. Stop the server with:
|
||||
.fi
|
||||
Below is a minimal config file. The source distribution contains an extensive
|
||||
example.conf file with all the options.
|
||||
|
||||
.nf
|
||||
# unbound.conf(5) config file for unbound(8).
|
||||
server:
|
||||
directory: "/etc/unbound"
|
||||
username: unbound # make sure it can write to pidfile, logfile.
|
||||
username: unbound # make sure it can write to pidfile.
|
||||
chroot: "/etc/unbound"
|
||||
logfile: "/etc/unbound/unbound.log"
|
||||
# logfile: "/etc/unbound/unbound.log" #uncomment to use logfile.
|
||||
pidfile: "/etc/unbound/unbound.pid"
|
||||
# verbosity: 1 # uncomment and increase to get more logging.
|
||||
.fi
|
||||
|
||||
.El
|
||||
.Sh FILE FORMAT
|
||||
There must be whitespace between keywords. Attribute keywords end with a colon ':'. An attribute
|
||||
is followed by its containing attributes, or a value.
|
||||
|
||||
.Pp
|
||||
Files can be included using the
|
||||
.Ic include:
|
||||
directive. It can appear anywhere, and takes a single filename as an argument.
|
||||
Processing continues as if the text from the included file was copied into
|
||||
the config file at that point.
|
||||
|
||||
.Ss Server Options
|
||||
There may only be one
|
||||
These options are part of the
|
||||
.Ic server:
|
||||
clause.
|
||||
.Bl -tag -width indent
|
||||
@@ -78,8 +75,21 @@ The number of threads to create to serve clients. Use 1 for no threading.
|
||||
.It \fBport:\fR <port number>
|
||||
The port number, default 53, on which the server responds to queries.
|
||||
.It \fBinterface:\fR <ip address>
|
||||
Interface to use to connect to the network. Can be given multiple times to
|
||||
work on several interfaces. If none are given the default (all) is used.
|
||||
Interface to use to connect to the network. This interface is listened to
|
||||
for queries from clients, and answers to clients are given from it.
|
||||
Can be given multiple times to work on several interfaces. If none are
|
||||
given the default is to listen to localhost.
|
||||
The interfaces are not changed on a reload (kill -HUP) but only on restart.
|
||||
.It \fBoutgoing-interface:\fR <ip address>
|
||||
Interface to use to connect to the network. This interface is used to send
|
||||
queries to authoritative servers and receive their replies. Can be given
|
||||
multiple times to work on several interfaces. If none are given the
|
||||
default (all) is used. You can specify the same interfaces in
|
||||
.Ic interface:
|
||||
and
|
||||
.Ic outgoing-interface:
|
||||
lines, the interfaces are then used for both purposes. Outgoing queries are
|
||||
sent via a random outgoing interface to counter spoofing.
|
||||
.It \fBoutgoing-port:\fR <port number>
|
||||
The starting port number where the outgoing query port range is allocated.
|
||||
Default is 1053.
|
||||
@@ -91,6 +101,15 @@ extra resources from the operating system.
|
||||
.It \fBoutgoing-num-tcp:\fR <number>
|
||||
Number of outgoing TCP buffers to allocate per thread. Default is 10. If set
|
||||
to 0, or if do_tcp is "no", no TCP queries to authoritative servers are done.
|
||||
.It \fBincoming-num-tcp:\fR <number>
|
||||
Number of incoming TCP buffers to allocate per thread. Default is 10. If set
|
||||
to 0, or if do_tcp is "no", no TCP queries from clients are accepted.
|
||||
.It \fBmsg-buffer-size:\fR <number>
|
||||
Number of bytes size of the message buffers. Default is 65552 bytes, enough
|
||||
for 64 Kb packets, the maximum DNS message size. No message larger than this
|
||||
can be sent or received. Can be reduced to use less memory, but some requests
|
||||
for DNS data, such as for huge resource records, will result in a SERVFAIL
|
||||
reply to the client.
|
||||
.It \fBmsg-cache-size:\fR <number>
|
||||
Number of bytes size of the message cache. Default is 4 megabytes.
|
||||
.It \fBmsg-cache-slabs:\fR <number>
|
||||
@@ -99,11 +118,21 @@ Must be set to a power of 2. Setting (close) to the number of cpus is a
|
||||
reasonable guess.
|
||||
.It \fBnum-queries-per-thread:\fR <number>
|
||||
The number of queries that every thread will service simultaneously.
|
||||
If more queries arrive that need servicing, they are dropped. This forces
|
||||
the client to resend after a timeout; allowing the server time to work on
|
||||
the existing queries. Default 1024.
|
||||
.It \fBrrset-cache-size:\fR <number>
|
||||
Number of bytes size of the RRset cache. Default is 4 megabytes.
|
||||
.It \fBrrset-cache-slabs:\fR <number>
|
||||
Number of slabs in the RRset cache. Slabs reduce lock contention by threads.
|
||||
Must be set to a power of 2.
|
||||
.It \fBcache-max-ttl:\fR <seconds>
|
||||
Time to live maximum for RRsets and messages in the cache. Default is
|
||||
864000 seconds (10 days). If the maximum kicks in, responses to clients
|
||||
still get decrementing TTLs based on the original (larger) values.
|
||||
When the internal TTL expires, the cache item has expired.
|
||||
Can be set lower to force the resolver to query for data often, and not
|
||||
trust (very large) TTL values.
|
||||
.It \fBinfra-host-ttl:\fR <seconds>
|
||||
Time to live for entries in the host cache. The host cache contains
|
||||
roundtrip timing and EDNS support information. Default is 900.
|
||||
@@ -113,9 +142,11 @@ The time to live when a delegation is discovered to be lame. Default is 900.
|
||||
Number of slabs in the infrastructure cache. Slabs reduce lock contention
|
||||
by threads. Must be set to a power of 2.
|
||||
.It \fBinfra-cache-numhosts:\fR <number>
|
||||
Number of hosts for which information is cached. Default is 1000.
|
||||
.It \fBinfra-cache-numlame:\fR <number>
|
||||
Number of zones per host for which lameness is cached. Default is 1000.
|
||||
Number of hosts for which information is cached. Default is 10000.
|
||||
.It \fBinfra-cache-lame-size:\fR <number>
|
||||
Number of bytes that the lameness cache per host is allowed to use. Default
|
||||
is 10 kb, which gives maximum storage for a couple score zones, depending on
|
||||
the lame zone name lengths.
|
||||
.It \fBdo-ip4:\fR <yes or no>
|
||||
Enable or disable whether ip4 queries are answered. Default is yes.
|
||||
.It \fBdo-ip6:\fR <yes or no>
|
||||
@@ -125,11 +156,12 @@ Enable or disable whether UDP queries are answered. Default is yes.
|
||||
.It \fBdo-tcp:\fR <yes or no>
|
||||
Enable or disable whether TCP queries are answered. Default is yes.
|
||||
.It \fBchroot:\fR <directory>
|
||||
If given a chroot is done to the given directory. The default is none ("").
|
||||
If given a chroot is done to the given directory. The default is
|
||||
"/etc/unbound". If you give "" no chroot is performed.
|
||||
.It \fBusername:\fR <name>
|
||||
If given, after binding the port the user privileges are dropped. Default is
|
||||
not to change user, username: "".
|
||||
|
||||
"unbound". If you give username: "" no user change is performed.
|
||||
.Pp
|
||||
If this user is not capable of binding the
|
||||
port, reloads (by signal HUP) will still retain the opened ports.
|
||||
If you change the port number in the config file, and that new port number
|
||||
@@ -140,10 +172,31 @@ Sets the working directory for the program.
|
||||
If "" is given, logging goes to stderr, or nowhere once daemonized.
|
||||
The logfile is appended to, in the following format:
|
||||
[seconds since 1970] unbound[pid:tid]: type: message.
|
||||
If this option is given, the use-syslog is option is set to "no".
|
||||
The logfile is reopened (for append) when the config file is reread, on
|
||||
SIGHUP.
|
||||
.It \fBuse-syslog:\fR <yes or no>
|
||||
Sets unbound to send log messages to the syslogd, using
|
||||
.Xr syslog 3 .
|
||||
The log facility LOG_DAEMON is used, with identity "unbound".
|
||||
The logfile setting is overridden when use-syslog is turned on.
|
||||
The default is to log to syslog.
|
||||
.It \fBpidfile:\fR <filename>
|
||||
The process id is written to the file. Default is "unbound.pid". So,
|
||||
kill -HUP `cat /etc/unbound/unbound.pid` will trigger a reload,
|
||||
kill -QUIT `cat /etc/unbound/unbound.pid` will gracefully terminate.
|
||||
The process id is written to the file. Default is "/etc/unbound/unbound.pid".
|
||||
So,
|
||||
.nf
|
||||
kill -HUP `cat /etc/unbound/unbound.pid`
|
||||
.fi
|
||||
triggers a reload,
|
||||
.nf
|
||||
kill -QUIT `cat /etc/unbound/unbound.pid`
|
||||
.fi
|
||||
gracefully terminates.
|
||||
.It \fBroot-hints:\fR <filename>
|
||||
Read the root hints from this file. Default is nothing, using builtin hints
|
||||
for the IN class. The file has the format of zone files, with root
|
||||
nameserver names and addresses only. The default may become outdated,
|
||||
when servers change, therefore it is good practice to use a root-hints file.
|
||||
.It \fBhide-identity:\fR <yes or no>
|
||||
If enabled id.server and hostname.bind queries are refused.
|
||||
.It \fBidentity:\fR <string>
|
||||
@@ -158,13 +211,13 @@ version is returned.
|
||||
Set the target fetch policy used by unbound to determine if it should fetch
|
||||
nameserver target addresses opportunistically. The policy is described per
|
||||
dependency depth.
|
||||
|
||||
.Pp
|
||||
The number of values determines the maximum dependency depth
|
||||
that unbound will pursue in answering a query.
|
||||
A value of -1 means to fetch all targets opportunistically for that dependency
|
||||
depth. A value of 0 means to fetch on demand only. A positive value fetches
|
||||
that many targets opportunistically.
|
||||
|
||||
.Pp
|
||||
Enclose the list between quotes ("") and put spaces between numbers.
|
||||
The default is "3 2 1 0 0". Setting all zeroes, "0 0 0 0 0" gives behaviour
|
||||
closer to that of BIND 9, while setting "-1 -1 -1 -1 -1" gives behaviour
|
||||
@@ -179,12 +232,83 @@ wise to send these, and could be necessary for operation if TSIG or EDNS
|
||||
payload is very large.
|
||||
.It \fBharden-glue:\fR <yes or no>
|
||||
Will trust glue only if it is within the servers authority. Default is on.
|
||||
.It \fBharden-dnssec-stripped:\fR <yes or no>
|
||||
Require DNSSEC data for trust-anchored zones, if such data is absent,
|
||||
the zone becomes bogus. If turned off, and no DNSSEC data is received
|
||||
(or the DNSKEY data fails to validate), then the zone is made insecure,
|
||||
this behaves like there is no trust anchor. You could turn this off if
|
||||
you are sometimes behind an intrusive firewall (of some sort) that
|
||||
removes DNSSEC data from packets, or a zone changes from signed to
|
||||
unsigned to badly signed often. If turned off you run the risk of a
|
||||
downgrade attack that disables security for a zone. Default is on.
|
||||
.It \fBdo-not-query-address:\fR <IP address>
|
||||
Do not query the given IP address. Can be IP4 or IP6. By default the
|
||||
DNS port is blocked for that address. Appending the character '@' and then
|
||||
the portnumber will block other port numbers.
|
||||
Do not query the given IP address. Can be IP4 or IP6. Append /num to
|
||||
indicate a classless delegation netblock, for example like
|
||||
10.2.3.4/24 or 2001::11/64.
|
||||
.It \fBdo-not-query-localhost:\fR <yes or no>
|
||||
If yes, localhost is added to the do-not-query-address entries, both
|
||||
IP6 ::1 and IP4 127.0.0.1/8. If no, then localhost can be used to send
|
||||
queries to. Default is yes.
|
||||
.It \fBmodule-config:\fR <"module names">
|
||||
Module configuration, a list of module names separated by spaces, surround
|
||||
the string with quotes (""). The modules can be validator, iterator.
|
||||
Setting this to "iterator" will result in a non-validating server.
|
||||
Setting this to "validator iterator" will turn on DNSSEC validation.
|
||||
You must also set trust-anchors for validation to be useful.
|
||||
.It \fBtrust-anchor-file:\fR <filename>
|
||||
File with trusted keys for validation. Both DS and DNSKEY entries can appear
|
||||
in the file. The format of the file is the standard DNS Zone file format.
|
||||
Default is "", or no trust anchor file.
|
||||
.It \fBtrust-anchor:\fR <"Resource Record">
|
||||
A DS or DNSKEY RR for a key to use for validation. Multiple entries can be
|
||||
given to specify multiple trusted keys, in addition to the trust-anchor-files.
|
||||
The resource record is entered in the same format as 'dig' or 'drill' prints
|
||||
them, the same format as in the zone file. Has to be on a single line, with
|
||||
"" around it. A TTL can be specified for ease of cut and paste, but is ignored.
|
||||
A class can be specified, but class IN is default.
|
||||
.It \fBtrusted-keys-file:\fR <filename>
|
||||
File with trusted keys for validation. Specify more than one file
|
||||
with several entries, one file per entry. Like \fBtrust-anchor-file\fR
|
||||
but has a different file format. Format is BIND-9 style format,
|
||||
the trusted-keys { name flag proto algo "key"; }; clauses are read.
|
||||
.It \fBval-override-date:\fR <rrsig-style date spec>
|
||||
Default is "" or "0", which disables this debugging feature. If enabled by
|
||||
giving a RRSIG style date, that date is used for verifying RRSIG inception
|
||||
and expiration dates, instead of the current date. Do not set this unless
|
||||
you are debugging signature inception and expiration.
|
||||
.It \fBval-bogus-ttl:\fR <number>
|
||||
The time to live for bogus data. This is data that has failed validation;
|
||||
due to invalid signatures or other checks. The TTL from that data cannot be
|
||||
trusted, and this value is used instead. The value is in seconds, default 900.
|
||||
The time interval prevents repeated revalidation of bogus data.
|
||||
.It \fBval-clean-additional:\fR <yes or no>
|
||||
Instruct the validator to remove data from the additional section of secure
|
||||
messages that are not signed properly. Messages that are insecure, bogus,
|
||||
indeterminate or unchecked are not affected. Default is yes. Use this setting
|
||||
to protect the users that rely on this validator for authentication from
|
||||
protentially bad data in the additional section.
|
||||
.It \fBval-permissive-mode:\fR <yes or no>
|
||||
Instruct the validator to mark bogus messages as indeterminate. The security
|
||||
checks are performed, but if the result is bogus (failed security), the
|
||||
reply is not withheld from the client with SERVFAIL as usual. The client
|
||||
receives the bogus data. For messages that are found to be secure the AD bit
|
||||
is set in replies. Also logging is performed as for full validation.
|
||||
The default value is "no".
|
||||
.It \fBval-nsec3-keysize-iterations:\fR <"list of values">
|
||||
List of keysize and iteration count values, separated by spaces, surrounded
|
||||
by quotes. Default is "1024 150 2048 500 4096 2500". This determines the
|
||||
maximum allowed NSEC3 iteration count before a message is simply marked
|
||||
insecure instead of performing the many hashing iterations. The list must
|
||||
be in ascending order and have at least one entry. If you set it to
|
||||
"1024 65535" there is no restriction to NSEC3 iteration values.
|
||||
This table must be kept short; a very long list could cause slower operation.
|
||||
.It \fBkey-cache-size:\fR <number>
|
||||
Number of bytes size of the key cache. Default is 4 megabytes.
|
||||
.It \fBkey-cache-slabs:\fR <number>
|
||||
Number of slabs in the key cache. Slabs reduce lock contention by threads.
|
||||
Must be set to a power of 2. Setting (close) to the number of cpus is a
|
||||
reasonable guess.
|
||||
.El
|
||||
|
||||
.Ss Stub Zone Options
|
||||
There may be multiple
|
||||
.Ic stub-zone:
|
||||
@@ -199,7 +323,6 @@ Name of stub zone nameserver. Is itself resolved before it is used.
|
||||
IP address of stub zone nameserver. Can be IP 4 or IP 6.
|
||||
To use a nondefault port for DNS communication append '@' with the port number.
|
||||
.El
|
||||
|
||||
.Ss Forward Zone Options
|
||||
There may be multiple
|
||||
.Ic forward-zone:
|
||||
@@ -217,20 +340,53 @@ Name of server to forward to. Is itself resolved before it is used.
|
||||
IP address of server to forward to. Can be IP 4 or IP 6.
|
||||
To use a nondefault port for DNS communication append '@' with the port number.
|
||||
.El
|
||||
|
||||
.Sh MEMORY CONTROL EXAMPLE
|
||||
In the example config settings below memory usage is reduced. Some service
|
||||
levels are lower, notable very large data and a high TCP load are no longer
|
||||
supported. Very large data and high TCP loads are exceptional for the DNS.
|
||||
DNSSEC validation is enabled, just add trust anchors.
|
||||
If you do not have to worry about programs using more than 1 meg of memory,
|
||||
the below example is not for you. Use the defaults to receive full service.
|
||||
.Pp
|
||||
.nf
|
||||
# example settings that reduce memory usage
|
||||
server:
|
||||
num-threads: 1
|
||||
outgoing-num-tcp: 1 # this limits TCP service, uses less buffers.
|
||||
incoming-num-tcp: 1
|
||||
outgoing-range: 1 # uses less memory, but less port randomness.
|
||||
msg-buffer-size: 8192 # note this limits service, 'no huge stuff'.
|
||||
msg-cache-size: 102400 # 100 Kb.
|
||||
msg-cache-slabs: 1
|
||||
rrset-cache-size: 102400 # 100 Kb.
|
||||
rrset-cache-slabs: 1
|
||||
infra-cache-numhosts: 200
|
||||
infra-cache-numlame: 10
|
||||
key-cache-size: 102400 # 100 Kb.
|
||||
key-cache-slabs: 1
|
||||
num-queries-per-thread: 30
|
||||
target-fetch-policy: "2 1 0 0 0 0"
|
||||
harden-large-queries: "yes"
|
||||
harden-short-bufsize: "yes"
|
||||
do-ip6: no # save a bit of memory if not used.
|
||||
.fi
|
||||
.Sh FILES
|
||||
.Bl -tag -width indent
|
||||
.It Pa /etc/unbound
|
||||
default unbound working directory
|
||||
default unbound working directory and default
|
||||
.Xr chroot 2
|
||||
location.
|
||||
.It Pa unbound.conf
|
||||
unbound configuration file.
|
||||
.It Pa unbound.pid
|
||||
default unbound pidfile with process ID of the running daemon.
|
||||
.It Pa unbound.log
|
||||
unbound log file.
|
||||
unbound log file. default is to log to
|
||||
.Xr syslog 3 .
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr unbound 8
|
||||
.Xr unbound 8 ,
|
||||
.Xr unbound-checkconf 8 .
|
||||
.Sh AUTHORS
|
||||
.Ic Unbound
|
||||
was written by NLnet Labs. Please see CREDITS file
|
||||
|
||||
+2
-1
@@ -495,7 +495,8 @@ EXCLUDE = ./build \
|
||||
util/configparser.c \
|
||||
util/configparser.h \
|
||||
util/configlexer.c \
|
||||
util/locks.h
|
||||
util/locks.h \
|
||||
./ldns-src
|
||||
|
||||
# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
|
||||
# directories that are symbolic links (a Unix filesystem feature) are excluded
|
||||
|
||||
+31
-20
@@ -42,23 +42,24 @@
|
||||
#include "config.h"
|
||||
#include "iterator/iter_delegpt.h"
|
||||
#include "services/cache/dns.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/data/dname.h"
|
||||
#include "util/data/packed_rrset.h"
|
||||
#include "util/data/msgreply.h"
|
||||
#include "util/net_help.h"
|
||||
|
||||
struct delegpt*
|
||||
delegpt_create(struct region* region)
|
||||
delegpt_create(struct regional* region)
|
||||
{
|
||||
struct delegpt* dp=(struct delegpt*)region_alloc(region, sizeof(*dp));
|
||||
struct delegpt* dp=(struct delegpt*)regional_alloc(
|
||||
region, sizeof(*dp));
|
||||
if(!dp)
|
||||
return NULL;
|
||||
memset(dp, 0, sizeof(*dp));
|
||||
return dp;
|
||||
}
|
||||
|
||||
struct delegpt* delegpt_copy(struct delegpt* dp, struct region* region)
|
||||
struct delegpt* delegpt_copy(struct delegpt* dp, struct regional* region)
|
||||
{
|
||||
struct delegpt* copy = delegpt_create(region);
|
||||
struct delegpt_ns* ns;
|
||||
@@ -80,24 +81,31 @@ struct delegpt* delegpt_copy(struct delegpt* dp, struct region* region)
|
||||
}
|
||||
|
||||
int
|
||||
delegpt_set_name(struct delegpt* dp, struct region* region, uint8_t* name)
|
||||
delegpt_set_name(struct delegpt* dp, struct regional* region, uint8_t* name)
|
||||
{
|
||||
dp->namelabs = dname_count_size_labels(name, &dp->namelen);
|
||||
dp->name = region_alloc_init(region, name, dp->namelen);
|
||||
dp->name = regional_alloc_init(region, name, dp->namelen);
|
||||
return dp->name != 0;
|
||||
}
|
||||
|
||||
int
|
||||
delegpt_add_ns(struct delegpt* dp, struct region* region, uint8_t* name)
|
||||
delegpt_add_ns(struct delegpt* dp, struct regional* region, uint8_t* name)
|
||||
{
|
||||
struct delegpt_ns* ns = (struct delegpt_ns*)region_alloc(region,
|
||||
struct delegpt_ns* ns;
|
||||
size_t len;
|
||||
(void)dname_count_size_labels(name, &len);
|
||||
/* slow check for duplicates to avoid counting failures when
|
||||
* adding the same server as a dependency twice */
|
||||
if(delegpt_find_ns(dp, name, len))
|
||||
return 1;
|
||||
ns = (struct delegpt_ns*)regional_alloc(region,
|
||||
sizeof(struct delegpt_ns));
|
||||
if(!ns)
|
||||
return 0;
|
||||
ns->next = dp->nslist;
|
||||
ns->namelen = len;
|
||||
dp->nslist = ns;
|
||||
(void)dname_count_size_labels(name, &ns->namelen);
|
||||
ns->name = region_alloc_init(region, name, ns->namelen);
|
||||
ns->name = regional_alloc_init(region, name, ns->namelen);
|
||||
ns->resolved = 0;
|
||||
return 1;
|
||||
}
|
||||
@@ -117,7 +125,7 @@ delegpt_find_ns(struct delegpt* dp, uint8_t* name, size_t namelen)
|
||||
}
|
||||
|
||||
int
|
||||
delegpt_add_target(struct delegpt* dp, struct region* region,
|
||||
delegpt_add_target(struct delegpt* dp, struct regional* region,
|
||||
uint8_t* name, size_t namelen, struct sockaddr_storage* addr,
|
||||
socklen_t addrlen)
|
||||
{
|
||||
@@ -131,10 +139,10 @@ delegpt_add_target(struct delegpt* dp, struct region* region,
|
||||
}
|
||||
|
||||
int
|
||||
delegpt_add_addr(struct delegpt* dp, struct region* region,
|
||||
delegpt_add_addr(struct delegpt* dp, struct regional* region,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen)
|
||||
{
|
||||
struct delegpt_addr* a = (struct delegpt_addr*)region_alloc(region,
|
||||
struct delegpt_addr* a = (struct delegpt_addr*)regional_alloc(region,
|
||||
sizeof(struct delegpt_addr));
|
||||
if(!a)
|
||||
return 0;
|
||||
@@ -145,6 +153,7 @@ delegpt_add_addr(struct delegpt* dp, struct region* region,
|
||||
dp->usable_list = a;
|
||||
memcpy(&a->addr, addr, addrlen);
|
||||
a->addrlen = addrlen;
|
||||
a->attempts = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -182,12 +191,14 @@ delegpt_count_addr(struct delegpt* dp, size_t* numaddr, size_t* numres,
|
||||
}
|
||||
}
|
||||
|
||||
void delegpt_log(struct delegpt* dp)
|
||||
void delegpt_log(enum verbosity_value v, struct delegpt* dp)
|
||||
{
|
||||
char buf[LDNS_MAX_DOMAINLEN+1];
|
||||
struct delegpt_ns* ns;
|
||||
struct delegpt_addr* a;
|
||||
size_t missing=0, numns=0, numaddr=0, numres=0, numavail=0;
|
||||
if(verbosity < v)
|
||||
return;
|
||||
dname_str(dp->name, buf);
|
||||
if(dp->nslist == NULL && dp->target_list == NULL) {
|
||||
log_info("DelegationPoint<%s>: empty", buf);
|
||||
@@ -205,7 +216,7 @@ void delegpt_log(struct delegpt* dp)
|
||||
log_info(" %s%s", buf, (ns->resolved?"*":""));
|
||||
}
|
||||
for(a = dp->target_list; a; a = a->next_target) {
|
||||
log_addr(" ", &a->addr, a->addrlen);
|
||||
log_addr(VERB_ALGO, " ", &a->addr, a->addrlen);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,7 +257,7 @@ find_NS(struct reply_info* rep, size_t from, size_t to)
|
||||
}
|
||||
|
||||
struct delegpt*
|
||||
delegpt_from_message(struct dns_msg* msg, struct region* region)
|
||||
delegpt_from_message(struct dns_msg* msg, struct regional* region)
|
||||
{
|
||||
struct ub_packed_rrset_key* ns_rrset = NULL;
|
||||
struct delegpt* dp;
|
||||
@@ -295,7 +306,7 @@ delegpt_from_message(struct dns_msg* msg, struct region* region)
|
||||
}
|
||||
|
||||
int
|
||||
delegpt_rrset_add_ns(struct delegpt* dp, struct region* region,
|
||||
delegpt_rrset_add_ns(struct delegpt* dp, struct regional* region,
|
||||
struct ub_packed_rrset_key* ns_rrset)
|
||||
{
|
||||
struct packed_rrset_data* nsdata = (struct packed_rrset_data*)
|
||||
@@ -314,7 +325,7 @@ delegpt_rrset_add_ns(struct delegpt* dp, struct region* region,
|
||||
}
|
||||
|
||||
int
|
||||
delegpt_add_rrset_A(struct delegpt* dp, struct region* region,
|
||||
delegpt_add_rrset_A(struct delegpt* dp, struct regional* region,
|
||||
struct ub_packed_rrset_key* ak)
|
||||
{
|
||||
struct packed_rrset_data* d=(struct packed_rrset_data*)ak->entry.data;
|
||||
@@ -337,7 +348,7 @@ delegpt_add_rrset_A(struct delegpt* dp, struct region* region,
|
||||
}
|
||||
|
||||
int
|
||||
delegpt_add_rrset_AAAA(struct delegpt* dp, struct region* region,
|
||||
delegpt_add_rrset_AAAA(struct delegpt* dp, struct regional* region,
|
||||
struct ub_packed_rrset_key* ak)
|
||||
{
|
||||
struct packed_rrset_data* d=(struct packed_rrset_data*)ak->entry.data;
|
||||
@@ -360,7 +371,7 @@ delegpt_add_rrset_AAAA(struct delegpt* dp, struct region* region,
|
||||
}
|
||||
|
||||
int
|
||||
delegpt_add_rrset(struct delegpt* dp, struct region* region,
|
||||
delegpt_add_rrset(struct delegpt* dp, struct regional* region,
|
||||
struct ub_packed_rrset_key* rrset)
|
||||
{
|
||||
if(!rrset)
|
||||
|
||||
+30
-24
@@ -42,7 +42,8 @@
|
||||
|
||||
#ifndef ITERATOR_ITER_DELEGPT_H
|
||||
#define ITERATOR_ITER_DELEGPT_H
|
||||
struct region;
|
||||
#include "util/log.h"
|
||||
struct regional;
|
||||
struct delegpt_ns;
|
||||
struct delegpt_addr;
|
||||
struct dns_msg;
|
||||
@@ -103,55 +104,59 @@ struct delegpt_addr {
|
||||
struct sockaddr_storage addr;
|
||||
/** length of addr */
|
||||
socklen_t addrlen;
|
||||
/** number of attempts for this addr */
|
||||
int attempts;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create new delegation point.
|
||||
* @param region: where to allocate it.
|
||||
* @param regional: where to allocate it.
|
||||
* @return new delegation point or NULL on error.
|
||||
*/
|
||||
struct delegpt* delegpt_create(struct region* region);
|
||||
struct delegpt* delegpt_create(struct regional* regional);
|
||||
|
||||
/**
|
||||
* Create a copy of a delegation point.
|
||||
* @param dp: delegation point to copy.
|
||||
* @param region: where to allocate it.
|
||||
* @param regional: where to allocate it.
|
||||
* @return new delegation point or NULL on error.
|
||||
*/
|
||||
struct delegpt* delegpt_copy(struct delegpt* dp, struct region* region);
|
||||
struct delegpt* delegpt_copy(struct delegpt* dp, struct regional* regional);
|
||||
|
||||
/**
|
||||
* Set name of delegation point.
|
||||
* @param dp: delegation point.
|
||||
* @param region: where to allocate the name copy.
|
||||
* @param regional: where to allocate the name copy.
|
||||
* @param name: name to use.
|
||||
* @return false on error.
|
||||
*/
|
||||
int delegpt_set_name(struct delegpt* dp, struct region* region, uint8_t* name);
|
||||
int delegpt_set_name(struct delegpt* dp, struct regional* regional,
|
||||
uint8_t* name);
|
||||
|
||||
/**
|
||||
* Add a name to the delegation point.
|
||||
* @param dp: delegation point.
|
||||
* @param region: where to allocate the info.
|
||||
* @param regional: where to allocate the info.
|
||||
* @param name: domain name in wire format.
|
||||
* @return false on error.
|
||||
*/
|
||||
int delegpt_add_ns(struct delegpt* dp, struct region* region, uint8_t* name);
|
||||
int delegpt_add_ns(struct delegpt* dp, struct regional* regional,
|
||||
uint8_t* name);
|
||||
|
||||
/**
|
||||
* Add NS rrset; calls add_ns repeatedly.
|
||||
* @param dp: delegation point.
|
||||
* @param region: where to allocate the info.
|
||||
* @param regional: where to allocate the info.
|
||||
* @param ns_rrset: NS rrset.
|
||||
* return 0 on alloc error.
|
||||
*/
|
||||
int delegpt_rrset_add_ns(struct delegpt* dp, struct region* region,
|
||||
int delegpt_rrset_add_ns(struct delegpt* dp, struct regional* regional,
|
||||
struct ub_packed_rrset_key* ns_rrset);
|
||||
|
||||
/**
|
||||
* Add target address to the delegation point.
|
||||
* @param dp: delegation point.
|
||||
* @param region: where to allocate the info.
|
||||
* @param regional: where to allocate the info.
|
||||
* @param name: name for which target was found (must be in nslist).
|
||||
* This name is marked resolved.
|
||||
* @param namelen: length of name.
|
||||
@@ -159,49 +164,49 @@ int delegpt_rrset_add_ns(struct delegpt* dp, struct region* region,
|
||||
* @param addrlen: the length of addr.
|
||||
* @return false on error.
|
||||
*/
|
||||
int delegpt_add_target(struct delegpt* dp, struct region* region,
|
||||
int delegpt_add_target(struct delegpt* dp, struct regional* regional,
|
||||
uint8_t* name, size_t namelen, struct sockaddr_storage* addr,
|
||||
socklen_t addrlen);
|
||||
|
||||
/**
|
||||
* Add A RRset to delegpt.
|
||||
* @param dp: delegation point.
|
||||
* @param region: where to allocate the info.
|
||||
* @param regional: where to allocate the info.
|
||||
* @param rrset: RRset A to add.
|
||||
* @return 0 on alloc error.
|
||||
*/
|
||||
int delegpt_add_rrset_A(struct delegpt* dp, struct region* region,
|
||||
int delegpt_add_rrset_A(struct delegpt* dp, struct regional* regional,
|
||||
struct ub_packed_rrset_key* rrset);
|
||||
|
||||
/**
|
||||
* Add AAAA RRset to delegpt.
|
||||
* @param dp: delegation point.
|
||||
* @param region: where to allocate the info.
|
||||
* @param regional: where to allocate the info.
|
||||
* @param rrset: RRset AAAA to add.
|
||||
* @return 0 on alloc error.
|
||||
*/
|
||||
int delegpt_add_rrset_AAAA(struct delegpt* dp, struct region* region,
|
||||
int delegpt_add_rrset_AAAA(struct delegpt* dp, struct regional* regional,
|
||||
struct ub_packed_rrset_key* rrset);
|
||||
|
||||
/**
|
||||
* Add any RRset to delegpt.
|
||||
* @param dp: delegation point.
|
||||
* @param region: where to allocate the info.
|
||||
* @param regional: where to allocate the info.
|
||||
* @param rrset: RRset to add, NS, A, AAAA.
|
||||
* @return 0 on alloc error.
|
||||
*/
|
||||
int delegpt_add_rrset(struct delegpt* dp, struct region* region,
|
||||
int delegpt_add_rrset(struct delegpt* dp, struct regional* regional,
|
||||
struct ub_packed_rrset_key* rrset);
|
||||
|
||||
/**
|
||||
* Add address to the delegation point. No servername is associated or checked.
|
||||
* @param dp: delegation point.
|
||||
* @param region: where to allocate the info.
|
||||
* @param regional: where to allocate the info.
|
||||
* @param addr: the address.
|
||||
* @param addrlen: the length of addr.
|
||||
* @return false on error.
|
||||
*/
|
||||
int delegpt_add_addr(struct delegpt* dp, struct region* region,
|
||||
int delegpt_add_addr(struct delegpt* dp, struct regional* regional,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen);
|
||||
|
||||
/**
|
||||
@@ -216,9 +221,10 @@ struct delegpt_ns* delegpt_find_ns(struct delegpt* dp, uint8_t* name,
|
||||
|
||||
/**
|
||||
* Print the delegation point to the log. For debugging.
|
||||
* @param v: verbosity value that is needed to emit to log.
|
||||
* @param dp: delegation point.
|
||||
*/
|
||||
void delegpt_log(struct delegpt* dp);
|
||||
void delegpt_log(enum verbosity_value v, struct delegpt* dp);
|
||||
|
||||
/**
|
||||
* Add all usable targets to the result list.
|
||||
@@ -247,11 +253,11 @@ size_t delegpt_count_missing_targets(struct delegpt* dp);
|
||||
* find "glue" in either the ADDITIONAL section or the ANSWER section.
|
||||
*
|
||||
* @param msg: the dns message, referral.
|
||||
* @param region: where to allocate delegation point.
|
||||
* @param regional: where to allocate delegation point.
|
||||
* @return new delegation point or NULL on alloc error, or if the
|
||||
* message was not appropriate.
|
||||
*/
|
||||
struct delegpt* delegpt_from_message(struct dns_msg* msg,
|
||||
struct region* region);
|
||||
struct regional* regional);
|
||||
|
||||
#endif /* ITERATOR_ITER_DELEGPT_H */
|
||||
|
||||
+180
-20
@@ -43,18 +43,24 @@
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "iterator/iter_donotq.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/log.h"
|
||||
#include "util/config_file.h"
|
||||
#include "util/net_help.h"
|
||||
|
||||
/** compare two donotq entries */
|
||||
static int
|
||||
int
|
||||
donotq_cmp(const void* k1, const void* k2)
|
||||
{
|
||||
struct iter_donotq_addr* n1 = (struct iter_donotq_addr*)k1;
|
||||
struct iter_donotq_addr* n2 = (struct iter_donotq_addr*)k2;
|
||||
return sockaddr_cmp(&n1->addr, n1->addrlen, &n2->addr, n2->addrlen);
|
||||
int r = sockaddr_cmp_addr(&n1->addr, n1->addrlen, &n2->addr,
|
||||
n2->addrlen);
|
||||
if(r != 0) return r;
|
||||
if(n1->net < n2->net)
|
||||
return -1;
|
||||
if(n1->net > n2->net)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct iter_donotq*
|
||||
@@ -64,7 +70,7 @@ donotq_create()
|
||||
sizeof(struct iter_donotq));
|
||||
if(!dq)
|
||||
return NULL;
|
||||
dq->region = region_create(malloc, free);
|
||||
dq->region = regional_create();
|
||||
if(!dq->region) {
|
||||
donotq_delete(dq);
|
||||
return NULL;
|
||||
@@ -77,7 +83,7 @@ donotq_delete(struct iter_donotq* dq)
|
||||
{
|
||||
if(!dq)
|
||||
return;
|
||||
region_destroy(dq->region);
|
||||
regional_destroy(dq->region);
|
||||
free(dq->tree);
|
||||
free(dq);
|
||||
}
|
||||
@@ -85,17 +91,83 @@ donotq_delete(struct iter_donotq* dq)
|
||||
/** insert new address into donotq structure */
|
||||
static int
|
||||
donotq_insert(struct iter_donotq* dq, struct sockaddr_storage* addr,
|
||||
socklen_t addrlen)
|
||||
socklen_t addrlen, int net)
|
||||
{
|
||||
struct iter_donotq_addr* node = region_alloc(dq->region,
|
||||
struct iter_donotq_addr* node = regional_alloc(dq->region,
|
||||
sizeof(struct iter_donotq_addr));
|
||||
if(!node)
|
||||
return 0;
|
||||
node->node.key = node;
|
||||
memcpy(&node->addr, addr, addrlen);
|
||||
node->addrlen = addrlen;
|
||||
node->net = net;
|
||||
node->parent = NULL;
|
||||
if(!rbtree_insert(dq->tree, &node->node)) {
|
||||
log_warn("duplicate donotquery address ignored.");
|
||||
verbose(VERB_DETAIL, "duplicate donotquery address ignored.");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** make sure the netblock ends in zeroes for compare in tree */
|
||||
static void
|
||||
mask_block(int ip6, struct sockaddr_storage* addr, int net)
|
||||
{
|
||||
uint8_t mask[8] = {0x0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe};
|
||||
int i, max;
|
||||
uint8_t* s;
|
||||
if(ip6) {
|
||||
s = (uint8_t*)&((struct sockaddr_in6*)addr)->sin6_addr;
|
||||
max = 128;
|
||||
} else {
|
||||
s = (uint8_t*)&((struct sockaddr_in*)addr)->sin_addr;
|
||||
max = 32;
|
||||
}
|
||||
if(net >= max)
|
||||
return;
|
||||
for(i=net/8+1; i<max/8; i++) {
|
||||
s[i] = 0;
|
||||
}
|
||||
s[net/8] &= mask[net&0x7];
|
||||
}
|
||||
|
||||
/** apply donotq string */
|
||||
static int
|
||||
donotq_str_cfg(struct iter_donotq* dq, const char* str)
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
int net;
|
||||
char* s = NULL;
|
||||
socklen_t addrlen;
|
||||
net = (str_is_ip6(str)?128:32);
|
||||
if((s=strchr(str, '/'))) {
|
||||
if(atoi(s+1) > net) {
|
||||
log_err("netblock too large: %s", str);
|
||||
return 0;
|
||||
}
|
||||
net = atoi(s+1);
|
||||
if(net == 0 && strcmp(s+1, "0") != 0) {
|
||||
log_err("cannot parse donotquery netblock:"
|
||||
" '%s'", str);
|
||||
return 0;
|
||||
}
|
||||
if(!(s = strdup(str))) {
|
||||
log_err("out of memory");
|
||||
return 0;
|
||||
}
|
||||
*strchr(s, '/') = '\0';
|
||||
}
|
||||
if(!ipstrtoaddr(s?s:str, UNBOUND_DNS_PORT, &addr, &addrlen)) {
|
||||
free(s);
|
||||
log_err("cannot parse donotquery ip address: '%s'", str);
|
||||
return 0;
|
||||
}
|
||||
if(s) {
|
||||
free(s);
|
||||
mask_block(str_is_ip6(str), &addr, net);
|
||||
}
|
||||
if(!donotq_insert(dq, &addr, addrlen, net)) {
|
||||
log_err("out of memory");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -105,23 +177,78 @@ static int
|
||||
read_donotq(struct iter_donotq* dq, struct config_file* cfg)
|
||||
{
|
||||
struct config_strlist* p;
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t addrlen;
|
||||
for(p = cfg->donotqueryaddrs; p; p = p->next) {
|
||||
log_assert(p->str);
|
||||
if(!extstrtoaddr(p->str, &addr, &addrlen)) {
|
||||
log_err("cannot parse donotquery ip address: '%s'",
|
||||
p->str);
|
||||
if(!donotq_str_cfg(dq, p->str))
|
||||
return 0;
|
||||
}
|
||||
if(!donotq_insert(dq, &addr, addrlen)) {
|
||||
log_err("out of memory");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** number of bits that two addrs share (are equal) */
|
||||
static int
|
||||
addr_in_common(struct sockaddr_storage* addr1, int net1,
|
||||
struct sockaddr_storage* addr2, int net2, socklen_t addrlen)
|
||||
{
|
||||
int min = (net1<net2)?net1:net2;
|
||||
int i, to;
|
||||
int match = 0;
|
||||
uint8_t* s1, *s2;
|
||||
if(addr_is_ip6(addr1, addrlen)) {
|
||||
s1 = (uint8_t*)&((struct sockaddr_in6*)addr1)->sin6_addr;
|
||||
s2 = (uint8_t*)&((struct sockaddr_in6*)addr2)->sin6_addr;
|
||||
to = 16;
|
||||
} else {
|
||||
s1 = (uint8_t*)&((struct sockaddr_in*)addr1)->sin_addr;
|
||||
s2 = (uint8_t*)&((struct sockaddr_in*)addr2)->sin_addr;
|
||||
to = 4;
|
||||
}
|
||||
/* match = bits_in_common(s1, s2, to); */
|
||||
for(i=0; i<to; i++) {
|
||||
if(s1[i] == s2[i]) {
|
||||
match += 8;
|
||||
} else {
|
||||
uint8_t z = s1[i]^s2[i];
|
||||
log_assert(z);
|
||||
while(!(z&0x80)) {
|
||||
match++;
|
||||
z<<=1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(match > min) match = min;
|
||||
return match;
|
||||
}
|
||||
|
||||
/** initialise parent pointers in the tree */
|
||||
static void
|
||||
donotq_init_parents(struct iter_donotq* donotq)
|
||||
{
|
||||
struct iter_donotq_addr* node, *prev = NULL, *p;
|
||||
int m;
|
||||
RBTREE_FOR(node, struct iter_donotq_addr*, donotq->tree) {
|
||||
node->parent = NULL;
|
||||
if(!prev || prev->addrlen != node->addrlen) {
|
||||
prev = node;
|
||||
continue;
|
||||
}
|
||||
m = addr_in_common(&prev->addr, prev->net, &node->addr,
|
||||
node->net, node->addrlen);
|
||||
/* sort order like: ::/0, 1::/2, 1::/4, ... 2::/2 */
|
||||
/* find the previous, or parent-parent-parent */
|
||||
for(p = prev; p; p = p->parent)
|
||||
if(p->net <= m) {
|
||||
/* ==: since prev matched m, this is closest*/
|
||||
/* <: prev matches more, but is not a parent,
|
||||
* this one is a (grand)parent */
|
||||
node->parent = p;
|
||||
break;
|
||||
}
|
||||
prev = node;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
donotq_apply_cfg(struct iter_donotq* dq, struct config_file* cfg)
|
||||
{
|
||||
@@ -131,6 +258,13 @@ donotq_apply_cfg(struct iter_donotq* dq, struct config_file* cfg)
|
||||
return 0;
|
||||
if(!read_donotq(dq, cfg))
|
||||
return 0;
|
||||
if(cfg->donotquery_localhost) {
|
||||
if(!donotq_str_cfg(dq, "127.0.0.0/8"))
|
||||
return 0;
|
||||
if(!donotq_str_cfg(dq, "::1"))
|
||||
return 0;
|
||||
}
|
||||
donotq_init_parents(dq);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -139,11 +273,37 @@ donotq_lookup(struct iter_donotq* donotq, struct sockaddr_storage* addr,
|
||||
socklen_t addrlen)
|
||||
{
|
||||
/* lookup in the tree */
|
||||
rbnode_t* res = NULL;
|
||||
struct iter_donotq_addr* result;
|
||||
struct iter_donotq_addr key;
|
||||
key.node.key = &key;
|
||||
memcpy(&key.addr, addr, addrlen);
|
||||
key.addrlen = addrlen;
|
||||
if(rbtree_search(donotq->tree, &key))
|
||||
key.net = (addr_is_ip6(addr, addrlen)?128:32);
|
||||
if(rbtree_find_less_equal(donotq->tree, &key, &res)) {
|
||||
/* exact */
|
||||
return 1;
|
||||
} else {
|
||||
/* smaller element (or no element) */
|
||||
int m;
|
||||
result = (struct iter_donotq_addr*)res;
|
||||
if(!result || result->addrlen != addrlen)
|
||||
return 0;
|
||||
/* count number of bits matched */
|
||||
m = addr_in_common(&result->addr, result->net, addr,
|
||||
key.net, addrlen);
|
||||
while(result) { /* go up until addr is inside netblock */
|
||||
if(result->net <= m)
|
||||
return 1;
|
||||
result = result->parent;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t
|
||||
donotq_get_mem(struct iter_donotq* donotq)
|
||||
{
|
||||
if(!donotq) return 0;
|
||||
return sizeof(*donotq) + regional_get_mem(donotq->region);
|
||||
}
|
||||
|
||||
+17
-3
@@ -45,14 +45,14 @@
|
||||
#include "util/rbtree.h"
|
||||
struct iter_env;
|
||||
struct config_file;
|
||||
struct region;
|
||||
struct regional;
|
||||
|
||||
/**
|
||||
* Iterator donotqueryaddresses structure
|
||||
*/
|
||||
struct iter_donotq {
|
||||
/** region for allocation */
|
||||
struct region* region;
|
||||
/** regional for allocation */
|
||||
struct regional* region;
|
||||
/**
|
||||
* Tree of the single addresses that are blocked.
|
||||
* contents of type iter_donotq_addr.
|
||||
@@ -71,6 +71,10 @@ struct iter_donotq_addr {
|
||||
struct sockaddr_storage addr;
|
||||
/** length of addr */
|
||||
socklen_t addrlen;
|
||||
/** netblock size */
|
||||
int net;
|
||||
/** parent node in donotq tree that encompasses this entry */
|
||||
struct iter_donotq_addr* parent;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -103,4 +107,14 @@ int donotq_apply_cfg(struct iter_donotq* donotq, struct config_file* cfg);
|
||||
int donotq_lookup(struct iter_donotq* donotq, struct sockaddr_storage* addr,
|
||||
socklen_t addrlen);
|
||||
|
||||
/**
|
||||
* Get memory used by donotqueryaddresses structure.
|
||||
* @param donotq: structure for address storage.
|
||||
* @return bytes in use.
|
||||
*/
|
||||
size_t donotq_get_mem(struct iter_donotq* donotq);
|
||||
|
||||
/** compare two donotq entries */
|
||||
int donotq_cmp(const void* k1, const void* k2);
|
||||
|
||||
#endif /* ITERATOR_ITER_DONOTQ_H */
|
||||
|
||||
+16
-9
@@ -42,14 +42,13 @@
|
||||
#include "config.h"
|
||||
#include "iterator/iter_fwd.h"
|
||||
#include "iterator/iter_delegpt.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/log.h"
|
||||
#include "util/config_file.h"
|
||||
#include "util/net_help.h"
|
||||
#include "util/data/dname.h"
|
||||
|
||||
/** compare two fwd entries */
|
||||
static int
|
||||
int
|
||||
fwd_cmp(const void* k1, const void* k2)
|
||||
{
|
||||
int m;
|
||||
@@ -71,7 +70,7 @@ forwards_create()
|
||||
sizeof(struct iter_forwards));
|
||||
if(!fwd)
|
||||
return NULL;
|
||||
fwd->region = region_create(malloc, free);
|
||||
fwd->region = regional_create();
|
||||
if(!fwd->region) {
|
||||
forwards_delete(fwd);
|
||||
return NULL;
|
||||
@@ -84,7 +83,7 @@ forwards_delete(struct iter_forwards* fwd)
|
||||
{
|
||||
if(!fwd)
|
||||
return;
|
||||
region_destroy(fwd->region);
|
||||
regional_destroy(fwd->region);
|
||||
free(fwd->tree);
|
||||
free(fwd);
|
||||
}
|
||||
@@ -93,13 +92,13 @@ forwards_delete(struct iter_forwards* fwd)
|
||||
static int
|
||||
forwards_insert(struct iter_forwards* fwd, uint16_t c, struct delegpt* dp)
|
||||
{
|
||||
struct iter_forward_zone* node = region_alloc(fwd->region,
|
||||
struct iter_forward_zone* node = regional_alloc(fwd->region,
|
||||
sizeof(struct iter_forward_zone));
|
||||
if(!node)
|
||||
return 0;
|
||||
node->node.key = node;
|
||||
node->dclass = c;
|
||||
node->name = region_alloc_init(fwd->region, dp->name, dp->namelen);
|
||||
node->name = regional_alloc_init(fwd->region, dp->name, dp->namelen);
|
||||
if(!node->name)
|
||||
return 0;
|
||||
node->namelen = dp->namelen;
|
||||
@@ -229,8 +228,8 @@ read_forwards(struct iter_forwards* fwd, struct config_file* cfg)
|
||||
return 0;
|
||||
if(!forwards_insert(fwd, LDNS_RR_CLASS_IN, dp))
|
||||
return 0;
|
||||
log_info("Forward zone server list:");
|
||||
delegpt_log(dp);
|
||||
verbose(VERB_DETAIL, "Forward zone server list:");
|
||||
delegpt_log(VERB_DETAIL, dp);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -283,3 +282,11 @@ forwards_lookup(struct iter_forwards* fwd, uint8_t* qname, uint16_t qclass)
|
||||
return result->dp;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t
|
||||
forwards_get_mem(struct iter_forwards* fwd)
|
||||
{
|
||||
if(!fwd)
|
||||
return 0;
|
||||
return sizeof(*fwd) + regional_get_mem(fwd->region);
|
||||
}
|
||||
|
||||
+13
-3
@@ -46,14 +46,14 @@
|
||||
struct iter_env;
|
||||
struct config_file;
|
||||
struct delegpt;
|
||||
struct region;
|
||||
struct regional;
|
||||
|
||||
/**
|
||||
* Iterator forward zones structure
|
||||
*/
|
||||
struct iter_forwards {
|
||||
/** region where forward zone server addresses are allocated */
|
||||
struct region* region;
|
||||
/** regional where forward zone server addresses are allocated */
|
||||
struct regional* region;
|
||||
/**
|
||||
* Zones are stored in this tree. Sort order is specially chosen.
|
||||
* first sorted on qtype. Then on dname in nsec-like order, so that
|
||||
@@ -118,4 +118,14 @@ int forwards_apply_cfg(struct iter_forwards* fwd, struct config_file* cfg);
|
||||
struct delegpt* forwards_lookup(struct iter_forwards* fwd,
|
||||
uint8_t* qname, uint16_t qclass);
|
||||
|
||||
/**
|
||||
* Get memory in use by forward storage
|
||||
* @param fwd: forward storage.
|
||||
* @return bytes in use
|
||||
*/
|
||||
size_t forwards_get_mem(struct iter_forwards* fwd);
|
||||
|
||||
/** compare two fwd entries */
|
||||
int fwd_cmp(const void* k1, const void* k2);
|
||||
|
||||
#endif /* ITERATOR_ITER_FWD_H */
|
||||
|
||||
+142
-13
@@ -42,14 +42,13 @@
|
||||
#include "config.h"
|
||||
#include "iterator/iter_hints.h"
|
||||
#include "iterator/iter_delegpt.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/log.h"
|
||||
#include "util/config_file.h"
|
||||
#include "util/net_help.h"
|
||||
#include "util/data/dname.h"
|
||||
|
||||
/** compare two hint entries */
|
||||
static int
|
||||
int
|
||||
stub_cmp(const void* k1, const void* k2)
|
||||
{
|
||||
int m;
|
||||
@@ -71,7 +70,7 @@ hints_create()
|
||||
sizeof(struct iter_hints));
|
||||
if(!hints)
|
||||
return NULL;
|
||||
hints->region = region_create(malloc, free);
|
||||
hints->region = regional_create();
|
||||
if(!hints->region) {
|
||||
hints_delete(hints);
|
||||
return NULL;
|
||||
@@ -84,14 +83,14 @@ hints_delete(struct iter_hints* hints)
|
||||
{
|
||||
if(!hints)
|
||||
return;
|
||||
region_destroy(hints->region);
|
||||
regional_destroy(hints->region);
|
||||
free(hints->tree);
|
||||
free(hints);
|
||||
}
|
||||
|
||||
/** add hint to delegation hints */
|
||||
static int
|
||||
ah(struct delegpt* dp, struct region* r, const char* sv, const char* ip)
|
||||
ah(struct delegpt* dp, struct regional* r, const char* sv, const char* ip)
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t addrlen;
|
||||
@@ -113,7 +112,7 @@ ah(struct delegpt* dp, struct region* r, const char* sv, const char* ip)
|
||||
|
||||
/** obtain compiletime provided root hints */
|
||||
static struct delegpt*
|
||||
compile_time_root_prime(struct region* r)
|
||||
compile_time_root_prime(struct regional* r)
|
||||
{
|
||||
/* from:
|
||||
; This file is made available by InterNIC
|
||||
@@ -141,7 +140,7 @@ compile_time_root_prime(struct region* r)
|
||||
if(!ah(dp, r, "I.ROOT-SERVERS.NET.", "192.36.148.17")) return 0;
|
||||
if(!ah(dp, r, "J.ROOT-SERVERS.NET.", "192.58.128.30")) return 0;
|
||||
if(!ah(dp, r, "K.ROOT-SERVERS.NET.", "193.0.14.129")) return 0;
|
||||
if(!ah(dp, r, "L.ROOT-SERVERS.NET.", "198.32.64.12")) return 0;
|
||||
if(!ah(dp, r, "L.ROOT-SERVERS.NET.", "199.7.83.42")) return 0;
|
||||
if(!ah(dp, r, "M.ROOT-SERVERS.NET.", "202.12.27.33")) return 0;
|
||||
return dp;
|
||||
}
|
||||
@@ -150,13 +149,13 @@ compile_time_root_prime(struct region* r)
|
||||
static int
|
||||
hints_insert(struct iter_hints* hints, uint16_t c, struct delegpt* dp)
|
||||
{
|
||||
struct iter_hints_stub* node = region_alloc(hints->region,
|
||||
struct iter_hints_stub* node = regional_alloc(hints->region,
|
||||
sizeof(struct iter_hints_stub));
|
||||
if(!node)
|
||||
return 0;
|
||||
node->node.key = node;
|
||||
node->hint_class = c;
|
||||
node->name = region_alloc_init(hints->region, dp->name, dp->namelen);
|
||||
node->name = regional_alloc_init(hints->region, dp->name, dp->namelen);
|
||||
if(!node->name)
|
||||
return 0;
|
||||
node->namelen = dp->namelen;
|
||||
@@ -286,7 +285,127 @@ read_stubs(struct iter_hints* hints, struct config_file* cfg)
|
||||
return 0;
|
||||
if(!hints_insert(hints, LDNS_RR_CLASS_IN, dp))
|
||||
return 0;
|
||||
delegpt_log(dp);
|
||||
delegpt_log(VERB_DETAIL, dp);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** read root hints from file */
|
||||
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 delegpt* dp;
|
||||
ldns_rr* rr = NULL;
|
||||
ldns_status status;
|
||||
uint16_t c = LDNS_RR_CLASS_IN;
|
||||
FILE* f = fopen(fname, "r");
|
||||
if(!f) {
|
||||
log_err("could not read root hints %s: %s",
|
||||
fname, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
dp = delegpt_create(hints->region);
|
||||
if(!dp) {
|
||||
log_err("out of memory reading root hints");
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
verbose(VERB_DETAIL, "Reading root hints from %s", fname);
|
||||
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));
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_NS) {
|
||||
if(!delegpt_add_ns(dp, hints->region,
|
||||
ldns_rdf_data(ldns_rr_rdf(rr, 0)))) {
|
||||
log_err("out of memory reading root hints");
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
c = ldns_rr_get_class(rr);
|
||||
if(!dp->name) {
|
||||
if(!delegpt_set_name(dp, hints->region,
|
||||
ldns_rdf_data(ldns_rr_owner(rr)))){
|
||||
log_err("out of memory.");
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_A) {
|
||||
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(dp, hints->region,
|
||||
ldns_rdf_data(ldns_rr_owner(rr)),
|
||||
ldns_rdf_size(ldns_rr_owner(rr)),
|
||||
(struct sockaddr_storage*)&sa, len)) {
|
||||
log_err("out of memory reading root hints");
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
} else if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_AAAA) {
|
||||
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(dp, hints->region,
|
||||
ldns_rdf_data(ldns_rr_owner(rr)),
|
||||
ldns_rdf_size(ldns_rr_owner(rr)),
|
||||
(struct sockaddr_storage*)&sa, len)) {
|
||||
log_err("out of memory reading root hints");
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
log_warn("root hints %s:%d skipping type %d",
|
||||
fname, lineno, ldns_rr_get_type(rr));
|
||||
}
|
||||
|
||||
ldns_rr_free(rr);
|
||||
}
|
||||
fclose(f);
|
||||
if(!dp->name) {
|
||||
log_warn("root hints %s: no NS content", fname);
|
||||
return 1;
|
||||
}
|
||||
if(!hints_insert(hints, c, dp)) {
|
||||
return 0;
|
||||
}
|
||||
delegpt_log(VERB_DETAIL, dp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** read root hints list */
|
||||
static int
|
||||
read_root_hints_list(struct iter_hints* hints, struct config_file* cfg)
|
||||
{
|
||||
struct config_strlist* p;
|
||||
for(p = cfg->root_hints; p; p = p->next) {
|
||||
log_assert(p->str);
|
||||
if(p->str && p->str[0]) {
|
||||
if(!read_root_hints(hints, p->str))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -298,7 +417,10 @@ hints_apply_cfg(struct iter_hints* hints, struct config_file* cfg)
|
||||
hints->tree = rbtree_create(stub_cmp);
|
||||
if(!hints->tree)
|
||||
return 0;
|
||||
/* TODO: read root hints from file named in cfg */
|
||||
|
||||
/* read root hints */
|
||||
if(!read_root_hints_list(hints, cfg))
|
||||
return 0;
|
||||
|
||||
/* read stub hints */
|
||||
if(!read_stubs(hints, cfg))
|
||||
@@ -312,7 +434,7 @@ hints_apply_cfg(struct iter_hints* hints, struct config_file* cfg)
|
||||
return 0;
|
||||
if(!hints_insert(hints, LDNS_RR_CLASS_IN, dp))
|
||||
return 0;
|
||||
delegpt_log(dp);
|
||||
delegpt_log(VERB_DETAIL, dp);
|
||||
}
|
||||
|
||||
init_parents(hints);
|
||||
@@ -375,3 +497,10 @@ hints_lookup_stub(struct iter_hints* hints, uint8_t* qname,
|
||||
return result->dp; /* need to prime this stub */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t
|
||||
hints_get_mem(struct iter_hints* hints)
|
||||
{
|
||||
if(!hints) return 0;
|
||||
return sizeof(*hints) + regional_get_mem(hints->region);
|
||||
}
|
||||
|
||||
+13
-3
@@ -46,14 +46,14 @@
|
||||
struct iter_env;
|
||||
struct config_file;
|
||||
struct delegpt;
|
||||
struct region;
|
||||
struct regional;
|
||||
|
||||
/**
|
||||
* Iterator hints structure
|
||||
*/
|
||||
struct iter_hints {
|
||||
/** region where hints are allocated */
|
||||
struct region* region;
|
||||
/** regional where hints are allocated */
|
||||
struct regional* region;
|
||||
/**
|
||||
* Hints are stored in this tree. Sort order is specially chosen.
|
||||
* first sorted on qtype. Then on dname in nsec-like order, so that
|
||||
@@ -127,4 +127,14 @@ struct delegpt* hints_lookup_root(struct iter_hints* hints, uint16_t qclass);
|
||||
struct delegpt* hints_lookup_stub(struct iter_hints* hints,
|
||||
uint8_t* qname, uint16_t qclass, struct delegpt* dp);
|
||||
|
||||
/**
|
||||
* Get memory in use by hints
|
||||
* @param hints: hint storage.
|
||||
* @return bytes in use
|
||||
*/
|
||||
size_t hints_get_mem(struct iter_hints* hints);
|
||||
|
||||
/** compare two hint entries */
|
||||
int stub_cmp(const void* k1, const void* k2);
|
||||
|
||||
#endif /* ITERATOR_ITER_HINTS_H */
|
||||
|
||||
@@ -100,8 +100,8 @@ response_type_from_cache(struct dns_msg* msg,
|
||||
}
|
||||
|
||||
enum response_type
|
||||
response_type_from_server(struct dns_msg* msg, struct query_info* request,
|
||||
struct delegpt* dp)
|
||||
response_type_from_server(int rdset,
|
||||
struct dns_msg* msg, struct query_info* request, struct delegpt* dp)
|
||||
{
|
||||
uint8_t* origzone = (uint8_t*)"\000"; /* the default */
|
||||
size_t origzonelen = 1;
|
||||
@@ -111,8 +111,13 @@ response_type_from_server(struct dns_msg* msg, struct query_info* request,
|
||||
return RESPONSE_TYPE_THROWAWAY;
|
||||
|
||||
/* If the message is NXDOMAIN, then it answers the question. */
|
||||
if(FLAGS_GET_RCODE(msg->rep->flags) == LDNS_RCODE_NXDOMAIN)
|
||||
if(FLAGS_GET_RCODE(msg->rep->flags) == LDNS_RCODE_NXDOMAIN) {
|
||||
/* make sure its not recursive when we don't want it to */
|
||||
if( (msg->rep->flags&BIT_RA) &&
|
||||
!(msg->rep->flags&BIT_AA) && !rdset)
|
||||
return RESPONSE_TYPE_LAME;
|
||||
return RESPONSE_TYPE_ANSWER;
|
||||
}
|
||||
|
||||
/* Other response codes mean (so far) to throw the response away as
|
||||
* meaningless and move on to the next nameserver. */
|
||||
@@ -138,6 +143,18 @@ response_type_from_server(struct dns_msg* msg, struct query_info* request,
|
||||
for(i=0; i<msg->rep->an_numrrsets; i++) {
|
||||
struct ub_packed_rrset_key* s = msg->rep->rrsets[i];
|
||||
|
||||
/* if the answer section has NS rrset, and qtype ANY
|
||||
* and the delegation is lower, and no CNAMEs followed,
|
||||
* this is a referral where the NS went to AN section */
|
||||
if((request->qtype == LDNS_RR_TYPE_ANY ||
|
||||
request->qtype == LDNS_RR_TYPE_NS) &&
|
||||
ntohs(s->rk.type) == LDNS_RR_TYPE_NS &&
|
||||
ntohs(s->rk.rrset_class) == request->qclass &&
|
||||
dname_strict_subdomain_c(s->rk.dname,
|
||||
origzone)) {
|
||||
return RESPONSE_TYPE_REFERRAL;
|
||||
}
|
||||
|
||||
/* If we have encountered an answer (before or
|
||||
* after a CNAME), then we are done! Note that
|
||||
* if qtype == CNAME then this will be noted as an
|
||||
@@ -181,6 +198,10 @@ response_type_from_server(struct dns_msg* msg, struct query_info* request,
|
||||
/* The normal way of detecting NOERROR/NODATA. */
|
||||
if(ntohs(s->rk.type) == LDNS_RR_TYPE_SOA &&
|
||||
dname_subdomain_c(request->qname, s->rk.dname)) {
|
||||
/* we do our own recursion, thank you */
|
||||
if( (msg->rep->flags&BIT_RA) &&
|
||||
!(msg->rep->flags&BIT_AA) && !rdset)
|
||||
return RESPONSE_TYPE_LAME;
|
||||
return RESPONSE_TYPE_ANSWER;
|
||||
}
|
||||
|
||||
@@ -191,6 +212,11 @@ response_type_from_server(struct dns_msg* msg, struct query_info* request,
|
||||
* thought we were contacting, then it is an answer.*/
|
||||
/* FIXME: is this correct? */
|
||||
if(query_dname_compare(s->rk.dname, origzone) == 0) {
|
||||
/* see if mistakenly a recursive server was
|
||||
* deployed and is responding nonAA */
|
||||
if( (msg->rep->flags&BIT_RA) &&
|
||||
!(msg->rep->flags&BIT_AA) && !rdset)
|
||||
return RESPONSE_TYPE_LAME;
|
||||
return RESPONSE_TYPE_ANSWER;
|
||||
}
|
||||
/* If we are getting a referral upwards (or to
|
||||
@@ -219,5 +245,8 @@ response_type_from_server(struct dns_msg* msg, struct query_info* request,
|
||||
|
||||
/* If we've gotten this far, this is NOERROR/NODATA (which could
|
||||
* be an entirely empty message) */
|
||||
/* check if recursive answer; saying it has empty cache */
|
||||
if( (msg->rep->flags&BIT_RA) && !(msg->rep->flags&BIT_AA) && !rdset)
|
||||
return RESPONSE_TYPE_LAME;
|
||||
return RESPONSE_TYPE_ANSWER;
|
||||
}
|
||||
|
||||
@@ -107,13 +107,14 @@ enum response_type response_type_from_cache(struct dns_msg* msg,
|
||||
* relies somewhat on the originating zone to be accurate (for lameness
|
||||
* detection, mostly).
|
||||
*
|
||||
* @param rdset: if RD bit was sent in query sent by unbound.
|
||||
* @param msg: the message from the cache.
|
||||
* @param request: the request that generated the response.
|
||||
* @param dp: The delegation point that was being queried
|
||||
* when the response was returned.
|
||||
* @return the response type (CNAME or ANSWER).
|
||||
*/
|
||||
enum response_type response_type_from_server(struct dns_msg* msg,
|
||||
struct query_info* request, struct delegpt* dp);
|
||||
enum response_type response_type_from_server(int rdset,
|
||||
struct dns_msg* msg, struct query_info* request, struct delegpt* dp);
|
||||
|
||||
#endif /* ITERATOR_ITER_RESPTYPE_H */
|
||||
|
||||
+21
-11
@@ -44,7 +44,7 @@
|
||||
#include "services/cache/rrset.h"
|
||||
#include "util/log.h"
|
||||
#include "util/net_help.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/config_file.h"
|
||||
#include "util/module.h"
|
||||
#include "util/data/msgparse.h"
|
||||
@@ -224,22 +224,22 @@ synth_cname(uint8_t* qname, size_t qnamelen, struct rrset_parse* dname_rrset,
|
||||
/** synthesize a CNAME rrset */
|
||||
static struct rrset_parse*
|
||||
synth_cname_rrset(uint8_t** sname, size_t* snamelen, uint8_t* alias,
|
||||
size_t aliaslen, struct region* region, struct msg_parse* msg,
|
||||
size_t aliaslen, struct regional* region, struct msg_parse* msg,
|
||||
struct rrset_parse* rrset, struct rrset_parse* prev,
|
||||
struct rrset_parse* nx, ldns_buffer* pkt)
|
||||
{
|
||||
struct rrset_parse* cn = (struct rrset_parse*)region_alloc(region,
|
||||
struct rrset_parse* cn = (struct rrset_parse*)regional_alloc(region,
|
||||
sizeof(struct rrset_parse));
|
||||
if(!cn)
|
||||
return NULL;
|
||||
memset(cn, 0, sizeof(*cn));
|
||||
cn->rr_first = (struct rr_parse*)region_alloc(region,
|
||||
cn->rr_first = (struct rr_parse*)regional_alloc(region,
|
||||
sizeof(struct rr_parse));
|
||||
if(!cn->rr_first)
|
||||
return NULL;
|
||||
cn->rr_last = cn->rr_first;
|
||||
/* CNAME from sname to alias */
|
||||
cn->dname = (uint8_t*)region_alloc(region, *snamelen);
|
||||
cn->dname = (uint8_t*)regional_alloc(region, *snamelen);
|
||||
if(!cn->dname)
|
||||
return NULL;
|
||||
dname_pkt_copy(pkt, cn->dname, *sname);
|
||||
@@ -253,7 +253,7 @@ synth_cname_rrset(uint8_t** sname, size_t* snamelen, uint8_t* alias,
|
||||
/* allocate TTL + rdatalen + uncompressed dname */
|
||||
memset(cn->rr_first, 0, sizeof(struct rr_parse));
|
||||
cn->rr_first->outside_packet = 1;
|
||||
cn->rr_first->ttl_data = (uint8_t*)region_alloc(region,
|
||||
cn->rr_first->ttl_data = (uint8_t*)regional_alloc(region,
|
||||
sizeof(uint32_t)+sizeof(uint16_t)+aliaslen);
|
||||
if(!cn->rr_first->ttl_data)
|
||||
return NULL;
|
||||
@@ -312,7 +312,7 @@ pkt_sub(ldns_buffer* pkt, uint8_t* comprname, uint8_t* zone)
|
||||
*/
|
||||
static int
|
||||
scrub_normalize(ldns_buffer* pkt, struct msg_parse* msg,
|
||||
struct query_info* qinfo, struct region* region)
|
||||
struct query_info* qinfo, struct regional* region)
|
||||
{
|
||||
uint8_t* sname = qinfo->qname;
|
||||
size_t snamelen = qinfo->qname_len;
|
||||
@@ -515,17 +515,27 @@ scrub_sanitize(ldns_buffer* pkt, struct msg_parse* msg, uint8_t* zonename,
|
||||
* same check can be used */
|
||||
|
||||
if(!pkt_sub(pkt, rrset->dname, zonename)) {
|
||||
if(!env->cfg->harden_glue) {
|
||||
if(msg->an_rrsets == 0 &&
|
||||
rrset->type == LDNS_RR_TYPE_NS &&
|
||||
rrset->section == LDNS_SECTION_AUTHORITY &&
|
||||
FLAGS_GET_RCODE(msg->flags) ==
|
||||
LDNS_RCODE_NOERROR) {
|
||||
/* noerror, nodata and this NS rrset is above
|
||||
* the zone. This is LAME!
|
||||
* Leave in the NS for lame classification. */
|
||||
} else if(!env->cfg->harden_glue) {
|
||||
/* store in cache! Since it is relevant
|
||||
* (from normalize) it will be picked up
|
||||
* from the cache to be used later */
|
||||
store_rrset(pkt, msg, env, rrset);
|
||||
remove_rrset("sanitize: storing potential "
|
||||
"poison RRset:", pkt, msg, prev, &rrset);
|
||||
} else
|
||||
continue;
|
||||
} else {
|
||||
remove_rrset("sanitize: removing potential "
|
||||
"poison RRset:", pkt, msg, prev, &rrset);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
prev = rrset;
|
||||
rrset = rrset->rrset_all_next;
|
||||
@@ -535,7 +545,7 @@ scrub_sanitize(ldns_buffer* pkt, struct msg_parse* msg, uint8_t* zonename,
|
||||
|
||||
int
|
||||
scrub_message(ldns_buffer* pkt, struct msg_parse* msg,
|
||||
struct query_info* qinfo, uint8_t* zonename, struct region* region,
|
||||
struct query_info* qinfo, uint8_t* zonename, struct regional* region,
|
||||
struct module_env* env)
|
||||
{
|
||||
/* basic sanity checks */
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
#define ITERATOR_ITER_SCRUB_H
|
||||
struct msg_parse;
|
||||
struct query_info;
|
||||
struct region;
|
||||
struct regional;
|
||||
struct module_env;
|
||||
|
||||
/**
|
||||
@@ -55,12 +55,12 @@ struct module_env;
|
||||
* @param qinfo: the query info that was sent to the server. Checked.
|
||||
* @param zonename: the name of the last delegation point.
|
||||
* Used to determine out of bailiwick information.
|
||||
* @param region: where to allocate (new) parts of the message.
|
||||
* @param regional: where to allocate (new) parts of the message.
|
||||
* @param env: module environment with config settings and cache.
|
||||
* @return: false if the message is total waste. true if scrubbed with success.
|
||||
*/
|
||||
int scrub_message(ldns_buffer* pkt, struct msg_parse* msg,
|
||||
struct query_info* qinfo, uint8_t* zonename, struct region* region,
|
||||
struct query_info* qinfo, uint8_t* zonename, struct regional* regional,
|
||||
struct module_env* env);
|
||||
|
||||
#endif /* ITERATOR_ITER_SCRUB_H */
|
||||
|
||||
+151
-86
@@ -53,35 +53,12 @@
|
||||
#include "util/module.h"
|
||||
#include "util/log.h"
|
||||
#include "util/config_file.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/data/msgparse.h"
|
||||
#include "util/data/dname.h"
|
||||
#include "util/random.h"
|
||||
|
||||
/** count number of integers in fetch policy string */
|
||||
static int
|
||||
fetch_count(const char* s)
|
||||
{
|
||||
/* format ::= (sp num)+ sp */
|
||||
/* num ::= [-](0-9)+ */
|
||||
/* sp ::= (space|tab)* */
|
||||
int num = 0;
|
||||
while(*s) {
|
||||
while(*s && isspace(*s))
|
||||
s++;
|
||||
if(!*s) /* end of string */
|
||||
break;
|
||||
if(*s == '-')
|
||||
s++;
|
||||
if(!*s) /* only - not allowed */
|
||||
return 0;
|
||||
if(!isdigit(*s)) /* bad character */
|
||||
return 0;
|
||||
while(*s && isdigit(*s))
|
||||
s++;
|
||||
num++;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
#include "util/fptr_wlist.h"
|
||||
#include "validator/val_anchor.h"
|
||||
|
||||
/** fillup fetch policy array */
|
||||
static void
|
||||
@@ -91,7 +68,8 @@ fetch_fill(struct iter_env* ie, const char* str)
|
||||
int i;
|
||||
for(i=0; i<ie->max_dependency_depth+1; i++) {
|
||||
ie->target_fetch_policy[i] = strtol(s, &e, 10);
|
||||
log_assert(s != e); /* parsed syntax already */
|
||||
if(s == e)
|
||||
fatal_exit("cannot parse fetch policy number %s", s);
|
||||
s = e;
|
||||
}
|
||||
}
|
||||
@@ -100,7 +78,7 @@ fetch_fill(struct iter_env* ie, const char* str)
|
||||
static int
|
||||
read_fetch_policy(struct iter_env* ie, const char* str)
|
||||
{
|
||||
int count = fetch_count(str);
|
||||
int count = cfg_count_numbers(str);
|
||||
if(count < 1) {
|
||||
log_err("Cannot parse target fetch policy: \"%s\"", str);
|
||||
return 0;
|
||||
@@ -156,19 +134,22 @@ iter_filter_unsuitable(struct iter_env* iter_env, struct module_env* env,
|
||||
{
|
||||
int rtt;
|
||||
int lame;
|
||||
int dnsseclame;
|
||||
if(donotq_lookup(iter_env->donotq, &a->addr, a->addrlen)) {
|
||||
return -1; /* server is on the donotquery list */
|
||||
}
|
||||
if(!iter_env->supports_ipv6 && addr_is_ip6(&a->addr)) {
|
||||
if(!iter_env->supports_ipv6 && addr_is_ip6(&a->addr, a->addrlen)) {
|
||||
return -1; /* there is no ip6 available */
|
||||
}
|
||||
/* check lameness - need zone , class info */
|
||||
if(infra_get_lame_rtt(env->infra_cache, &a->addr, a->addrlen,
|
||||
name, namelen, &lame, &rtt, now)) {
|
||||
name, namelen, &lame, &dnsseclame, &rtt, now)) {
|
||||
if(lame)
|
||||
return -1; /* server is lame */
|
||||
else if(rtt >= USEFUL_SERVER_TOP_TIMEOUT)
|
||||
return -1; /* server is unresponsive */
|
||||
else if(dnsseclame)
|
||||
return rtt+USEFUL_SERVER_TOP_TIMEOUT; /* nonpref */
|
||||
else return rtt;
|
||||
}
|
||||
/* no server information present */
|
||||
@@ -179,7 +160,8 @@ iter_filter_unsuitable(struct iter_env* iter_env, struct module_env* env,
|
||||
* returns number of best targets (or 0, no suitable targets) */
|
||||
static int
|
||||
iter_filter_order(struct iter_env* iter_env, struct module_env* env,
|
||||
uint8_t* name, size_t namelen, time_t now, struct delegpt* dp)
|
||||
uint8_t* name, size_t namelen, time_t now, struct delegpt* dp,
|
||||
int* best_rtt)
|
||||
{
|
||||
int got_num = 0, got_rtt = 0, thisrtt, swap_to_front;
|
||||
struct delegpt_addr* a, *n, *prev=NULL;
|
||||
@@ -220,23 +202,30 @@ iter_filter_order(struct iter_env* iter_env, struct module_env* env,
|
||||
a = a->next_result;
|
||||
}
|
||||
}
|
||||
*best_rtt = got_rtt;
|
||||
return got_num;
|
||||
}
|
||||
|
||||
struct delegpt_addr*
|
||||
iter_server_selection(struct iter_env* iter_env,
|
||||
struct module_env* env, struct delegpt* dp,
|
||||
uint8_t* name, size_t namelen)
|
||||
uint8_t* name, size_t namelen, int* dnssec_expected)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
int sel;
|
||||
int selrtt;
|
||||
struct delegpt_addr* a, *prev;
|
||||
int num = iter_filter_order(iter_env, env, name, namelen, now, dp);
|
||||
int num = iter_filter_order(iter_env, env, name, namelen, now, dp,
|
||||
&selrtt);
|
||||
|
||||
if(num == 0)
|
||||
return NULL;
|
||||
if(selrtt >= USEFUL_SERVER_TOP_TIMEOUT)
|
||||
*dnssec_expected = 0;
|
||||
if(num == 1) {
|
||||
a = dp->result_list;
|
||||
if(++a->attempts < OUTBOUND_MSG_RETRY)
|
||||
return a;
|
||||
dp->result_list = a->next_result;
|
||||
return a;
|
||||
}
|
||||
@@ -254,6 +243,8 @@ iter_server_selection(struct iter_env* iter_env,
|
||||
}
|
||||
if(!a) /* robustness */
|
||||
return NULL;
|
||||
if(++a->attempts < OUTBOUND_MSG_RETRY)
|
||||
return a;
|
||||
/* remove it from the delegation point result list */
|
||||
if(prev)
|
||||
prev->next_result = a->next_result;
|
||||
@@ -262,9 +253,10 @@ iter_server_selection(struct iter_env* iter_env,
|
||||
}
|
||||
|
||||
struct dns_msg*
|
||||
dns_alloc_msg(ldns_buffer* pkt, struct msg_parse* msg, struct region* region)
|
||||
dns_alloc_msg(ldns_buffer* pkt, struct msg_parse* msg,
|
||||
struct regional* region)
|
||||
{
|
||||
struct dns_msg* m = (struct dns_msg*)region_alloc(region,
|
||||
struct dns_msg* m = (struct dns_msg*)regional_alloc(region,
|
||||
sizeof(struct dns_msg));
|
||||
if(!m)
|
||||
return NULL;
|
||||
@@ -277,14 +269,14 @@ dns_alloc_msg(ldns_buffer* pkt, struct msg_parse* msg, struct region* region)
|
||||
}
|
||||
|
||||
struct dns_msg*
|
||||
dns_copy_msg(struct dns_msg* from, struct region* region)
|
||||
dns_copy_msg(struct dns_msg* from, struct regional* region)
|
||||
{
|
||||
struct dns_msg* m = (struct dns_msg*)region_alloc(region,
|
||||
struct dns_msg* m = (struct dns_msg*)regional_alloc(region,
|
||||
sizeof(struct dns_msg));
|
||||
if(!m)
|
||||
return NULL;
|
||||
m->qinfo = from->qinfo;
|
||||
if(!(m->qinfo.qname = region_alloc_init(region, from->qinfo.qname,
|
||||
if(!(m->qinfo.qname = regional_alloc_init(region, from->qinfo.qname,
|
||||
from->qinfo.qname_len)))
|
||||
return NULL;
|
||||
if(!(m->rep = reply_info_copy(from->rep, NULL, region)))
|
||||
@@ -296,51 +288,7 @@ int
|
||||
iter_dns_store(struct module_env* env, struct query_info* msgqinf,
|
||||
struct reply_info* msgrep, int is_referral)
|
||||
{
|
||||
struct reply_info* rep = NULL;
|
||||
/* alloc, malloc properly (not in region, like msg is) */
|
||||
rep = reply_info_copy(msgrep, env->alloc, NULL);
|
||||
if(!rep)
|
||||
return 0;
|
||||
|
||||
if(is_referral) {
|
||||
/* store rrsets */
|
||||
struct rrset_ref ref;
|
||||
uint32_t now = time(NULL);
|
||||
size_t i;
|
||||
for(i=0; i<rep->rrset_count; i++) {
|
||||
packed_rrset_ttl_add((struct packed_rrset_data*)
|
||||
rep->rrsets[i]->entry.data, now);
|
||||
ref.key = rep->rrsets[i];
|
||||
ref.id = rep->rrsets[i]->id;
|
||||
/*ignore ret: it was in the cache, ref updated */
|
||||
(void)rrset_cache_update(env->rrset_cache, &ref,
|
||||
env->alloc, now);
|
||||
}
|
||||
free(rep);
|
||||
return 1;
|
||||
} else {
|
||||
/* store msg, and rrsets */
|
||||
struct query_info qinf;
|
||||
hashvalue_t h;
|
||||
|
||||
qinf = *msgqinf;
|
||||
qinf.qname = memdup(msgqinf->qname, msgqinf->qname_len);
|
||||
if(!qinf.qname) {
|
||||
reply_info_parsedelete(rep, env->alloc);
|
||||
return 0;
|
||||
}
|
||||
/* fixup flags to be sensible for a reply based on the cache */
|
||||
/* this module means that RA is available. It is an answer QR.
|
||||
* Not AA from cache. Not CD in cache (depends on client bit). */
|
||||
rep->flags |= (BIT_RA | BIT_QR);
|
||||
rep->flags &= ~(BIT_AA | BIT_CD);
|
||||
h = query_info_hash(&qinf);
|
||||
dns_cache_store_msg(env, &qinf, h, rep);
|
||||
/* qname is used inside query_info_entrysetup, and set to
|
||||
* NULL. If it has not been used, free it. free(0) is safe. */
|
||||
free(qinf.qname);
|
||||
}
|
||||
return 1;
|
||||
return dns_cache_store(env, msgqinf, msgrep, is_referral);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -365,7 +313,10 @@ causes_cycle(struct module_qstate* qstate, uint8_t* name, size_t namelen,
|
||||
qinf.qname_len = namelen;
|
||||
qinf.qtype = t;
|
||||
qinf.qclass = c;
|
||||
return (*qstate->env->detect_cycle)(qstate, &qinf);
|
||||
log_assert(fptr_whitelist_modenv_detect_cycle(
|
||||
qstate->env->detect_cycle));
|
||||
return (*qstate->env->detect_cycle)(qstate, &qinf,
|
||||
(uint16_t)(BIT_RD|BIT_CD), qstate->is_priming);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -382,9 +333,123 @@ iter_mark_cycle_targets(struct module_qstate* qstate, struct delegpt* dp)
|
||||
LDNS_RR_TYPE_A, qstate->qinfo.qclass)) {
|
||||
log_nametypeclass(VERB_DETAIL, "skipping target due "
|
||||
"to dependency cycle (harden-glue: no may "
|
||||
"fix this)", ns->name, LDNS_RR_TYPE_A,
|
||||
"fix some of the cycles)",
|
||||
ns->name, LDNS_RR_TYPE_A,
|
||||
qstate->qinfo.qclass);
|
||||
ns->resolved = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
iter_dp_is_useless(struct module_qstate* qstate, struct delegpt* dp)
|
||||
{
|
||||
struct delegpt_ns* ns;
|
||||
/* check:
|
||||
* o all NS items are required glue.
|
||||
* o no addresses are provided.
|
||||
* o RD qflag is on.
|
||||
* OR
|
||||
* o no addresses are provided.
|
||||
* o RD qflag is on.
|
||||
* o the query is for one of the nameservers in dp,
|
||||
* and that nameserver is a glue-name for this dp.
|
||||
*/
|
||||
if(!(qstate->query_flags&BIT_RD))
|
||||
return 0;
|
||||
/* either available or unused targets */
|
||||
if(dp->usable_list || dp->result_list)
|
||||
return 0;
|
||||
|
||||
/* see if query is for one of the nameservers, which is glue */
|
||||
if( (qstate->qinfo.qtype == LDNS_RR_TYPE_A ||
|
||||
qstate->qinfo.qtype == LDNS_RR_TYPE_AAAA) &&
|
||||
dname_subdomain_c(qstate->qinfo.qname, dp->name) &&
|
||||
delegpt_find_ns(dp, qstate->qinfo.qname,
|
||||
qstate->qinfo.qname_len))
|
||||
return 1;
|
||||
|
||||
for(ns = dp->nslist; ns; ns = ns->next) {
|
||||
if(ns->resolved) /* skip failed targets */
|
||||
continue;
|
||||
if(!dname_subdomain_c(ns->name, dp->name))
|
||||
return 0; /* one address is not required glue */
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
iter_indicates_dnssec(struct module_env* env, struct delegpt* dp,
|
||||
struct dns_msg* msg, uint16_t dclass)
|
||||
{
|
||||
/* information not available, !env->anchors can be common */
|
||||
if(!env || !env->anchors || !dp || !dp->name || !msg || !msg->rep)
|
||||
return 0;
|
||||
/* a trust anchor exists with this name, RRSIGs expected */
|
||||
if(anchor_find(env->anchors, dp->name, dp->namelabs, dp->namelen,
|
||||
dclass))
|
||||
return 1;
|
||||
/* see if DS rrset was given, in AUTH section */
|
||||
if(reply_find_rrset_section_ns(msg->rep, dp->name, dp->namelen,
|
||||
LDNS_RR_TYPE_DS, dclass))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
iter_msg_has_dnssec(struct dns_msg* msg)
|
||||
{
|
||||
size_t i;
|
||||
if(!msg || !msg->rep)
|
||||
return 0;
|
||||
for(i=0; i<msg->rep->an_numrrsets + msg->rep->ns_numrrsets; i++) {
|
||||
if(((struct packed_rrset_data*)msg->rep->rrsets[i]->
|
||||
entry.data)->rrsig_count > 0)
|
||||
return 1;
|
||||
}
|
||||
/* empty message has no DNSSEC info, with DNSSEC the reply is
|
||||
* not empty (NSEC) */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iter_msg_from_zone(struct dns_msg* msg, struct delegpt* dp,
|
||||
enum response_type type, uint16_t dclass)
|
||||
{
|
||||
if(!msg || !dp || !msg->rep || !dp->name)
|
||||
return 0;
|
||||
/* SOA RRset - always from reply zone */
|
||||
if(reply_find_rrset_section_an(msg->rep, dp->name, dp->namelen,
|
||||
LDNS_RR_TYPE_SOA, dclass) ||
|
||||
reply_find_rrset_section_ns(msg->rep, dp->name, dp->namelen,
|
||||
LDNS_RR_TYPE_SOA, dclass))
|
||||
return 1;
|
||||
if(type == RESPONSE_TYPE_REFERRAL) {
|
||||
size_t i;
|
||||
/* if it adds a single label, i.e. we expect .com,
|
||||
* and referral to example.com. NS ... , then origin zone
|
||||
* is .com. For a referral to sub.example.com. NS ... then
|
||||
* we do not know, since example.com. may be in between. */
|
||||
for(i=0; i<msg->rep->an_numrrsets+msg->rep->ns_numrrsets;
|
||||
i++) {
|
||||
struct ub_packed_rrset_key* s = msg->rep->rrsets[i];
|
||||
if(ntohs(s->rk.type) == LDNS_RR_TYPE_NS &&
|
||||
ntohs(s->rk.rrset_class) == dclass) {
|
||||
int l = dname_count_labels(s->rk.dname);
|
||||
if(l == dp->namelabs + 1 &&
|
||||
dname_strict_subdomain(s->rk.dname,
|
||||
l, dp->name, dp->namelabs))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
log_assert(type==RESPONSE_TYPE_ANSWER || type==RESPONSE_TYPE_CNAME);
|
||||
/* not a referral, and not lame delegation (upwards), so,
|
||||
* any NS rrset must be from the zone itself */
|
||||
if(reply_find_rrset_section_an(msg->rep, dp->name, dp->namelen,
|
||||
LDNS_RR_TYPE_NS, dclass) ||
|
||||
reply_find_rrset_section_ns(msg->rep, dp->name, dp->namelen,
|
||||
LDNS_RR_TYPE_NS, dclass))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+59
-10
@@ -42,12 +42,13 @@
|
||||
|
||||
#ifndef ITERATOR_ITER_UTILS_H
|
||||
#define ITERATOR_ITER_UTILS_H
|
||||
#include "iterator/iter_resptype.h"
|
||||
struct iter_env;
|
||||
struct config_file;
|
||||
struct module_env;
|
||||
struct delegpt_addr;
|
||||
struct delegpt;
|
||||
struct region;
|
||||
struct regional;
|
||||
struct msg_parse;
|
||||
struct ub_randstate;
|
||||
struct query_info;
|
||||
@@ -73,30 +74,32 @@ int iter_apply_cfg(struct iter_env* iter_env, struct config_file* cfg);
|
||||
* @param dp: delegation point with result list.
|
||||
* @param name: zone name (for lameness check).
|
||||
* @param namelen: length of name.
|
||||
* @param dnssec_expected: set to 0, if a known dnssec-lame server is selected
|
||||
* these are not preferred, but are used as a last resort.
|
||||
* @return best target or NULL if no target.
|
||||
* if not null, that target is removed from the result list in the dp.
|
||||
*/
|
||||
struct delegpt_addr* iter_server_selection(struct iter_env* iter_env,
|
||||
struct module_env* env, struct delegpt* dp, uint8_t* name,
|
||||
size_t namelen);
|
||||
size_t namelen, int* dnssec_expected);
|
||||
|
||||
/**
|
||||
* Allocate dns_msg from parsed msg, in region.
|
||||
* Allocate dns_msg from parsed msg, in regional.
|
||||
* @param pkt: packet.
|
||||
* @param msg: parsed message (cleaned and ready for region allocation).
|
||||
* @param region: region to use for allocation.
|
||||
* @param msg: parsed message (cleaned and ready for regional allocation).
|
||||
* @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 region* region);
|
||||
struct regional* regional);
|
||||
|
||||
/**
|
||||
* Copy a dns_msg to this region.
|
||||
* @param from: dns message, also in region.
|
||||
* @param region: region to use for allocation.
|
||||
* Copy a dns_msg to this regional.
|
||||
* @param from: dns message, also in regional.
|
||||
* @param regional: regional to use for allocation.
|
||||
* @return newly allocated dns_msg, or NULL on memory error.
|
||||
*/
|
||||
struct dns_msg* dns_copy_msg(struct dns_msg* from, struct region* region);
|
||||
struct dns_msg* dns_copy_msg(struct dns_msg* from, struct regional* regional);
|
||||
|
||||
/**
|
||||
* Allocate a dns_msg with malloc/alloc structure and store in dns cache.
|
||||
@@ -128,4 +131,50 @@ int iter_ns_probability(struct ub_randstate* rnd, int n, int m);
|
||||
*/
|
||||
void iter_mark_cycle_targets(struct module_qstate* qstate, struct delegpt* dp);
|
||||
|
||||
/**
|
||||
* See if delegation is useful or offers immediately no targets for
|
||||
* further recursion.
|
||||
* @param qstate: query state with RD flag and query name.
|
||||
* @param dp: delegpt to check.
|
||||
*/
|
||||
int iter_dp_is_useless(struct module_qstate* qstate, struct delegpt* dp);
|
||||
|
||||
/**
|
||||
* See if delegation is expected to have DNSSEC information (RRSIGs) in
|
||||
* its answers, or not. Inspects delegation point (name), trust anchors,
|
||||
* and delegation message (DS RRset) to determine this.
|
||||
* @param env: module env with trust anchors.
|
||||
* @param dp: delegation point.
|
||||
* @param msg: delegation message, with DS if a secure referral.
|
||||
* @param dclass: class of query.
|
||||
* @return 1 if dnssec is expected, 0 if not.
|
||||
*/
|
||||
int iter_indicates_dnssec(struct module_env* env, struct delegpt* dp,
|
||||
struct dns_msg* msg, uint16_t dclass);
|
||||
|
||||
/**
|
||||
* See if a message contains DNSSEC.
|
||||
* This is examined by looking for RRSIGs. With DNSSEC a valid answer,
|
||||
* nxdomain, nodata, referral or cname reply has RRSIGs in answer or auth
|
||||
* sections, sigs on answer data, SOA, DS, or NSEC/NSEC3 records.
|
||||
* @param msg: message to examine.
|
||||
* @return true if DNSSEC information was found.
|
||||
*/
|
||||
int iter_msg_has_dnssec(struct dns_msg* msg);
|
||||
|
||||
/**
|
||||
* See if a message is known to be from a certain zone.
|
||||
* This looks for SOA or NS rrsets, for answers.
|
||||
* For referrals, when one label is delegated, the zone is detected.
|
||||
* Does not look at signatures.
|
||||
* @param msg: the message to inspect.
|
||||
* @param dp: delegation point with zone name to look for.
|
||||
* @param type: type of message.
|
||||
* @param dclass: class of query.
|
||||
* @return true if message is certain to be from zone in dp->name.
|
||||
* false if not sure (empty msg), or not from the zone.
|
||||
*/
|
||||
int iter_msg_from_zone(struct dns_msg* msg, struct delegpt* dp,
|
||||
enum response_type type, uint16_t dclass);
|
||||
|
||||
#endif /* ITERATOR_ITER_UTILS_H */
|
||||
|
||||
+343
-125
@@ -54,12 +54,12 @@
|
||||
#include "util/module.h"
|
||||
#include "util/netevent.h"
|
||||
#include "util/net_help.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/data/dname.h"
|
||||
#include "util/data/msgencode.h"
|
||||
#include "util/fptr_wlist.h"
|
||||
|
||||
/** iterator init */
|
||||
static int
|
||||
int
|
||||
iter_init(struct module_env* env, int id)
|
||||
{
|
||||
struct iter_env* iter_env = (struct iter_env*)calloc(1,
|
||||
@@ -76,27 +76,26 @@ iter_init(struct module_env* env, int id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** iterator deinit */
|
||||
static void
|
||||
void
|
||||
iter_deinit(struct module_env* env, int id)
|
||||
{
|
||||
struct iter_env* iter_env;
|
||||
if(!env || !env->modinfo)
|
||||
if(!env || !env->modinfo || !env->modinfo[id])
|
||||
return;
|
||||
iter_env = (struct iter_env*)env->modinfo[id];
|
||||
free(iter_env->target_fetch_policy);
|
||||
hints_delete(iter_env->hints);
|
||||
forwards_delete(iter_env->fwds);
|
||||
donotq_delete(iter_env->donotq);
|
||||
if(iter_env)
|
||||
free(iter_env);
|
||||
free(iter_env);
|
||||
env->modinfo[id] = NULL;
|
||||
}
|
||||
|
||||
/** new query for iterator */
|
||||
static int
|
||||
iter_new(struct module_qstate* qstate, int id)
|
||||
{
|
||||
struct iter_qstate* iq = (struct iter_qstate*)region_alloc(
|
||||
struct iter_qstate* iq = (struct iter_qstate*)regional_alloc(
|
||||
qstate->region, sizeof(struct iter_qstate));
|
||||
qstate->minfo[id] = iq;
|
||||
if(!iq)
|
||||
@@ -104,17 +103,19 @@ iter_new(struct module_qstate* qstate, int id)
|
||||
memset(iq, 0, sizeof(*iq));
|
||||
iq->state = INIT_REQUEST_STATE;
|
||||
iq->final_state = FINISHED_STATE;
|
||||
iq->prepend_list = NULL;
|
||||
iq->prepend_last = NULL;
|
||||
iq->an_prepend_list = NULL;
|
||||
iq->an_prepend_last = NULL;
|
||||
iq->ns_prepend_list = NULL;
|
||||
iq->ns_prepend_last = NULL;
|
||||
iq->dp = NULL;
|
||||
iq->depth = 0;
|
||||
iq->num_target_queries = 0;
|
||||
iq->num_current_queries = 0;
|
||||
iq->query_restart_count = 0;
|
||||
iq->referral_count = 0;
|
||||
iq->priming = 0;
|
||||
iq->priming_stub = 0;
|
||||
iq->wait_priming_stub = 0;
|
||||
iq->refetch_glue = 0;
|
||||
iq->dnssec_expected = 0;
|
||||
iq->chase_flags = qstate->query_flags;
|
||||
/* Start with the (current) qname. */
|
||||
iq->qchase = qstate->qinfo;
|
||||
@@ -187,7 +188,7 @@ error_supers(struct module_qstate* qstate, int id, struct module_qstate* super)
|
||||
/* not interested */
|
||||
verbose(VERB_ALGO, "subq error, but not interested");
|
||||
log_query_info(VERB_ALGO, "superq", &super->qinfo);
|
||||
delegpt_log(super_iq->dp);
|
||||
delegpt_log(VERB_ALGO, super_iq->dp);
|
||||
log_assert(0);
|
||||
return;
|
||||
}
|
||||
@@ -217,65 +218,107 @@ error_response(struct module_qstate* qstate, int id, int rcode)
|
||||
verbose(VERB_DETAIL, "return error response %s",
|
||||
ldns_lookup_by_id(ldns_rcodes, rcode)?
|
||||
ldns_lookup_by_id(ldns_rcodes, rcode)->name:"??");
|
||||
/* tell clients that we failed */
|
||||
(*qstate->env->query_done)(qstate, rcode, NULL);
|
||||
/* tell our parents that we failed */
|
||||
(*qstate->env->walk_supers)(qstate, id, &error_supers);
|
||||
qstate->return_rcode = rcode;
|
||||
qstate->return_msg = NULL;
|
||||
qstate->ext_state[id] = module_finished;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** prepend the prepend list in the answer section of dns_msg */
|
||||
/** prepend the prepend list in the answer and authority section of dns_msg */
|
||||
static int
|
||||
iter_prepend(struct iter_qstate* iq, struct dns_msg* msg,
|
||||
struct region* region)
|
||||
struct regional* region)
|
||||
{
|
||||
struct iter_prep_list* p;
|
||||
struct ub_packed_rrset_key** sets;
|
||||
size_t num = 0;
|
||||
for(p = iq->prepend_list; p; p = p->next)
|
||||
num++;
|
||||
if(num == 0)
|
||||
size_t num_an = 0, num_ns = 0;;
|
||||
for(p = iq->an_prepend_list; p; p = p->next)
|
||||
num_an++;
|
||||
for(p = iq->ns_prepend_list; p; p = p->next)
|
||||
num_ns++;
|
||||
if(num_an + num_ns == 0)
|
||||
return 1;
|
||||
verbose(VERB_ALGO, "prepending %d rrsets", (int)num);
|
||||
sets = region_alloc(region, (num+msg->rep->rrset_count) *
|
||||
verbose(VERB_ALGO, "prepending %d rrsets", (int)num_an + (int)num_ns);
|
||||
sets = regional_alloc(region, (num_an+num_ns+msg->rep->rrset_count) *
|
||||
sizeof(struct ub_packed_rrset_key*));
|
||||
if(!sets)
|
||||
return 0;
|
||||
memcpy(sets+num, msg->rep->rrsets, msg->rep->rrset_count *
|
||||
sizeof(struct ub_packed_rrset_key*));
|
||||
num = 0;
|
||||
for(p = iq->prepend_list; p; p = p->next) {
|
||||
sets[num++] = p->rrset;
|
||||
/* ANSWER section */
|
||||
num_an = 0;
|
||||
for(p = iq->an_prepend_list; p; p = p->next) {
|
||||
sets[num_an++] = p->rrset;
|
||||
}
|
||||
msg->rep->rrset_count += num;
|
||||
msg->rep->an_numrrsets += num;
|
||||
memcpy(sets+num_an, msg->rep->rrsets, msg->rep->an_numrrsets *
|
||||
sizeof(struct ub_packed_rrset_key*));
|
||||
/* AUTH section */
|
||||
num_ns = 0;
|
||||
for(p = iq->ns_prepend_list; p; p = p->next) {
|
||||
sets[msg->rep->an_numrrsets + num_an + num_ns++] = p->rrset;
|
||||
}
|
||||
memcpy(sets + num_an + msg->rep->an_numrrsets + num_ns,
|
||||
msg->rep->rrsets + msg->rep->an_numrrsets,
|
||||
(msg->rep->ns_numrrsets + msg->rep->ar_numrrsets) *
|
||||
sizeof(struct ub_packed_rrset_key*));
|
||||
|
||||
/* if the rcode was NXDOMAIN, and we prepended DNAME/CNAMEs, then
|
||||
* it should now be NOERROR. */
|
||||
if(FLAGS_GET_RCODE(msg->rep->flags) == LDNS_RCODE_NXDOMAIN) {
|
||||
FLAGS_SET_RCODE(msg->rep->flags, LDNS_RCODE_NOERROR);
|
||||
}
|
||||
msg->rep->rrset_count += num_an + num_ns;
|
||||
msg->rep->an_numrrsets += num_an;
|
||||
msg->rep->ns_numrrsets += num_ns;
|
||||
msg->rep->rrsets = sets;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add rrset to prepend list
|
||||
* Add rrset to ANSWER prepend list
|
||||
* @param qstate: query state.
|
||||
* @param iq: iterator query state.
|
||||
* @param rrset: rrset to add.
|
||||
* @return false on failure (malloc).
|
||||
*/
|
||||
static int
|
||||
iter_add_prepend(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
iter_add_prepend_answer(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
struct ub_packed_rrset_key* rrset)
|
||||
{
|
||||
struct iter_prep_list* p = (struct iter_prep_list*)region_alloc(
|
||||
struct iter_prep_list* p = (struct iter_prep_list*)regional_alloc(
|
||||
qstate->region, sizeof(struct iter_prep_list));
|
||||
if(!p)
|
||||
return 0;
|
||||
p->rrset = rrset;
|
||||
p->next = NULL;
|
||||
/* add at end */
|
||||
if(iq->prepend_last)
|
||||
iq->prepend_last->next = p;
|
||||
else iq->prepend_list = p;
|
||||
iq->prepend_last = p;
|
||||
if(iq->an_prepend_last)
|
||||
iq->an_prepend_last->next = p;
|
||||
else iq->an_prepend_list = p;
|
||||
iq->an_prepend_last = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add rrset to AUTHORITY prepend list
|
||||
* @param qstate: query state.
|
||||
* @param iq: iterator query state.
|
||||
* @param rrset: rrset to add.
|
||||
* @return false on failure (malloc).
|
||||
*/
|
||||
static int
|
||||
iter_add_prepend_auth(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
struct ub_packed_rrset_key* rrset)
|
||||
{
|
||||
struct iter_prep_list* p = (struct iter_prep_list*)regional_alloc(
|
||||
qstate->region, sizeof(struct iter_prep_list));
|
||||
if(!p)
|
||||
return 0;
|
||||
p->rrset = rrset;
|
||||
p->next = NULL;
|
||||
/* add at end */
|
||||
if(iq->ns_prepend_last)
|
||||
iq->ns_prepend_last->next = p;
|
||||
else iq->ns_prepend_list = p;
|
||||
iq->ns_prepend_last = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -312,7 +355,7 @@ handle_cname_response(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
* directly. */
|
||||
if(ntohs(r->rk.type) == LDNS_RR_TYPE_DNAME &&
|
||||
dname_strict_subdomain_c(*mname, r->rk.dname)) {
|
||||
if(!iter_add_prepend(qstate, iq, r))
|
||||
if(!iter_add_prepend_answer(qstate, iq, r))
|
||||
return 0;
|
||||
continue;
|
||||
}
|
||||
@@ -320,13 +363,24 @@ handle_cname_response(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
if(ntohs(r->rk.type) == LDNS_RR_TYPE_CNAME &&
|
||||
query_dname_compare(*mname, r->rk.dname) == 0) {
|
||||
/* Add this relevant CNAME rrset to the prepend list.*/
|
||||
if(!iter_add_prepend(qstate, iq, r))
|
||||
if(!iter_add_prepend_answer(qstate, iq, r))
|
||||
return 0;
|
||||
get_cname_target(r, mname, mname_len);
|
||||
}
|
||||
|
||||
/* Other rrsets in the section are ignored. */
|
||||
}
|
||||
/* add authority rrsets to authority prepend, for wildcarded CNAMEs */
|
||||
for(i=msg->rep->an_numrrsets; i<msg->rep->an_numrrsets +
|
||||
msg->rep->ns_numrrsets; i++) {
|
||||
struct ub_packed_rrset_key* r = msg->rep->rrsets[i];
|
||||
/* only add NSEC/NSEC3, as they may be needed for validation */
|
||||
if(ntohs(r->rk.type) == LDNS_RR_TYPE_NSEC ||
|
||||
ntohs(r->rk.type) == LDNS_RR_TYPE_NSEC3) {
|
||||
if(!iter_add_prepend_auth(qstate, iq, r))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -376,11 +430,10 @@ generate_sub_request(uint8_t* qname, size_t qnamelen, uint16_t qtype,
|
||||
* the resolution chain, which might have a validator. We are
|
||||
* uninterested in validating things not on the direct resolution
|
||||
* path. */
|
||||
/* Turned off! CD does not make a difference in query results.
|
||||
qstate->query_flags |= BIT_CD;
|
||||
*/
|
||||
qflags |= BIT_CD;
|
||||
|
||||
/* attach subquery, lookup existing or make a new one */
|
||||
log_assert(fptr_whitelist_modenv_attach_sub(qstate->env->attach_sub));
|
||||
if(!(*qstate->env->attach_sub)(qstate, &qinf, qflags, prime, &subq)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -389,10 +442,12 @@ generate_sub_request(uint8_t* qname, size_t qnamelen, uint16_t qtype,
|
||||
/* initialise the new subquery */
|
||||
subq->curmod = id;
|
||||
subq->ext_state[id] = module_state_initial;
|
||||
subq->minfo[id] = region_alloc(subq->region,
|
||||
subq->minfo[id] = regional_alloc(subq->region,
|
||||
sizeof(struct iter_qstate));
|
||||
if(!subq->minfo[id]) {
|
||||
log_err("init subq: out of memory");
|
||||
log_assert(fptr_whitelist_modenv_kill_sub(
|
||||
qstate->env->kill_sub));
|
||||
(*qstate->env->kill_sub)(subq);
|
||||
return 0;
|
||||
}
|
||||
@@ -433,6 +488,12 @@ prime_root(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
verbose(VERB_ALGO, "Cannot prime due to lack of hints");
|
||||
return 0;
|
||||
}
|
||||
/* copy dp; to avoid messing up available list for other thr/queries */
|
||||
dp = delegpt_copy(dp, qstate->region);
|
||||
if(!dp) {
|
||||
log_err("out of memory priming root, copydp");
|
||||
return 0;
|
||||
}
|
||||
/* Priming requests start at the QUERYTARGETS state, skipping
|
||||
* the normal INIT state logic (which would cause an infloop). */
|
||||
if(!generate_sub_request((uint8_t*)"\000", 1, LDNS_RR_TYPE_NS,
|
||||
@@ -448,7 +509,6 @@ prime_root(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
subiq->dp = dp;
|
||||
/* there should not be any target queries. */
|
||||
subiq->num_target_queries = 0;
|
||||
subiq->priming = 1;
|
||||
}
|
||||
|
||||
/* this module stops, our submodule starts, and does the query. */
|
||||
@@ -500,13 +560,21 @@ prime_stub(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
(struct iter_qstate*)subq->minfo[id];
|
||||
|
||||
/* Set the initial delegation point to the hint. */
|
||||
subiq->dp = stub_dp;
|
||||
/* make copy to avoid use of stub dp by different qs/threads */
|
||||
subiq->dp = delegpt_copy(stub_dp, subq->region);
|
||||
if(!subiq->dp) {
|
||||
log_err("out of memory priming stub, copydp");
|
||||
log_assert(fptr_whitelist_modenv_kill_sub(
|
||||
qstate->env->kill_sub));
|
||||
(*qstate->env->kill_sub)(subq);
|
||||
(void)error_response(qstate, id, LDNS_RCODE_SERVFAIL);
|
||||
return 1; /* return 1 to make module stop, with error */
|
||||
}
|
||||
/* there should not be any target queries -- although there
|
||||
* wouldn't be anyway, since stub hints never have
|
||||
* missing targets. */
|
||||
subiq->num_target_queries = 0;
|
||||
subiq->priming = 1;
|
||||
subiq->priming_stub = 1;
|
||||
subiq->wait_priming_stub = 1;
|
||||
}
|
||||
|
||||
/* this module stops, our submodule starts, and does the query. */
|
||||
@@ -599,7 +667,9 @@ processInitRequest(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
/* handle positive cache response */
|
||||
enum response_type type = response_type_from_cache(msg,
|
||||
&iq->qchase);
|
||||
log_dns_msg("msg from cache lookup", &msg->qinfo, msg->rep);
|
||||
if(verbosity >= VERB_ALGO)
|
||||
log_dns_msg("msg from cache lookup", &msg->qinfo,
|
||||
msg->rep);
|
||||
|
||||
if(type == RESPONSE_TYPE_CNAME) {
|
||||
uint8_t* sname = 0;
|
||||
@@ -644,6 +714,10 @@ processInitRequest(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
* When re-fetching glue we also need to ask the parent.
|
||||
*/
|
||||
if(iq->refetch_glue) {
|
||||
if(!iq->dp) {
|
||||
log_err("internal or malloc fail: no dp for refetch");
|
||||
return error_response(qstate, id, LDNS_RCODE_SERVFAIL);
|
||||
}
|
||||
delname = iq->dp->name;
|
||||
delnamelen = iq->dp->namelen;
|
||||
} else {
|
||||
@@ -651,34 +725,88 @@ processInitRequest(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
delnamelen = iq->qchase.qname_len;
|
||||
}
|
||||
if((iq->qchase.qtype == LDNS_RR_TYPE_DS || iq->refetch_glue)
|
||||
&& delname[0] != 0) {
|
||||
&& !dname_is_root(delname)) {
|
||||
/* do not adjust root label, remove first label from delname */
|
||||
size_t lablen = delname[0] + 1;
|
||||
delname += lablen;
|
||||
delnamelen -= lablen;
|
||||
dname_remove_label(&delname, &delnamelen);
|
||||
iq->refetch_glue = 0; /* if CNAME causes restart, no refetch */
|
||||
}
|
||||
|
||||
/* Lookup the delegation in the cache. If null, then the cache needs
|
||||
* to be primed for the qclass. */
|
||||
iq->dp = dns_cache_find_delegation(qstate->env, delname, delnamelen,
|
||||
iq->qchase.qtype, iq->qchase.qclass, qstate->region,
|
||||
&iq->deleg_msg);
|
||||
while(1) {
|
||||
|
||||
/* Lookup the delegation in the cache. If null, then the
|
||||
* cache needs to be primed for the qclass. */
|
||||
iq->dp = dns_cache_find_delegation(qstate->env, delname,
|
||||
delnamelen, iq->qchase.qtype, iq->qchase.qclass,
|
||||
qstate->region, &iq->deleg_msg, (uint32_t)time(NULL));
|
||||
|
||||
/* If the cache has returned nothing, then we have a root priming
|
||||
* situation. */
|
||||
if(iq->dp == NULL) {
|
||||
/* Note that the result of this will set a new
|
||||
* DelegationPoint based on the result of priming. */
|
||||
if(!prime_root(qstate, iq, ie, id, iq->qchase.qclass))
|
||||
return error_response(qstate, id, LDNS_RCODE_REFUSED);
|
||||
/* If the cache has returned nothing, then we have a
|
||||
* root priming situation. */
|
||||
if(iq->dp == NULL) {
|
||||
/* Note that the result of this will set a new
|
||||
* DelegationPoint based on the result of priming. */
|
||||
if(!prime_root(qstate, iq, ie, id, iq->qchase.qclass))
|
||||
return error_response(qstate, id,
|
||||
LDNS_RCODE_REFUSED);
|
||||
|
||||
/* priming creates and sends a subordinate query, with
|
||||
* this query as the parent. So further processing for
|
||||
* this event will stop until reactivated by the results
|
||||
* of priming. */
|
||||
return 0;
|
||||
/* priming creates and sends a subordinate query, with
|
||||
* this query as the parent. So further processing for
|
||||
* this event will stop until reactivated by the
|
||||
* results of priming. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* see if this dp not useless.
|
||||
* It is useless if:
|
||||
* o all NS items are required glue.
|
||||
* or the query is for NS item that is required glue.
|
||||
* o no addresses are provided.
|
||||
* o RD qflag is on.
|
||||
* Instead, go up one level, and try to get even further
|
||||
* If the root was useless, use safety belt information.
|
||||
* Only check cache returns, because replies for servers
|
||||
* could be useless but lead to loops (bumping into the
|
||||
* same server reply) if useless-checked.
|
||||
*/
|
||||
if(iter_dp_is_useless(qstate, iq->dp)) {
|
||||
if(dname_is_root(iq->dp->name)) {
|
||||
/* use safety belt */
|
||||
verbose(VERB_OPS, "Priming problem: NS but "
|
||||
"no addresses. Fallback to the safety belt.");
|
||||
iq->dp = hints_lookup_root(ie->hints,
|
||||
iq->qchase.qclass);
|
||||
/* note deleg_msg is from previous lookup,
|
||||
* but RD is on, so it is not used */
|
||||
if(!iq->dp) {
|
||||
log_err("internal error: no hints dp");
|
||||
return error_response(qstate, id,
|
||||
LDNS_RCODE_REFUSED);
|
||||
}
|
||||
iq->dp = delegpt_copy(iq->dp, qstate->region);
|
||||
if(!iq->dp) {
|
||||
log_err("out of memory in safety belt");
|
||||
return error_response(qstate, id,
|
||||
LDNS_RCODE_SERVFAIL);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
verbose(VERB_ALGO,
|
||||
"cache delegation was useless:");
|
||||
delegpt_log(VERB_ALGO, iq->dp);
|
||||
/* go up */
|
||||
delname = iq->dp->name;
|
||||
delnamelen = iq->dp->namelen;
|
||||
dname_remove_label(&delname, &delnamelen);
|
||||
}
|
||||
} else break;
|
||||
}
|
||||
|
||||
verbose(VERB_ALGO, "cache delegation returns delegpt");
|
||||
delegpt_log(VERB_ALGO, iq->dp);
|
||||
|
||||
/* if the cache reply dp equals a validation anchor or msg has DS,
|
||||
* then DNSSEC RRSIGs are expected in the reply */
|
||||
iq->dnssec_expected = iter_indicates_dnssec(qstate->env, iq->dp,
|
||||
iq->deleg_msg, iq->qchase.qclass);
|
||||
|
||||
/* Reset the RD flag. If this is a query restart, then the RD
|
||||
* will have been turned off. */
|
||||
if(qstate->query_flags & BIT_RD)
|
||||
@@ -921,6 +1049,15 @@ processQueryTargets(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
verbose(VERB_DETAIL, "Failed to get a delegation, giving up");
|
||||
return error_response(qstate, id, LDNS_RCODE_SERVFAIL);
|
||||
}
|
||||
delegpt_log(VERB_ALGO, iq->dp);
|
||||
|
||||
if(iq->num_current_queries>0) {
|
||||
/* already busy answering a query, this restart is because
|
||||
* more delegpt addrs became available, wait for existing
|
||||
* query. */
|
||||
verbose(VERB_ALGO, "woke up, but wait for outstanding query");
|
||||
return 0;
|
||||
}
|
||||
|
||||
tf_policy = 0;
|
||||
if(iq->depth <= ie->max_dependency_depth) {
|
||||
@@ -946,7 +1083,7 @@ processQueryTargets(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
|
||||
/* Select the next usable target, filtering out unsuitable targets. */
|
||||
target = iter_server_selection(ie, qstate->env, iq->dp,
|
||||
iq->dp->name, iq->dp->namelen);
|
||||
iq->dp->name, iq->dp->namelen, &iq->dnssec_expected);
|
||||
|
||||
/* If no usable target was selected... */
|
||||
if(!target) {
|
||||
@@ -1002,23 +1139,21 @@ processQueryTargets(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
iq->num_current_queries);
|
||||
return 0;
|
||||
}
|
||||
/* move other targets to slumber list */
|
||||
if(iq->num_target_queries>0) {
|
||||
(*qstate->env->detach_subs)(qstate);
|
||||
iq->num_target_queries = 0;
|
||||
}
|
||||
|
||||
/* We have a valid target. */
|
||||
log_query_info(VERB_DETAIL, "sending query:", &iq->qchase);
|
||||
log_name_addr(VERB_DETAIL, "sending to target:", iq->dp->name,
|
||||
&target->addr, target->addrlen);
|
||||
log_assert(fptr_whitelist_modenv_send_query(qstate->env->send_query));
|
||||
outq = (*qstate->env->send_query)(
|
||||
iq->qchase.qname, iq->qchase.qname_len,
|
||||
iq->qchase.qtype, iq->qchase.qclass,
|
||||
iq->chase_flags, 1, &target->addr, target->addrlen, qstate);
|
||||
iq->chase_flags, EDNS_DO|BIT_CD,
|
||||
&target->addr, target->addrlen, qstate);
|
||||
if(!outq) {
|
||||
log_err("error sending query to auth server; skip this address");
|
||||
log_addr("error for address:", &target->addr, target->addrlen);
|
||||
log_addr(0, "error for address:",
|
||||
&target->addr, target->addrlen);
|
||||
return next_state(iq, QUERYTARGETS_STATE);
|
||||
}
|
||||
outbound_list_insert(&iq->outlist, outq);
|
||||
@@ -1045,18 +1180,36 @@ static int
|
||||
processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
int id)
|
||||
{
|
||||
int dnsseclame = 0;
|
||||
enum response_type type;
|
||||
iq->num_current_queries--;
|
||||
if(iq->response == NULL) {
|
||||
verbose(VERB_ALGO, "query response was timeout");
|
||||
return next_state(iq, QUERYTARGETS_STATE);
|
||||
}
|
||||
type = response_type_from_server(iq->response, &iq->qchase, iq->dp);
|
||||
type = response_type_from_server((int)(iq->chase_flags&BIT_RD),
|
||||
iq->response, &iq->qchase, iq->dp);
|
||||
if(type == RESPONSE_TYPE_REFERRAL && (iq->chase_flags&BIT_RD)) {
|
||||
/* When forwarding (RD bit is set), we handle referrals
|
||||
* differently. No queries should be sent elsewhere */
|
||||
type = RESPONSE_TYPE_ANSWER;
|
||||
}
|
||||
if(iq->dnssec_expected && !(iq->chase_flags&BIT_RD)
|
||||
&& type != RESPONSE_TYPE_LAME
|
||||
&& type != RESPONSE_TYPE_THROWAWAY
|
||||
&& type != RESPONSE_TYPE_UNTYPED) {
|
||||
/* a possible answer, see if it is missing DNSSEC */
|
||||
/* but not when forwarding, so we dont mark fwder lame */
|
||||
/* also make sure the answer is from the zone we expected,
|
||||
* otherwise, (due to parent,child on same server), we
|
||||
* might mark the server,zone lame inappropriately */
|
||||
if(!iter_msg_has_dnssec(iq->response) &&
|
||||
iter_msg_from_zone(iq->response, iq->dp, type,
|
||||
iq->qchase.qclass)) {
|
||||
type = RESPONSE_TYPE_LAME;
|
||||
dnsseclame = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* handle each of the type cases */
|
||||
if(type == RESPONSE_TYPE_ANSWER) {
|
||||
@@ -1069,6 +1222,8 @@ processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
/* close down outstanding requests to be discarded */
|
||||
outbound_list_clear(&iq->outlist);
|
||||
iq->num_current_queries = 0;
|
||||
log_assert(fptr_whitelist_modenv_detach_subs(
|
||||
qstate->env->detach_subs));
|
||||
(*qstate->env->detach_subs)(qstate);
|
||||
iq->num_target_queries = 0;
|
||||
return final_state(iq);
|
||||
@@ -1091,9 +1246,13 @@ processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
if(!cache_fill_missing(qstate->env, iq->qchase.qclass,
|
||||
qstate->region, iq->dp))
|
||||
return error_response(qstate, id, LDNS_RCODE_SERVFAIL);
|
||||
delegpt_log(iq->dp);
|
||||
delegpt_log(VERB_ALGO, iq->dp);
|
||||
/* Count this as a referral. */
|
||||
iq->referral_count++;
|
||||
/* see if the next dp is a trust anchor, or a DS was sent
|
||||
* along, indicating dnssec is expected for next zone */
|
||||
iq->dnssec_expected = iter_indicates_dnssec(qstate->env,
|
||||
iq->dp, iq->response, iq->qchase.qclass);
|
||||
|
||||
/* stop current outstanding queries.
|
||||
* FIXME: should the outstanding queries be waited for and
|
||||
@@ -1101,6 +1260,8 @@ processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
*/
|
||||
outbound_list_clear(&iq->outlist);
|
||||
iq->num_current_queries = 0;
|
||||
log_assert(fptr_whitelist_modenv_detach_subs(
|
||||
qstate->env->detach_subs));
|
||||
(*qstate->env->detach_subs)(qstate);
|
||||
iq->num_target_queries = 0;
|
||||
verbose(VERB_ALGO, "cleared outbound list for next round");
|
||||
@@ -1112,7 +1273,9 @@ processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
* reset of the query state and go back to INIT_REQUEST_STATE).
|
||||
*/
|
||||
verbose(VERB_DETAIL, "query response was CNAME");
|
||||
log_dns_msg("cname msg", &iq->response->qinfo, iq->response->rep);
|
||||
if(verbosity >= VERB_ALGO)
|
||||
log_dns_msg("cname msg", &iq->response->qinfo,
|
||||
iq->response->rep);
|
||||
/* Process the CNAME response. */
|
||||
if(!handle_cname_response(qstate, iq, iq->response,
|
||||
&sname, &snamelen))
|
||||
@@ -1129,6 +1292,7 @@ processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
/* Clear the query state, since this is a query restart. */
|
||||
iq->deleg_msg = NULL;
|
||||
iq->dp = NULL;
|
||||
iq->dnssec_expected = 0;
|
||||
/* Note the query restart. */
|
||||
iq->query_restart_count++;
|
||||
|
||||
@@ -1138,6 +1302,8 @@ processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
*/
|
||||
outbound_list_clear(&iq->outlist);
|
||||
iq->num_current_queries = 0;
|
||||
log_assert(fptr_whitelist_modenv_detach_subs(
|
||||
qstate->env->detach_subs));
|
||||
(*qstate->env->detach_subs)(qstate);
|
||||
iq->num_target_queries = 0;
|
||||
verbose(VERB_ALGO, "cleared outbound list for query restart");
|
||||
@@ -1145,15 +1311,18 @@ processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
return next_state(iq, INIT_REQUEST_STATE);
|
||||
} else if(type == RESPONSE_TYPE_LAME) {
|
||||
/* Cache the LAMEness. */
|
||||
verbose(VERB_DETAIL, "query response was LAME");
|
||||
verbose(VERB_DETAIL, "query response was %sLAME",
|
||||
dnsseclame?"DNSSEC ":"");
|
||||
if(qstate->reply) {
|
||||
/* need addr for lameness cache, but we may have
|
||||
* gotten this from cache, so test to be sure */
|
||||
if(!infra_set_lame(qstate->env->infra_cache,
|
||||
&qstate->reply->addr, qstate->reply->addrlen,
|
||||
iq->dp->name, iq->dp->namelen, time(NULL)))
|
||||
iq->dp->name, iq->dp->namelen, time(NULL),
|
||||
dnsseclame))
|
||||
log_err("mark host lame: out of memory");
|
||||
} else log_err("lame response from cache");
|
||||
} else log_err("%slame response from cache",
|
||||
dnsseclame?"DNSSEC ":"");
|
||||
} else if(type == RESPONSE_TYPE_THROWAWAY) {
|
||||
/* LAME and THROWAWAY responses are handled the same way.
|
||||
* In this case, the event is just sent directly back to
|
||||
@@ -1184,17 +1353,13 @@ processQueryResponse(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
static void
|
||||
prime_supers(struct module_qstate* qstate, int id, struct module_qstate* forq)
|
||||
{
|
||||
struct iter_qstate* iq = (struct iter_qstate*)qstate->minfo[id];
|
||||
struct iter_qstate* foriq = (struct iter_qstate*)forq->minfo[id];
|
||||
struct delegpt* dp = NULL;
|
||||
enum response_type type = response_type_from_server(iq->response,
|
||||
&iq->qchase, iq->dp);
|
||||
|
||||
log_assert(iq->priming || iq->priming_stub);
|
||||
if(type == RESPONSE_TYPE_ANSWER) {
|
||||
/* Convert our response to a delegation point */
|
||||
dp = delegpt_from_message(iq->response, forq->region);
|
||||
}
|
||||
log_assert(qstate->is_priming || foriq->wait_priming_stub);
|
||||
log_assert(qstate->return_rcode == LDNS_RCODE_NOERROR);
|
||||
/* Convert our response to a delegation point */
|
||||
dp = delegpt_from_message(qstate->return_msg, forq->region);
|
||||
if(!dp) {
|
||||
/* if there is no convertable delegation point, then
|
||||
* the ANSWER type was (presumably) a negative answer. */
|
||||
@@ -1205,10 +1370,10 @@ prime_supers(struct module_qstate* qstate, int id, struct module_qstate* forq)
|
||||
return;
|
||||
}
|
||||
|
||||
log_query_info(VERB_DETAIL, "priming successful for", &iq->qchase);
|
||||
delegpt_log(dp);
|
||||
log_query_info(VERB_DETAIL, "priming successful for", &qstate->qinfo);
|
||||
delegpt_log(VERB_ALGO, dp);
|
||||
foriq->dp = dp;
|
||||
foriq->deleg_msg = dns_copy_msg(iq->response, forq->region);
|
||||
foriq->deleg_msg = dns_copy_msg(qstate->return_msg, forq->region);
|
||||
if(!foriq->deleg_msg) {
|
||||
log_err("copy prime response: out of memory");
|
||||
foriq->dp = NULL;
|
||||
@@ -1218,9 +1383,10 @@ prime_supers(struct module_qstate* qstate, int id, struct module_qstate* forq)
|
||||
|
||||
/* root priming responses go to init stage 2, priming stub
|
||||
* responses to to stage 3. */
|
||||
if(iq->priming_stub)
|
||||
if(foriq->wait_priming_stub) {
|
||||
foriq->state = INIT_REQUEST_3_STATE;
|
||||
else foriq->state = INIT_REQUEST_2_STATE;
|
||||
foriq->wait_priming_stub = 0;
|
||||
} else foriq->state = INIT_REQUEST_2_STATE;
|
||||
/* because we are finished, the parent will be reactivated */
|
||||
}
|
||||
|
||||
@@ -1239,14 +1405,19 @@ prime_supers(struct module_qstate* qstate, int id, struct module_qstate* forq)
|
||||
static int
|
||||
processPrimeResponse(struct module_qstate* qstate, int id)
|
||||
{
|
||||
struct iter_qstate* iq = (struct iter_qstate*)qstate->minfo[id];
|
||||
enum response_type type = response_type_from_server(0, iq->response,
|
||||
&iq->qchase, iq->dp);
|
||||
if(type == RESPONSE_TYPE_ANSWER) {
|
||||
qstate->return_rcode = LDNS_RCODE_NOERROR;
|
||||
qstate->return_msg = iq->response;
|
||||
} else {
|
||||
qstate->return_rcode = LDNS_RCODE_SERVFAIL;
|
||||
qstate->return_msg = NULL;
|
||||
}
|
||||
|
||||
/* This event is finished. */
|
||||
qstate->ext_state[id] = module_finished;
|
||||
|
||||
/* there should be no outside clients subscribed tell them to
|
||||
* bugger off (and retry) */
|
||||
(*qstate->env->query_done)(qstate, LDNS_RCODE_SERVFAIL, NULL);
|
||||
/* tell interested supers that priming is done */
|
||||
(*qstate->env->walk_supers)(qstate, id, &prime_supers);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1257,7 +1428,7 @@ processPrimeResponse(struct module_qstate* qstate, int id)
|
||||
* to received target responses (caching, updating the current delegation
|
||||
* point, etc).
|
||||
* Callback from walk_supers for every super state that is interested in
|
||||
* the results from thiis query.
|
||||
* the results from this query.
|
||||
*
|
||||
* @param qstate: query state.
|
||||
* @param id: module id.
|
||||
@@ -1271,8 +1442,11 @@ processTargetResponse(struct module_qstate* qstate, int id,
|
||||
struct iter_qstate* foriq = (struct iter_qstate*)forq->minfo[id];
|
||||
struct ub_packed_rrset_key* rrset;
|
||||
struct delegpt_ns* dpns;
|
||||
log_assert(qstate->return_rcode == LDNS_RCODE_NOERROR);
|
||||
|
||||
foriq->state = QUERYTARGETS_STATE;
|
||||
log_query_info(VERB_ALGO, "processTargetResponse", &qstate->qinfo);
|
||||
log_query_info(VERB_ALGO, "processTargetResponse super", &forq->qinfo);
|
||||
|
||||
/* check to see if parent event is still interested (in orig name). */
|
||||
dpns = delegpt_find_ns(foriq->dp, qstate->qinfo.qname,
|
||||
@@ -1297,7 +1471,7 @@ processTargetResponse(struct module_qstate* qstate, int id,
|
||||
* the original event.
|
||||
* NOTE: we could only look for the AnswerRRset if the
|
||||
* response type was ANSWER. */
|
||||
rrset = reply_find_answer_rrset(&iq->qchase, iq->response->rep);
|
||||
rrset = reply_find_answer_rrset(&iq->qchase, qstate->return_msg->rep);
|
||||
if(rrset) {
|
||||
/* if CNAMEs have been followed - add new NS to delegpt. */
|
||||
/* BTW. RFC 1918 says NS should not have got CNAMEs. Robust. */
|
||||
@@ -1309,7 +1483,12 @@ processTargetResponse(struct module_qstate* qstate, int id,
|
||||
}
|
||||
if(!delegpt_add_rrset(foriq->dp, forq->region, rrset))
|
||||
log_err("out of memory adding targets");
|
||||
} else dpns->resolved = 1; /* fail the target */
|
||||
verbose(VERB_ALGO, "added target response");
|
||||
delegpt_log(VERB_ALGO, foriq->dp);
|
||||
} else {
|
||||
verbose(VERB_ALGO, "iterator TargetResponse failed");
|
||||
dpns->resolved = 1; /* fail the target */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1352,28 +1531,54 @@ processFinished(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
/* if (mPrivateTTL > 0){IterUtils.setPrivateTTL(resp, mPrivateTTL); } */
|
||||
|
||||
/* prepend any items we have accumulated */
|
||||
if(iq->prepend_list) {
|
||||
if(iq->an_prepend_list || iq->ns_prepend_list) {
|
||||
if(!iter_prepend(iq, iq->response, qstate->region)) {
|
||||
log_err("prepend rrsets: out of memory");
|
||||
return error_response(qstate, id, LDNS_RCODE_SERVFAIL);
|
||||
}
|
||||
/* store message with the finished prepended items */
|
||||
if(!iter_dns_store(qstate->env, &qstate->qinfo,
|
||||
iq->response->rep, 0))
|
||||
return error_response(qstate, id, LDNS_RCODE_SERVFAIL);
|
||||
/* reset the query name back */
|
||||
iq->response->qinfo = qstate->qinfo;
|
||||
/* store message with the finished prepended items,
|
||||
* but only if we did recursion. The nonrecursion referral
|
||||
* from cache does not need to be stored in the msg cache. */
|
||||
if(qstate->query_flags&BIT_RD) {
|
||||
if(!iter_dns_store(qstate->env, &qstate->qinfo,
|
||||
iq->response->rep, 0))
|
||||
return error_response(qstate, id,
|
||||
LDNS_RCODE_SERVFAIL);
|
||||
}
|
||||
}
|
||||
if(query_dname_compare(qstate->qinfo.qname,
|
||||
iq->response->qinfo.qname) == 0) {
|
||||
/* use server supplied upper/lower case */
|
||||
qstate->qinfo.qname = iq->response->qinfo.qname;
|
||||
}
|
||||
(*qstate->env->query_done)(qstate, LDNS_RCODE_NOERROR,
|
||||
iq->response->rep);
|
||||
(*qstate->env->walk_supers)(qstate, id, &processTargetResponse);
|
||||
|
||||
qstate->return_rcode = LDNS_RCODE_NOERROR;
|
||||
qstate->return_msg = iq->response;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return priming query results to interestes super querystates.
|
||||
*
|
||||
* Sets the delegation point and delegation message (not nonRD queries).
|
||||
* This is a callback from walk_supers.
|
||||
*
|
||||
* @param qstate: query state that finished.
|
||||
* @param id: module id.
|
||||
* @param super: the qstate to inform.
|
||||
*/
|
||||
void
|
||||
iter_inform_super(struct module_qstate* qstate, int id,
|
||||
struct module_qstate* super)
|
||||
{
|
||||
if(qstate->return_rcode != LDNS_RCODE_NOERROR)
|
||||
error_supers(qstate, id, super);
|
||||
else if(qstate->is_priming)
|
||||
prime_supers(qstate, id, super);
|
||||
else processTargetResponse(qstate, id, super);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle iterator state.
|
||||
* Handle events. This is the real processing loop for events, responsible
|
||||
@@ -1469,7 +1674,7 @@ process_response(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
}
|
||||
|
||||
/* parse message */
|
||||
prs = (struct msg_parse*)region_alloc(qstate->env->scratch,
|
||||
prs = (struct msg_parse*)regional_alloc(qstate->env->scratch,
|
||||
sizeof(struct msg_parse));
|
||||
if(!prs) {
|
||||
log_err("out of memory on incoming message");
|
||||
@@ -1487,6 +1692,8 @@ process_response(struct module_qstate* qstate, struct iter_qstate* iq,
|
||||
/* edns is not examined, but removed from message to help cache */
|
||||
if(parse_extract_edns(prs, &edns) != LDNS_RCODE_NOERROR)
|
||||
goto handle_it;
|
||||
/* remove CD-bit, we asked for in case we handle validation ourself */
|
||||
prs->flags &= ~BIT_CD;
|
||||
|
||||
/* normalize and sanitize: easy to delete items from linked lists */
|
||||
if(!scrub_message(pkt, prs, &iq->qchase, iq->dp->name,
|
||||
@@ -1508,8 +1715,7 @@ handle_it:
|
||||
iter_handle(qstate, iq, ie, id);
|
||||
}
|
||||
|
||||
/** iterator operate on a query */
|
||||
static void
|
||||
void
|
||||
iter_operate(struct module_qstate* qstate, enum module_ev event, int id,
|
||||
struct outbound_entry* outbound)
|
||||
{
|
||||
@@ -1524,7 +1730,8 @@ iter_operate(struct module_qstate* qstate, enum module_ev event, int id,
|
||||
&iq->qchase);
|
||||
|
||||
/* perform iterator state machine */
|
||||
if(event == module_event_new && iq == NULL) {
|
||||
if((event == module_event_new || event == module_event_pass) &&
|
||||
iq == NULL) {
|
||||
if(!iter_new(qstate, id)) {
|
||||
(void)error_response(qstate, id, LDNS_RCODE_SERVFAIL);
|
||||
return;
|
||||
@@ -1551,8 +1758,7 @@ iter_operate(struct module_qstate* qstate, enum module_ev event, int id,
|
||||
(void)error_response(qstate, id, LDNS_RCODE_SERVFAIL);
|
||||
}
|
||||
|
||||
/** iterator cleanup query state */
|
||||
static void
|
||||
void
|
||||
iter_clear(struct module_qstate* qstate, int id)
|
||||
{
|
||||
struct iter_qstate* iq;
|
||||
@@ -1566,12 +1772,24 @@ iter_clear(struct module_qstate* qstate, int id)
|
||||
qstate->minfo[id] = NULL;
|
||||
}
|
||||
|
||||
size_t
|
||||
iter_get_mem(struct module_env* env, int id)
|
||||
{
|
||||
struct iter_env* ie = (struct iter_env*)env->modinfo[id];
|
||||
if(!ie)
|
||||
return 0;
|
||||
return sizeof(*ie) + sizeof(int)*((size_t)ie->max_dependency_depth+1)
|
||||
+ hints_get_mem(ie->hints) + forwards_get_mem(ie->fwds)
|
||||
+ donotq_get_mem(ie->donotq);
|
||||
}
|
||||
|
||||
/**
|
||||
* The iterator function block
|
||||
*/
|
||||
static struct module_func_block iter_block = {
|
||||
"iterator",
|
||||
&iter_init, &iter_deinit, &iter_operate, &iter_clear
|
||||
&iter_init, &iter_deinit, &iter_operate, &iter_inform_super,
|
||||
&iter_clear, &iter_get_mem
|
||||
};
|
||||
|
||||
struct module_func_block*
|
||||
|
||||
+50
-11
@@ -44,7 +44,7 @@
|
||||
#define ITERATOR_ITERATOR_H
|
||||
#include "services/outbound_list.h"
|
||||
#include "util/data/msgreply.h"
|
||||
struct module_func_block;
|
||||
#include "util/module.h"
|
||||
struct delegpt;
|
||||
struct iter_hints;
|
||||
struct iter_forwards;
|
||||
@@ -58,12 +58,14 @@ struct iter_prep_list;
|
||||
/** how nice is a server without further information, in msec
|
||||
* Equals rtt initial timeout value.
|
||||
*/
|
||||
#define UNKNOWN_SERVER_NICENESS 3000
|
||||
#define UNKNOWN_SERVER_NICENESS 376
|
||||
/** maximum timeout before a host is deemed unsuitable, in msec.
|
||||
* After host_ttl this will be timed out and the host will be tried again.
|
||||
* Equals RTT_MAX_TIMEOUT
|
||||
*/
|
||||
#define USEFUL_SERVER_TOP_TIMEOUT 120000
|
||||
/** number of retries on outgoing queries */
|
||||
#define OUTBOUND_MSG_RETRY 4
|
||||
|
||||
/**
|
||||
* Global state for the iterator.
|
||||
@@ -182,9 +184,17 @@ struct iter_qstate {
|
||||
* This is a list of RRsets that must be prepended to the
|
||||
* ANSWER section of a response before being sent upstream.
|
||||
*/
|
||||
struct iter_prep_list* prepend_list;
|
||||
struct iter_prep_list* an_prepend_list;
|
||||
/** Last element of the prepend list */
|
||||
struct iter_prep_list* prepend_last;
|
||||
struct iter_prep_list* an_prepend_last;
|
||||
|
||||
/**
|
||||
* This is the list of RRsets that must be prepended to the
|
||||
* AUTHORITY section of the response before being sent upstream.
|
||||
*/
|
||||
struct iter_prep_list* ns_prepend_list;
|
||||
/** Last element of the authority prepend list */
|
||||
struct iter_prep_list* ns_prepend_last;
|
||||
|
||||
/** query name used for chasing the results. Initially the same as
|
||||
* the state qinfo, but after CNAMEs this will be different.
|
||||
@@ -215,18 +225,18 @@ struct iter_qstate {
|
||||
/** the number of times this query as followed a referral. */
|
||||
int referral_count;
|
||||
|
||||
/**
|
||||
* This flag, if true, means that this event is a priming query.
|
||||
* In that case priming stub may be set as well.
|
||||
/**
|
||||
* expected dnssec information for this iteration step.
|
||||
* If dnssec rrsigs are expected and not given, the server is marked
|
||||
* lame (dnssec-lame).
|
||||
*/
|
||||
int priming;
|
||||
int dnssec_expected;
|
||||
|
||||
/**
|
||||
* This is flag that, if true, means that this event is
|
||||
* representing a stub priming query. It is meaningless unless
|
||||
* the finalState is the PRIMING_RESP_STATE.
|
||||
* waiting for a stub priming query.
|
||||
*/
|
||||
int priming_stub;
|
||||
int wait_priming_stub;
|
||||
|
||||
/**
|
||||
* This is a flag that, if true, means that this query is
|
||||
@@ -272,4 +282,33 @@ const char* iter_state_to_string(enum iter_state state);
|
||||
*/
|
||||
int iter_state_is_responsestate(enum iter_state s);
|
||||
|
||||
/** iterator init */
|
||||
int iter_init(struct module_env* env, int id);
|
||||
|
||||
/** iterator deinit */
|
||||
void iter_deinit(struct module_env* env, int id);
|
||||
|
||||
/** iterator operate on a query */
|
||||
void iter_operate(struct module_qstate* qstate, enum module_ev event, int id,
|
||||
struct outbound_entry* outbound);
|
||||
|
||||
/**
|
||||
* Return priming query results to interestes super querystates.
|
||||
*
|
||||
* Sets the delegation point and delegation message (not nonRD queries).
|
||||
* This is a callback from walk_supers.
|
||||
*
|
||||
* @param qstate: query state that finished.
|
||||
* @param id: module id.
|
||||
* @param super: the qstate to inform.
|
||||
*/
|
||||
void iter_inform_super(struct module_qstate* qstate, int id,
|
||||
struct module_qstate* super);
|
||||
|
||||
/** iterator cleanup query state */
|
||||
void iter_clear(struct module_qstate* qstate, int id);
|
||||
|
||||
/** iterator alloc size routine */
|
||||
size_t iter_get_mem(struct module_env* env, int id);
|
||||
|
||||
#endif /* ITERATOR_ITERATOR_H */
|
||||
|
||||
Binary file not shown.
+10
-8
@@ -134,7 +134,7 @@ done
|
||||
# Check if SVNROOT is specified.
|
||||
if [ -z "$SVNROOT" ]; then
|
||||
if test -f .svn/entries; then
|
||||
eval `grep 'url=' .svn/entries | head -1`
|
||||
eval `svn info | grep 'URL:' | sed -e 's/URL: /url=/' | head -1`
|
||||
SVNROOT="$url"
|
||||
fi
|
||||
if test -z "$SVNROOT"; then
|
||||
@@ -148,15 +148,11 @@ if test -z "$LDNSDIR"; then
|
||||
eval `grep 'ldnsdir=' Makefile`
|
||||
LDNSDIR="$ldnsdir"
|
||||
fi
|
||||
if test -z "$LDNSDIR"; then
|
||||
error "LDNSDIR not detected in Makefile, specify manually (using -l)"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Start the packaging process.
|
||||
info "SVNROOT is $SVNROOT"
|
||||
info "SNAPSHOT is $SNAPSHOT"
|
||||
info "LDNSDIR is $LDNSDIR"
|
||||
|
||||
#question "Do you wish to continue with these settings?" || error "User abort."
|
||||
|
||||
@@ -185,9 +181,15 @@ echo "#include \"util/configyyrename.h\"" > util/configlexer.c || error_cleanup
|
||||
flex -i -t util/configlexer.lex >> util/configlexer.c || error_cleanup "Failed to create configlexer"
|
||||
bison -y -d -o util/configparser.c util/configparser.y || error_cleanup "Failed to create configparser"
|
||||
|
||||
# copy ldns-testpkts from ldns examples
|
||||
#cp $LDNSDIR/examples/ldns-testpkts.c testcode/ldns-testpkts.c || error_cleanup "copy ldns/examples/.. failed"
|
||||
#cp $LDNSDIR/examples/ldns-testpkts.h testcode/ldns-testpkts.h || error_cleanup "copy ldns/examples/.. failed"
|
||||
# check shared code, ldns-testpkts from ldns examples, if possible.
|
||||
if test ! -z "$LDNSDIR"; then
|
||||
if diff -q $LDNSDIR/examples/ldns-testpkts.c testcode/ldns-testpkts.c &&
|
||||
diff -q $LDNSDIR/examples/ldns-testpkts.h testcode/ldns-testpkts.h; then
|
||||
info "ldns-testpkts.c and ldns-testpkts.h are OK"
|
||||
else
|
||||
error_cleanup "ldns-testpkts is different in ldns and unbound"
|
||||
fi
|
||||
fi
|
||||
|
||||
find . -name .c-mode-rc.el -exec rm {} \;
|
||||
find . -name .cvsignore -exec rm {} \;
|
||||
|
||||
Vendored
+122
-40
@@ -47,7 +47,7 @@
|
||||
#include "util/data/dname.h"
|
||||
#include "util/module.h"
|
||||
#include "util/net_help.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
|
||||
/** store rrsets in the rrset cache.
|
||||
* @param env: module environment with caches.
|
||||
@@ -103,10 +103,10 @@ dns_cache_store_msg(struct module_env* env, struct query_info* qinfo,
|
||||
|
||||
/** allocate rrset in region - no more locks needed */
|
||||
static struct ub_packed_rrset_key*
|
||||
copy_rrset(struct ub_packed_rrset_key* key, struct region* region,
|
||||
copy_rrset(struct ub_packed_rrset_key* key, struct regional* region,
|
||||
uint32_t now)
|
||||
{
|
||||
struct ub_packed_rrset_key* ck = region_alloc(region,
|
||||
struct ub_packed_rrset_key* ck = regional_alloc(region,
|
||||
sizeof(struct ub_packed_rrset_key));
|
||||
struct packed_rrset_data* d;
|
||||
struct packed_rrset_data* data = (struct packed_rrset_data*)
|
||||
@@ -119,12 +119,12 @@ copy_rrset(struct ub_packed_rrset_key* key, struct region* region,
|
||||
ck->entry.hash = key->entry.hash;
|
||||
ck->entry.key = ck;
|
||||
ck->rk = key->rk;
|
||||
ck->rk.dname = region_alloc_init(region, key->rk.dname,
|
||||
ck->rk.dname = regional_alloc_init(region, key->rk.dname,
|
||||
key->rk.dname_len);
|
||||
if(!ck->rk.dname)
|
||||
return NULL;
|
||||
dsize = packed_rrset_sizeof(data);
|
||||
d = (struct packed_rrset_data*)region_alloc_init(region, data, dsize);
|
||||
d = (struct packed_rrset_data*)regional_alloc_init(region, data, dsize);
|
||||
if(!d)
|
||||
return NULL;
|
||||
ck->entry.data = d;
|
||||
@@ -139,11 +139,18 @@ copy_rrset(struct ub_packed_rrset_key* key, struct region* region,
|
||||
/** find closest NS or DNAME and returns the rrset (locked) */
|
||||
static struct ub_packed_rrset_key*
|
||||
find_closest_of_type(struct module_env* env, uint8_t* qname, size_t qnamelen,
|
||||
uint16_t qclass, uint32_t now, uint16_t searchtype)
|
||||
uint16_t qclass, uint32_t now, uint16_t searchtype, int stripfront)
|
||||
{
|
||||
struct ub_packed_rrset_key *rrset;
|
||||
uint8_t lablen;
|
||||
|
||||
if(stripfront) {
|
||||
/* strip off so that DNAMEs have strict subdomain match */
|
||||
lablen = *qname;
|
||||
qname += lablen + 1;
|
||||
qnamelen -= lablen + 1;
|
||||
}
|
||||
|
||||
/* snip off front part of qname until the type is found */
|
||||
while(qnamelen > 0) {
|
||||
if((rrset = rrset_cache_lookup(env->rrset_cache, qname,
|
||||
@@ -160,7 +167,7 @@ find_closest_of_type(struct module_env* env, uint8_t* qname, size_t qnamelen,
|
||||
|
||||
/** add addr to additional section */
|
||||
static void
|
||||
addr_to_additional(struct ub_packed_rrset_key* rrset, struct region* region,
|
||||
addr_to_additional(struct ub_packed_rrset_key* rrset, struct regional* region,
|
||||
struct dns_msg* msg, uint32_t now)
|
||||
{
|
||||
if((msg->rep->rrsets[msg->rep->rrset_count] =
|
||||
@@ -172,8 +179,9 @@ addr_to_additional(struct ub_packed_rrset_key* rrset, struct region* region,
|
||||
|
||||
/** find and add A and AAAA records for nameservers in delegpt */
|
||||
static int
|
||||
find_add_addrs(struct module_env* env, uint16_t qclass, struct region* region,
|
||||
struct delegpt* dp, uint32_t now, struct dns_msg** msg)
|
||||
find_add_addrs(struct module_env* env, uint16_t qclass,
|
||||
struct regional* region, struct delegpt* dp, uint32_t now,
|
||||
struct dns_msg** msg)
|
||||
{
|
||||
struct delegpt_ns* ns;
|
||||
struct ub_packed_rrset_key* akey;
|
||||
@@ -207,7 +215,7 @@ find_add_addrs(struct module_env* env, uint16_t qclass, struct region* region,
|
||||
/** find and add A and AAAA records for missing nameservers in delegpt */
|
||||
int
|
||||
cache_fill_missing(struct module_env* env, uint16_t qclass,
|
||||
struct region* region, struct delegpt* dp)
|
||||
struct regional* region, struct delegpt* dp)
|
||||
{
|
||||
struct delegpt_ns* ns;
|
||||
struct ub_packed_rrset_key* akey;
|
||||
@@ -243,7 +251,7 @@ cache_fill_missing(struct module_env* env, uint16_t qclass,
|
||||
|
||||
/** find and add DS or NSEC to delegation msg */
|
||||
static void
|
||||
find_add_ds(struct module_env* env, struct region* region,
|
||||
find_add_ds(struct module_env* env, struct regional* region,
|
||||
struct dns_msg* msg, struct delegpt* dp, uint32_t now)
|
||||
{
|
||||
/* Lookup the DS or NSEC at the delegation point. */
|
||||
@@ -274,21 +282,21 @@ find_add_ds(struct module_env* env, struct region* region,
|
||||
/** create referral message with NS and query */
|
||||
static struct dns_msg*
|
||||
create_msg(uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
|
||||
struct region* region, struct ub_packed_rrset_key* nskey,
|
||||
struct regional* region, struct ub_packed_rrset_key* nskey,
|
||||
struct packed_rrset_data* nsdata, uint32_t now)
|
||||
{
|
||||
struct dns_msg* msg = (struct dns_msg*)region_alloc(region,
|
||||
struct dns_msg* msg = (struct dns_msg*)regional_alloc(region,
|
||||
sizeof(struct dns_msg));
|
||||
if(!msg)
|
||||
return NULL;
|
||||
msg->qinfo.qname = region_alloc_init(region, qname, qnamelen);
|
||||
msg->qinfo.qname = regional_alloc_init(region, qname, qnamelen);
|
||||
if(!msg->qinfo.qname)
|
||||
return NULL;
|
||||
msg->qinfo.qname_len = qnamelen;
|
||||
msg->qinfo.qtype = qtype;
|
||||
msg->qinfo.qclass = qclass;
|
||||
/* non-packed reply_info, because it needs to grow the array */
|
||||
msg->rep = (struct reply_info*)region_alloc(region,
|
||||
msg->rep = (struct reply_info*)regional_alloc(region,
|
||||
sizeof(struct reply_info)-sizeof(struct rrset_ref));
|
||||
if(!msg->rep)
|
||||
return NULL;
|
||||
@@ -301,7 +309,8 @@ create_msg(uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
|
||||
* A rrset for every NS RR
|
||||
* AAAA rrset for every NS RR
|
||||
*/
|
||||
msg->rep->rrsets = (struct ub_packed_rrset_key**)region_alloc(region,
|
||||
msg->rep->rrsets = (struct ub_packed_rrset_key**)
|
||||
regional_alloc(region,
|
||||
(2 + nsdata->count*2)*sizeof(struct ub_packed_rrset_key*));
|
||||
if(!msg->rep->rrsets)
|
||||
return NULL;
|
||||
@@ -316,16 +325,15 @@ create_msg(uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
|
||||
struct delegpt*
|
||||
dns_cache_find_delegation(struct module_env* env, uint8_t* qname,
|
||||
size_t qnamelen, uint16_t qtype, uint16_t qclass,
|
||||
struct region* region, struct dns_msg** msg)
|
||||
struct regional* region, struct dns_msg** msg, uint32_t now)
|
||||
{
|
||||
/* try to find closest NS rrset */
|
||||
struct ub_packed_rrset_key* nskey;
|
||||
struct packed_rrset_data* nsdata;
|
||||
struct delegpt* dp;
|
||||
uint32_t now = (uint32_t)time(NULL);
|
||||
|
||||
nskey = find_closest_of_type(env, qname, qnamelen, qclass, now,
|
||||
LDNS_RR_TYPE_NS);
|
||||
LDNS_RR_TYPE_NS, 0);
|
||||
if(!nskey) /* hope the caller has hints to prime or something */
|
||||
return NULL;
|
||||
nsdata = (struct packed_rrset_data*)nskey->entry.data;
|
||||
@@ -355,29 +363,28 @@ dns_cache_find_delegation(struct module_env* env, uint8_t* qname,
|
||||
/* find and add A entries */
|
||||
if(!find_add_addrs(env, qclass, region, dp, now, msg))
|
||||
log_err("find_delegation: addrs out of memory");
|
||||
log_info("dns_cache_find_delegation returns delegpt");
|
||||
delegpt_log(dp);
|
||||
return dp;
|
||||
}
|
||||
|
||||
/** allocate dns_msg from query_info and reply_info */
|
||||
static struct dns_msg*
|
||||
gen_dns_msg(struct region* region, struct query_info* q, size_t num)
|
||||
gen_dns_msg(struct regional* region, struct query_info* q, size_t num)
|
||||
{
|
||||
struct dns_msg* msg = (struct dns_msg*)region_alloc(region,
|
||||
struct dns_msg* msg = (struct dns_msg*)regional_alloc(region,
|
||||
sizeof(struct dns_msg));
|
||||
if(!msg)
|
||||
return NULL;
|
||||
memcpy(&msg->qinfo, q, sizeof(struct query_info));
|
||||
msg->qinfo.qname = region_alloc_init(region, q->qname, q->qname_len);
|
||||
msg->qinfo.qname = regional_alloc_init(region, q->qname, q->qname_len);
|
||||
if(!msg->qinfo.qname)
|
||||
return NULL;
|
||||
/* allocate replyinfo struct and rrset key array separately */
|
||||
msg->rep = (struct reply_info*)region_alloc(region,
|
||||
msg->rep = (struct reply_info*)regional_alloc(region,
|
||||
sizeof(struct reply_info) - sizeof(struct rrset_ref));
|
||||
if(!msg->rep)
|
||||
return NULL;
|
||||
msg->rep->rrsets = (struct ub_packed_rrset_key**)region_alloc(region,
|
||||
msg->rep->rrsets = (struct ub_packed_rrset_key**)
|
||||
regional_alloc(region,
|
||||
num * sizeof(struct ub_packed_rrset_key*));
|
||||
if(!msg->rep->rrsets)
|
||||
return NULL;
|
||||
@@ -387,7 +394,7 @@ gen_dns_msg(struct region* region, struct query_info* q, size_t num)
|
||||
/** generate dns_msg from cached message */
|
||||
static struct dns_msg*
|
||||
tomsg(struct module_env* env, struct msgreply_entry* e, struct reply_info* r,
|
||||
struct region* region, uint32_t now, struct region* scratch)
|
||||
struct regional* region, uint32_t now, struct regional* scratch)
|
||||
{
|
||||
struct dns_msg* msg;
|
||||
size_t i;
|
||||
@@ -399,6 +406,7 @@ tomsg(struct module_env* env, struct msgreply_entry* e, struct reply_info* r,
|
||||
msg->rep->flags = r->flags;
|
||||
msg->rep->qdcount = r->qdcount;
|
||||
msg->rep->ttl = r->ttl;
|
||||
msg->rep->security = r->security;
|
||||
msg->rep->an_numrrsets = r->an_numrrsets;
|
||||
msg->rep->ns_numrrsets = r->ns_numrrsets;
|
||||
msg->rep->ar_numrrsets = r->ar_numrrsets;
|
||||
@@ -417,9 +425,9 @@ tomsg(struct module_env* env, struct msgreply_entry* e, struct reply_info* r,
|
||||
return msg;
|
||||
}
|
||||
|
||||
/** synthesize CNAME response from cached CNAME item */
|
||||
/** synthesize RRset-only response from cached RRset item */
|
||||
static struct dns_msg*
|
||||
cname_msg(struct ub_packed_rrset_key* rrset, struct region* region,
|
||||
rrset_msg(struct ub_packed_rrset_key* rrset, struct regional* region,
|
||||
uint32_t now, struct query_info* q)
|
||||
{
|
||||
struct dns_msg* msg;
|
||||
@@ -427,12 +435,13 @@ cname_msg(struct ub_packed_rrset_key* rrset, struct region* region,
|
||||
rrset->entry.data;
|
||||
if(now > d->ttl)
|
||||
return NULL;
|
||||
msg = gen_dns_msg(region, q, 1); /* only the CNAME RRset */
|
||||
msg = gen_dns_msg(region, q, 1); /* only the CNAME (or other) RRset */
|
||||
if(!msg)
|
||||
return NULL;
|
||||
msg->rep->flags = BIT_QR; /* reply, no AA, no error */
|
||||
msg->rep->qdcount = 1;
|
||||
msg->rep->ttl = d->ttl - now;
|
||||
msg->rep->security = sec_status_unchecked;
|
||||
msg->rep->an_numrrsets = 1;
|
||||
msg->rep->ns_numrrsets = 0;
|
||||
msg->rep->ar_numrrsets = 0;
|
||||
@@ -445,7 +454,7 @@ cname_msg(struct ub_packed_rrset_key* rrset, struct region* region,
|
||||
|
||||
/** synthesize DNAME+CNAME response from cached DNAME item */
|
||||
static struct dns_msg*
|
||||
synth_dname_msg(struct ub_packed_rrset_key* rrset, struct region* region,
|
||||
synth_dname_msg(struct ub_packed_rrset_key* rrset, struct regional* region,
|
||||
uint32_t now, struct query_info* q)
|
||||
{
|
||||
struct dns_msg* msg;
|
||||
@@ -462,6 +471,7 @@ synth_dname_msg(struct ub_packed_rrset_key* rrset, struct region* region,
|
||||
msg->rep->flags = BIT_QR; /* reply, no AA, no error */
|
||||
msg->rep->qdcount = 1;
|
||||
msg->rep->ttl = d->ttl - now;
|
||||
msg->rep->security = sec_status_unchecked;
|
||||
msg->rep->an_numrrsets = 1;
|
||||
msg->rep->ns_numrrsets = 0;
|
||||
msg->rep->ar_numrrsets = 0;
|
||||
@@ -478,7 +488,7 @@ synth_dname_msg(struct ub_packed_rrset_key* rrset, struct region* region,
|
||||
msg->rep->flags |= LDNS_RCODE_YXDOMAIN;
|
||||
return msg;
|
||||
}
|
||||
newname = (uint8_t*)region_alloc(region, newlen);
|
||||
newname = (uint8_t*)regional_alloc(region, newlen);
|
||||
if(!newname)
|
||||
return NULL;
|
||||
/* new name is concatenation of qname front (without DNAME owner)
|
||||
@@ -486,7 +496,7 @@ synth_dname_msg(struct ub_packed_rrset_key* rrset, struct region* region,
|
||||
memcpy(newname, q->qname, q->qname_len-rrset->rk.dname_len);
|
||||
memmove(newname+(q->qname_len-rrset->rk.dname_len), dtarg, dtarglen);
|
||||
/* create rest of CNAME rrset */
|
||||
ck = (struct ub_packed_rrset_key*)region_alloc(region,
|
||||
ck = (struct ub_packed_rrset_key*)regional_alloc(region,
|
||||
sizeof(struct ub_packed_rrset_key));
|
||||
if(!ck)
|
||||
return NULL;
|
||||
@@ -496,12 +506,12 @@ synth_dname_msg(struct ub_packed_rrset_key* rrset, struct region* region,
|
||||
ck->rk.type = htons(LDNS_RR_TYPE_CNAME);
|
||||
ck->rk.rrset_class = rrset->rk.rrset_class;
|
||||
ck->rk.flags = 0;
|
||||
ck->rk.dname = region_alloc_init(region, q->qname, q->qname_len);
|
||||
ck->rk.dname = regional_alloc_init(region, q->qname, q->qname_len);
|
||||
if(!ck->rk.dname)
|
||||
return NULL;
|
||||
ck->rk.dname_len = q->qname_len;
|
||||
ck->entry.hash = rrset_key_hash(&ck->rk);
|
||||
newd = (struct packed_rrset_data*)region_alloc(region,
|
||||
newd = (struct packed_rrset_data*)regional_alloc(region,
|
||||
sizeof(struct packed_rrset_data) + sizeof(size_t) +
|
||||
sizeof(uint8_t*) + sizeof(uint32_t) + sizeof(uint16_t)
|
||||
+ newlen);
|
||||
@@ -528,7 +538,7 @@ synth_dname_msg(struct ub_packed_rrset_key* rrset, struct region* region,
|
||||
struct dns_msg*
|
||||
dns_cache_lookup(struct module_env* env,
|
||||
uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
|
||||
struct region* region, struct region* scratch)
|
||||
struct regional* region, struct regional* scratch)
|
||||
{
|
||||
struct lruhash_entry* e;
|
||||
struct query_info k;
|
||||
@@ -560,7 +570,7 @@ dns_cache_lookup(struct module_env* env,
|
||||
* are more important, the CNAME is resynthesized and thus
|
||||
* consistent with the DNAME */
|
||||
if( (rrset=find_closest_of_type(env, qname, qnamelen, qclass, now,
|
||||
LDNS_RR_TYPE_DNAME))) {
|
||||
LDNS_RR_TYPE_DNAME, 1))) {
|
||||
/* synthesize a DNAME+CNAME message based on this */
|
||||
struct dns_msg* msg = synth_dname_msg(rrset, region, now, &k);
|
||||
if(msg) {
|
||||
@@ -573,7 +583,7 @@ dns_cache_lookup(struct module_env* env,
|
||||
/* see if we have CNAME for this domain */
|
||||
if( (rrset=rrset_cache_lookup(env->rrset_cache, qname, qnamelen,
|
||||
LDNS_RR_TYPE_CNAME, qclass, 0, now, 0))) {
|
||||
struct dns_msg* msg = cname_msg(rrset, region, now, &k);
|
||||
struct dns_msg* msg = rrset_msg(rrset, region, now, &k);
|
||||
if(msg) {
|
||||
lock_rw_unlock(&rrset->entry.lock);
|
||||
return msg;
|
||||
@@ -581,7 +591,79 @@ dns_cache_lookup(struct module_env* env,
|
||||
lock_rw_unlock(&rrset->entry.lock);
|
||||
}
|
||||
|
||||
/* construct DS, DNSKEY messages from rrset cache. TODO */
|
||||
|
||||
/* construct DS, DNSKEY messages from rrset cache. */
|
||||
if((qtype == LDNS_RR_TYPE_DS || qtype == LDNS_RR_TYPE_DNSKEY) &&
|
||||
(rrset=rrset_cache_lookup(env->rrset_cache, qname, qnamelen,
|
||||
qtype, qclass, 0, now, 0))) {
|
||||
/* if the rrset is from the additional section, and the
|
||||
* signatures have fallen off, then do not synthesize a msg
|
||||
* instead, allow a full query for signed results to happen.
|
||||
* Forego all rrset data from additional section, because
|
||||
* some signatures may not be present and cause validation
|
||||
* failure.
|
||||
*/
|
||||
struct packed_rrset_data *d = (struct packed_rrset_data*)
|
||||
rrset->entry.data;
|
||||
if(d->trust != rrset_trust_add_noAA &&
|
||||
d->trust != rrset_trust_add_AA) {
|
||||
struct dns_msg* msg = rrset_msg(rrset, region, now, &k);
|
||||
if(msg) {
|
||||
lock_rw_unlock(&rrset->entry.lock);
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
lock_rw_unlock(&rrset->entry.lock);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
dns_cache_store(struct module_env* env, struct query_info* msgqinf,
|
||||
struct reply_info* msgrep, int is_referral)
|
||||
{
|
||||
struct reply_info* rep = NULL;
|
||||
/* alloc, malloc properly (not in region, like msg is) */
|
||||
rep = reply_info_copy(msgrep, env->alloc, NULL);
|
||||
if(!rep)
|
||||
return 0;
|
||||
|
||||
if(is_referral) {
|
||||
/* store rrsets */
|
||||
struct rrset_ref ref;
|
||||
uint32_t now = time(NULL);
|
||||
size_t i;
|
||||
for(i=0; i<rep->rrset_count; i++) {
|
||||
packed_rrset_ttl_add((struct packed_rrset_data*)
|
||||
rep->rrsets[i]->entry.data, now);
|
||||
ref.key = rep->rrsets[i];
|
||||
ref.id = rep->rrsets[i]->id;
|
||||
/*ignore ret: it was in the cache, ref updated */
|
||||
(void)rrset_cache_update(env->rrset_cache, &ref,
|
||||
env->alloc, now);
|
||||
}
|
||||
free(rep);
|
||||
return 1;
|
||||
} else {
|
||||
/* store msg, and rrsets */
|
||||
struct query_info qinf;
|
||||
hashvalue_t h;
|
||||
|
||||
qinf = *msgqinf;
|
||||
qinf.qname = memdup(msgqinf->qname, msgqinf->qname_len);
|
||||
if(!qinf.qname) {
|
||||
reply_info_parsedelete(rep, env->alloc);
|
||||
return 0;
|
||||
}
|
||||
/* fixup flags to be sensible for a reply based on the cache */
|
||||
/* this module means that RA is available. It is an answer QR.
|
||||
* Not AA from cache. Not CD in cache (depends on client bit). */
|
||||
rep->flags |= (BIT_RA | BIT_QR);
|
||||
rep->flags &= ~(BIT_AA | BIT_CD);
|
||||
h = query_info_hash(&qinf);
|
||||
dns_cache_store_msg(env, &qinf, h, rep);
|
||||
/* qname is used inside query_info_entrysetup, and set to
|
||||
* NULL. If it has not been used, free it. free(0) is safe. */
|
||||
free(qinf.qname);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
Vendored
+23
-4
@@ -46,7 +46,7 @@
|
||||
struct module_env;
|
||||
struct query_info;
|
||||
struct reply_info;
|
||||
struct region;
|
||||
struct regional;
|
||||
struct delegpt;
|
||||
|
||||
/**
|
||||
@@ -59,6 +59,24 @@ struct dns_msg {
|
||||
struct reply_info *rep;
|
||||
};
|
||||
|
||||
/**
|
||||
* Allocate a dns_msg with malloc/alloc structure and store in dns cache.
|
||||
*
|
||||
* @param env: environment, with alloc structure and dns cache.
|
||||
* @param qinf: query info, the query for which answer is stored.
|
||||
* this is allocated in a region, and will be copied to malloc area
|
||||
* before insertion.
|
||||
* @param rep: reply in dns_msg from dns_alloc_msg for example.
|
||||
* this is allocated in a region, and will be copied to malloc area
|
||||
* before insertion.
|
||||
* @param is_referral: If true, then the given message to be stored is a
|
||||
* referral. The cache implementation may use this as a hint.
|
||||
* It will store only the RRsets, not the message.
|
||||
* @return 0 on alloc error (out of memory).
|
||||
*/
|
||||
int dns_cache_store(struct module_env* env, struct query_info* qinf,
|
||||
struct reply_info* rep, int is_referral);
|
||||
|
||||
/**
|
||||
* Store message in the cache. Stores in message cache and rrset cache.
|
||||
* Both qinfo and rep should be malloced and are put in the cache.
|
||||
@@ -84,11 +102,12 @@ void dns_cache_store_msg(struct module_env* env, struct query_info* qinfo,
|
||||
* @param region: where to allocate result delegation.
|
||||
* @param msg: if not NULL, delegation message is returned here, synthesized
|
||||
* from the cache.
|
||||
* @param timenow: the time now, for checking if TTL on cache entries is OK.
|
||||
* @return new delegation or NULL on error or if not found in cache.
|
||||
*/
|
||||
struct delegpt* dns_cache_find_delegation(struct module_env* env,
|
||||
uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
|
||||
struct region* region, struct dns_msg** msg);
|
||||
struct regional* region, struct dns_msg** msg, uint32_t timenow);
|
||||
|
||||
/**
|
||||
* Find cached message
|
||||
@@ -105,7 +124,7 @@ struct delegpt* dns_cache_find_delegation(struct module_env* env,
|
||||
*/
|
||||
struct dns_msg* dns_cache_lookup(struct module_env* env,
|
||||
uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass,
|
||||
struct region* region, struct region* scratch);
|
||||
struct regional* region, struct regional* scratch);
|
||||
|
||||
/**
|
||||
* find and add A and AAAA records for missing nameservers in delegpt
|
||||
@@ -116,7 +135,7 @@ struct dns_msg* dns_cache_lookup(struct module_env* env,
|
||||
* @return false on alloc failure.
|
||||
*/
|
||||
int cache_fill_missing(struct module_env* env, uint16_t qclass,
|
||||
struct region* region, struct delegpt* dp);
|
||||
struct regional* region, struct delegpt* dp);
|
||||
|
||||
/** Find covering DNAME */
|
||||
|
||||
|
||||
Vendored
+94
-32
@@ -47,16 +47,15 @@
|
||||
#include "util/net_help.h"
|
||||
#include "util/config_file.h"
|
||||
|
||||
/** calculate size for the hashtable, does not count size of lameness,
|
||||
* so the hashtable is a fixed number of items */
|
||||
static size_t
|
||||
infra_host_sizefunc(void* ATTR_UNUSED(k), void* ATTR_UNUSED(d))
|
||||
size_t
|
||||
infra_host_sizefunc(void* k, void* ATTR_UNUSED(d))
|
||||
{
|
||||
return sizeof(struct infra_host_key) + sizeof(struct infra_host_data);
|
||||
struct infra_host_key* key = (struct infra_host_key*)k;
|
||||
return sizeof(*key) + sizeof(struct infra_host_data)
|
||||
+ lock_get_mem(&key->entry.lock);
|
||||
}
|
||||
|
||||
/** compare two addresses, returns -1, 0, or +1 */
|
||||
static int
|
||||
int
|
||||
infra_host_compfunc(void* key1, void* key2)
|
||||
{
|
||||
struct infra_host_key* k1 = (struct infra_host_key*)key1;
|
||||
@@ -64,8 +63,7 @@ infra_host_compfunc(void* key1, void* key2)
|
||||
return sockaddr_cmp(&k1->addr, k1->addrlen, &k2->addr, k2->addrlen);
|
||||
}
|
||||
|
||||
/** delete key, and destroy the lock */
|
||||
static void
|
||||
void
|
||||
infra_host_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il)
|
||||
{
|
||||
struct infra_host_key* key = (struct infra_host_key*)k;
|
||||
@@ -76,8 +74,7 @@ infra_host_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il)
|
||||
free(key);
|
||||
}
|
||||
|
||||
/** delete data and destroy the lameness hashtable */
|
||||
static void
|
||||
void
|
||||
infra_host_deldatafunc(void* d, void* ATTR_UNUSED(arg))
|
||||
{
|
||||
struct infra_host_data* data = (struct infra_host_data*)d;
|
||||
@@ -103,7 +100,7 @@ infra_create(struct config_file* cfg)
|
||||
}
|
||||
infra->host_ttl = cfg->host_ttl;
|
||||
infra->lame_ttl = cfg->lame_ttl;
|
||||
infra->max_lame = cfg->infra_cache_numlame;
|
||||
infra->max_lame_size = cfg->infra_cache_lame_size;
|
||||
return infra;
|
||||
}
|
||||
|
||||
@@ -124,7 +121,7 @@ infra_adjust(struct infra_cache* infra, struct config_file* cfg)
|
||||
return infra_create(cfg);
|
||||
infra->host_ttl = cfg->host_ttl;
|
||||
infra->lame_ttl = cfg->lame_ttl;
|
||||
infra->max_lame = cfg->infra_cache_numlame;
|
||||
infra->max_lame_size = cfg->infra_cache_lame_size;
|
||||
maxmem = cfg->infra_cache_numhosts *
|
||||
(sizeof(struct infra_host_key)+sizeof(struct infra_host_data));
|
||||
if(maxmem != slabhash_get_size(infra->hosts) ||
|
||||
@@ -269,6 +266,7 @@ infra_lookup_lame(struct infra_host_data* host,
|
||||
struct lruhash_entry* e;
|
||||
struct infra_lame_key k;
|
||||
struct infra_lame_data *d;
|
||||
int dl;
|
||||
if(!host->lameness)
|
||||
return 0;
|
||||
k.entry.hash = hash_lameness(name, namelen);
|
||||
@@ -284,20 +282,20 @@ infra_lookup_lame(struct infra_host_data* host,
|
||||
lock_rw_unlock(&e->lock);
|
||||
return 0;
|
||||
}
|
||||
dl = d->isdnsseclame;
|
||||
lock_rw_unlock(&e->lock);
|
||||
return 1;
|
||||
return dl?2:1;
|
||||
}
|
||||
|
||||
/** calculate size, which is fixed, zonename does not count so that
|
||||
* a fixed number of items is stored */
|
||||
static size_t
|
||||
infra_lame_sizefunc(void* ATTR_UNUSED(k), void* ATTR_UNUSED(d))
|
||||
size_t
|
||||
infra_lame_sizefunc(void* k, void* ATTR_UNUSED(d))
|
||||
{
|
||||
return sizeof(struct infra_lame_key)+sizeof(struct infra_lame_data);
|
||||
struct infra_lame_key* key = (struct infra_lame_key*)k;
|
||||
return sizeof(*key) + sizeof(struct infra_lame_data)
|
||||
+ key->namelen + lock_get_mem(&key->entry.lock);
|
||||
}
|
||||
|
||||
/** compare zone names, returns -1, 0, +1 */
|
||||
static int
|
||||
int
|
||||
infra_lame_compfunc(void* key1, void* key2)
|
||||
{
|
||||
struct infra_lame_key* k1 = (struct infra_lame_key*)key1;
|
||||
@@ -310,8 +308,7 @@ infra_lame_compfunc(void* key1, void* key2)
|
||||
return query_dname_compare(k1->zonename, k2->zonename);
|
||||
}
|
||||
|
||||
/** free key, lock and zonename */
|
||||
static void
|
||||
void
|
||||
infra_lame_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il)
|
||||
{
|
||||
struct infra_lame_key* key = (struct infra_lame_key*)k;
|
||||
@@ -323,8 +320,7 @@ infra_lame_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il)
|
||||
free(key);
|
||||
}
|
||||
|
||||
/** free the lameness data */
|
||||
static void
|
||||
void
|
||||
infra_lame_deldatafunc(void* d, void* ATTR_UNUSED(arg))
|
||||
{
|
||||
if(!d)
|
||||
@@ -335,7 +331,7 @@ infra_lame_deldatafunc(void* d, void* ATTR_UNUSED(arg))
|
||||
int
|
||||
infra_set_lame(struct infra_cache* infra,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen,
|
||||
uint8_t* name, size_t namelen, time_t timenow)
|
||||
uint8_t* name, size_t namelen, time_t timenow, int dnsseclame)
|
||||
{
|
||||
struct infra_host_data* data;
|
||||
struct lruhash_entry* e;
|
||||
@@ -366,6 +362,7 @@ infra_set_lame(struct infra_cache* infra,
|
||||
k->entry.key = (void*)k;
|
||||
k->entry.data = (void*)d;
|
||||
d->ttl = timenow + infra->lame_ttl;
|
||||
d->isdnsseclame = dnsseclame;
|
||||
k->namelen = namelen;
|
||||
e = infra_lookup_host_nottl(infra, addr, addrlen, 1);
|
||||
if(!e) {
|
||||
@@ -384,8 +381,7 @@ infra_set_lame(struct infra_cache* infra,
|
||||
if(!data->lameness) {
|
||||
/* create hash table if not there already */
|
||||
data->lameness = lruhash_create(INFRA_LAME_STARTSIZE,
|
||||
infra->max_lame*(sizeof(struct infra_lame_key)+
|
||||
sizeof(struct infra_lame_data)), infra_lame_sizefunc,
|
||||
infra->max_lame_size, infra_lame_sizefunc,
|
||||
infra_lame_compfunc, infra_lame_delkeyfunc,
|
||||
infra_lame_deldatafunc, NULL);
|
||||
if(!data->lameness) {
|
||||
@@ -408,6 +404,23 @@ infra_set_lame(struct infra_cache* infra,
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
infra_update_tcp_works(struct infra_cache* infra,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen)
|
||||
{
|
||||
struct lruhash_entry* e = infra_lookup_host_nottl(infra, addr,
|
||||
addrlen, 1);
|
||||
struct infra_host_data* data;
|
||||
if(!e)
|
||||
return; /* doesn't exist */
|
||||
data = (struct infra_host_data*)e->data;
|
||||
if(data->rtt.rto >= RTT_MAX_TIMEOUT)
|
||||
/* do not disqualify this server altogether, it is better
|
||||
* than nothing */
|
||||
data->rtt.rto = RTT_MAX_TIMEOUT-1;
|
||||
lock_rw_unlock(&e->lock);
|
||||
}
|
||||
|
||||
int
|
||||
infra_rtt_update(struct infra_cache* infra,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen,
|
||||
@@ -417,6 +430,7 @@ infra_rtt_update(struct infra_cache* infra,
|
||||
addrlen, 1);
|
||||
struct infra_host_data* data;
|
||||
int needtoinsert = 0;
|
||||
int rto = 1;
|
||||
if(!e) {
|
||||
if(!(e = new_host_entry(infra, addr, addrlen, timenow)))
|
||||
return 0;
|
||||
@@ -428,11 +442,13 @@ infra_rtt_update(struct infra_cache* infra,
|
||||
if(roundtrip == -1)
|
||||
rtt_lost(&data->rtt);
|
||||
else rtt_update(&data->rtt, roundtrip);
|
||||
if(data->rtt.rto > 0)
|
||||
rto = data->rtt.rto;
|
||||
|
||||
if(needtoinsert)
|
||||
slabhash_insert(infra->hosts, e->hash, e, e->data, NULL);
|
||||
else { lock_rw_unlock(&e->lock); }
|
||||
return 1;
|
||||
return rto;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -463,22 +479,31 @@ infra_edns_update(struct infra_cache* infra,
|
||||
int
|
||||
infra_get_lame_rtt(struct infra_cache* infra,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen,
|
||||
uint8_t* name, size_t namelen, int* lame, int* rtt, time_t timenow)
|
||||
uint8_t* name, size_t namelen, int* lame, int* dnsseclame,
|
||||
int* rtt, time_t timenow)
|
||||
{
|
||||
struct infra_host_data* host;
|
||||
struct lruhash_entry* e = infra_lookup_host_nottl(infra, addr,
|
||||
addrlen, 0);
|
||||
int lm;
|
||||
if(!e)
|
||||
return 0;
|
||||
host = (struct infra_host_data*)e->data;
|
||||
*rtt = rtt_unclamped(&host->rtt);
|
||||
/* check lameness first, if so, ttl on host does not matter anymore */
|
||||
if(infra_lookup_lame(host, name, namelen, timenow)) {
|
||||
if((lm=infra_lookup_lame(host, name, namelen, timenow))) {
|
||||
lock_rw_unlock(&e->lock);
|
||||
*lame = 1;
|
||||
if(lm == 1) {
|
||||
*lame = 1;
|
||||
*dnsseclame = 0;
|
||||
} else {
|
||||
*lame = 0;
|
||||
*dnsseclame = 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
*lame = 0;
|
||||
*dnsseclame = 0;
|
||||
if(timenow > host->ttl) {
|
||||
lock_rw_unlock(&e->lock);
|
||||
return 0;
|
||||
@@ -486,3 +511,40 @@ infra_get_lame_rtt(struct infra_cache* infra,
|
||||
lock_rw_unlock(&e->lock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** helper memory count for a host lame cache */
|
||||
static size_t
|
||||
count_host_lame(struct lruhash_entry* e)
|
||||
{
|
||||
struct infra_host_data* host_data = (struct infra_host_data*)e->data;
|
||||
if(!host_data->lameness)
|
||||
return 0;
|
||||
return lruhash_get_mem(host_data->lameness);
|
||||
}
|
||||
|
||||
size_t
|
||||
infra_get_mem(struct infra_cache* infra)
|
||||
{
|
||||
size_t i, bin;
|
||||
size_t s = sizeof(*infra) +
|
||||
slabhash_get_mem(infra->hosts);
|
||||
struct lruhash_entry* e;
|
||||
for(i=0; i<infra->hosts->size; i++) {
|
||||
lock_quick_lock(&infra->hosts->array[i]->lock);
|
||||
for(bin=0; bin<infra->hosts->array[i]->size; bin++) {
|
||||
lock_quick_lock(&infra->hosts->array[i]->
|
||||
array[bin].lock);
|
||||
/* count data size in bin items. */
|
||||
for(e = infra->hosts->array[i]->array[bin].
|
||||
overflow_list; e; e = e->overflow_next) {
|
||||
lock_rw_rdlock(&e->lock);
|
||||
s += count_host_lame(e);
|
||||
lock_rw_unlock(&e->lock);
|
||||
}
|
||||
lock_quick_unlock(&infra->hosts->array[i]->
|
||||
array[bin].lock);
|
||||
}
|
||||
lock_quick_unlock(&infra->hosts->array[i]->lock);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
Vendored
+56
-6
@@ -91,6 +91,9 @@ struct infra_lame_key {
|
||||
struct infra_lame_data {
|
||||
/** TTL of this entry. absolute time. */
|
||||
time_t ttl;
|
||||
/** is the host lame (does not serve the zone authoritatively),
|
||||
* or is the host dnssec lame (does not serve DNSSEC data) */
|
||||
int isdnsseclame;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -103,8 +106,8 @@ struct infra_cache {
|
||||
int host_ttl;
|
||||
/** TTL for Lameness information, in seconds */
|
||||
int lame_ttl;
|
||||
/** infra lame cache max memory per host, for this many entries */
|
||||
size_t max_lame;
|
||||
/** infra lame cache max memory per host, in bytes */
|
||||
size_t max_lame_size;
|
||||
};
|
||||
|
||||
/** infra host cache default hash lookup size */
|
||||
@@ -172,7 +175,7 @@ int infra_host(struct infra_cache* infra, struct sockaddr_storage* addr,
|
||||
* @param name: domain name of zone apex.
|
||||
* @param namelen: length of domain name.
|
||||
* @param timenow: what time it is now.
|
||||
* @return: 0 if not lame or unknown or timed out, true if lame.
|
||||
* @return: 0 if not lame or unknown or timed out, 1 if lame, 2 if dnsseclame.
|
||||
*/
|
||||
int infra_lookup_lame(struct infra_host_data* host,
|
||||
uint8_t* name, size_t namelen, time_t timenow);
|
||||
@@ -185,11 +188,13 @@ int infra_lookup_lame(struct infra_host_data* host,
|
||||
* @param name: domain name of zone apex.
|
||||
* @param namelen: length of domain name.
|
||||
* @param timenow: what time it is now.
|
||||
* @param dnsseclame: if true the host is set dnssec lame.
|
||||
* if false, the host is marked lame (not serving the zone).
|
||||
* @return: 0 on error.
|
||||
*/
|
||||
int infra_set_lame(struct infra_cache* infra,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen,
|
||||
uint8_t* name, size_t namelen, time_t timenow);
|
||||
uint8_t* name, size_t namelen, time_t timenow, int dnsseclame);
|
||||
|
||||
/**
|
||||
* Update rtt information for the host.
|
||||
@@ -199,12 +204,21 @@ int infra_set_lame(struct infra_cache* infra,
|
||||
* @param roundtrip: estimate of roundtrip time in milliseconds or -1 for
|
||||
* timeout.
|
||||
* @param timenow: what time it is now.
|
||||
* @return: 0 on error.
|
||||
* @return: 0 on error. new rto otherwise.
|
||||
*/
|
||||
int infra_rtt_update(struct infra_cache* infra,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen,
|
||||
int roundtrip, time_t timenow);
|
||||
|
||||
/**
|
||||
* Update information for the host, store that a TCP transaction works.
|
||||
* @param infra: infrastructure cache.
|
||||
* @param addr: host address.
|
||||
* @param addrlen: length of addr.
|
||||
*/
|
||||
void infra_update_tcp_works(struct infra_cache* infra,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen);
|
||||
|
||||
/**
|
||||
* Update edns information for the host.
|
||||
* @param infra: infrastructure cache.
|
||||
@@ -226,6 +240,8 @@ int infra_edns_update(struct infra_cache* infra,
|
||||
* @param name: zone name.
|
||||
* @param namelen: zone name length.
|
||||
* @param lame: if function returns true, this returns lameness of the zone.
|
||||
* @param dnsseclame: if function returns true, this returns if the zone
|
||||
* is dnssec-lame.
|
||||
* @param rtt: if function returns true, this returns avg rtt of the server.
|
||||
* The rtt value is unclamped and reflects recent timeouts.
|
||||
* @param timenow: what time it is now.
|
||||
@@ -233,6 +249,40 @@ int infra_edns_update(struct infra_cache* infra,
|
||||
*/
|
||||
int infra_get_lame_rtt(struct infra_cache* infra,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen,
|
||||
uint8_t* name, size_t namelen, int* lame, int* rtt, time_t timenow);
|
||||
uint8_t* name, size_t namelen, int* lame, int* dnsseclame,
|
||||
int* rtt, time_t timenow);
|
||||
|
||||
/**
|
||||
* Get memory used by the infra cache.
|
||||
* @param infra: infrastructure cache.
|
||||
* @return memory in use in bytes.
|
||||
*/
|
||||
size_t infra_get_mem(struct infra_cache* infra);
|
||||
|
||||
/** calculate size for the hashtable, does not count size of lameness,
|
||||
* so the hashtable is a fixed number of items */
|
||||
size_t infra_host_sizefunc(void* k, void* d);
|
||||
|
||||
/** compare two addresses, returns -1, 0, or +1 */
|
||||
int infra_host_compfunc(void* key1, void* key2);
|
||||
|
||||
/** delete key, and destroy the lock */
|
||||
void infra_host_delkeyfunc(void* k, void* arg, int il);
|
||||
|
||||
/** delete data and destroy the lameness hashtable */
|
||||
void infra_host_deldatafunc(void* d, void* arg);
|
||||
|
||||
/** calculate size, which is fixed, zonename does not count so that
|
||||
* a fixed number of items is stored */
|
||||
size_t infra_lame_sizefunc(void* k, void* d);
|
||||
|
||||
/** compare zone names, returns -1, 0, +1 */
|
||||
int infra_lame_compfunc(void* key1, void* key2);
|
||||
|
||||
/** free key, lock and zonename */
|
||||
void infra_lame_delkeyfunc(void* k, void* arg, int il);
|
||||
|
||||
/** free the lameness data */
|
||||
void infra_lame_deldatafunc(void* d, void* arg);
|
||||
|
||||
#endif /* SERVICES_CACHE_INFRA_H */
|
||||
|
||||
Vendored
+111
-19
@@ -44,7 +44,8 @@
|
||||
#include "util/config_file.h"
|
||||
#include "util/data/packed_rrset.h"
|
||||
#include "util/data/msgreply.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/alloc.h"
|
||||
|
||||
struct rrset_cache* rrset_cache_create(struct config_file* cfg,
|
||||
struct alloc_cache* alloc)
|
||||
@@ -110,33 +111,48 @@ rrset_cache_touch(struct rrset_cache* r, struct ub_packed_rrset_key* key,
|
||||
|
||||
/** see if rrset needs to be updated in the cache */
|
||||
static int
|
||||
need_to_update_rrset(void* nd, void* cd, uint32_t timenow)
|
||||
need_to_update_rrset(void* nd, void* cd, uint32_t timenow, int equal)
|
||||
{
|
||||
struct packed_rrset_data* newd = (struct packed_rrset_data*)nd;
|
||||
struct packed_rrset_data* cached = (struct packed_rrset_data*)cd;
|
||||
/* o store if rrset has been validated */
|
||||
if( newd->security > cached->security) {
|
||||
return 1;
|
||||
}
|
||||
/* o if current RRset is more trustworthy - insert it */
|
||||
if( newd->trust > cached->trust )
|
||||
if( newd->trust > cached->trust ) {
|
||||
/* if the cached rrset is bogus, and this one equal,
|
||||
* do not update the TTL - let it expire. */
|
||||
if(equal && cached->ttl >= timenow &&
|
||||
cached->security == sec_status_bogus)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
/* o item in cache has expired */
|
||||
if( cached->ttl < timenow )
|
||||
return 1;
|
||||
/* o same trust, but different in data - insert it */
|
||||
if( newd->trust == cached->trust &&
|
||||
!rrsetdata_equal(newd, cached))
|
||||
if( newd->trust == cached->trust && !equal )
|
||||
return 1;
|
||||
/* o see if TTL is better than TTL in cache. */
|
||||
/* if so, see if rrset+rdata is the same */
|
||||
/* if so, update TTL in cache, even if trust is worse. */
|
||||
if( newd->ttl > cached->ttl &&
|
||||
rrsetdata_equal(newd, cached)) {
|
||||
/* since all else is the same, use the best trust value */
|
||||
if(newd->trust < cached->trust)
|
||||
newd->trust = cached->trust;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Update RRSet special key ID */
|
||||
static void
|
||||
rrset_update_id(struct rrset_ref* ref, struct alloc_cache* alloc)
|
||||
{
|
||||
/* this may clear the cache and invalidate lock below */
|
||||
uint64_t newid = alloc_get_id(alloc);
|
||||
/* obtain writelock */
|
||||
lock_rw_wrlock(&ref->key->entry.lock);
|
||||
/* check if it was deleted in the meantime, if so, skip update */
|
||||
if(ref->key->id == ref->id) {
|
||||
ref->key->id = newid;
|
||||
ref->id = newid;
|
||||
}
|
||||
lock_rw_unlock(&ref->key->entry.lock);
|
||||
}
|
||||
|
||||
int
|
||||
rrset_cache_update(struct rrset_cache* r, struct rrset_ref* ref,
|
||||
struct alloc_cache* alloc, uint32_t timenow)
|
||||
@@ -144,6 +160,9 @@ rrset_cache_update(struct rrset_cache* r, struct rrset_ref* ref,
|
||||
struct lruhash_entry* e;
|
||||
struct ub_packed_rrset_key* k = ref->key;
|
||||
hashvalue_t h = k->entry.hash;
|
||||
uint16_t rrset_type = ntohs(k->rk.type);
|
||||
int equal = 0;
|
||||
log_assert(ref->id != 0 && k->id != 0);
|
||||
/* looks up item with a readlock - no editing! */
|
||||
if((e=slabhash_lookup(&r->table, h, k, 0)) != 0) {
|
||||
/* return id and key as they will be used in the cache
|
||||
@@ -155,7 +174,10 @@ rrset_cache_update(struct rrset_cache* r, struct rrset_ref* ref,
|
||||
*/
|
||||
ref->key = (struct ub_packed_rrset_key*)e->key;
|
||||
ref->id = ref->key->id;
|
||||
if(!need_to_update_rrset(k->entry.data, e->data, timenow)) {
|
||||
equal = rrsetdata_equal((struct packed_rrset_data*)k->entry.
|
||||
data, (struct packed_rrset_data*)e->data);
|
||||
if(!need_to_update_rrset(k->entry.data, e->data, timenow,
|
||||
equal)) {
|
||||
/* cache is superior, return that value */
|
||||
lock_rw_unlock(&e->lock);
|
||||
ub_packed_rrset_parsedelete(k, alloc);
|
||||
@@ -170,9 +192,19 @@ rrset_cache_update(struct rrset_cache* r, struct rrset_ref* ref,
|
||||
/* use insert to update entry to manage lruhash
|
||||
* cache size values nicely. */
|
||||
}
|
||||
log_assert(ref->key->id != 0);
|
||||
slabhash_insert(&r->table, h, &k->entry, k->entry.data, alloc);
|
||||
if(e)
|
||||
if(e) {
|
||||
/* For NSEC, NSEC3, DNAME, when rdata is updated, update
|
||||
* the ID number so that proofs in message cache are
|
||||
* invalidated */
|
||||
if((rrset_type == LDNS_RR_TYPE_NSEC
|
||||
|| rrset_type == LDNS_RR_TYPE_NSEC3
|
||||
|| rrset_type == LDNS_RR_TYPE_DNAME) && !equal) {
|
||||
rrset_update_id(ref, alloc);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -239,12 +271,12 @@ rrset_array_unlock(struct rrset_ref* ref, size_t count)
|
||||
}
|
||||
|
||||
void
|
||||
rrset_array_unlock_touch(struct rrset_cache* r, struct region* scratch,
|
||||
rrset_array_unlock_touch(struct rrset_cache* r, struct regional* scratch,
|
||||
struct rrset_ref* ref, size_t count)
|
||||
{
|
||||
hashvalue_t* h;
|
||||
size_t i;
|
||||
if(!(h = (hashvalue_t*)region_alloc(scratch,
|
||||
if(!(h = (hashvalue_t*)regional_alloc(scratch,
|
||||
sizeof(hashvalue_t)*count)))
|
||||
log_warn("rrset LRU: memory allocation failed");
|
||||
else /* store hash values */
|
||||
@@ -265,3 +297,63 @@ rrset_array_unlock_touch(struct rrset_cache* r, struct region* scratch,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rrset_update_sec_status(struct rrset_cache* r,
|
||||
struct ub_packed_rrset_key* rrset)
|
||||
{
|
||||
uint32_t now = (uint32_t)time(0);
|
||||
struct packed_rrset_data* updata =
|
||||
(struct packed_rrset_data*)rrset->entry.data;
|
||||
struct lruhash_entry* e;
|
||||
struct packed_rrset_data* cachedata;
|
||||
|
||||
/* hash it again to make sure it has a hash */
|
||||
rrset->entry.hash = rrset_key_hash(&rrset->rk);
|
||||
|
||||
e = slabhash_lookup(&r->table, rrset->entry.hash, rrset, 1);
|
||||
if(!e)
|
||||
return; /* not in the cache anymore */
|
||||
cachedata = (struct packed_rrset_data*)e->data;
|
||||
if(!rrsetdata_equal(updata, cachedata)) {
|
||||
lock_rw_unlock(&e->lock);
|
||||
return; /* rrset has changed in the meantime */
|
||||
}
|
||||
/* update the cached rrset */
|
||||
if(updata->security > cachedata->security) {
|
||||
cachedata->trust = updata->trust;
|
||||
cachedata->security = updata->security;
|
||||
cachedata->ttl = updata->ttl + now;
|
||||
}
|
||||
lock_rw_unlock(&e->lock);
|
||||
}
|
||||
|
||||
void
|
||||
rrset_check_sec_status(struct rrset_cache* r,
|
||||
struct ub_packed_rrset_key* rrset)
|
||||
{
|
||||
uint32_t now = (uint32_t)time(0);
|
||||
struct packed_rrset_data* updata =
|
||||
(struct packed_rrset_data*)rrset->entry.data;
|
||||
struct lruhash_entry* e;
|
||||
struct packed_rrset_data* cachedata;
|
||||
|
||||
/* hash it again to make sure it has a hash */
|
||||
rrset->entry.hash = rrset_key_hash(&rrset->rk);
|
||||
|
||||
e = slabhash_lookup(&r->table, rrset->entry.hash, rrset, 0);
|
||||
if(!e)
|
||||
return; /* not in the cache anymore */
|
||||
cachedata = (struct packed_rrset_data*)e->data;
|
||||
if(now > cachedata->ttl || !rrsetdata_equal(updata, cachedata)) {
|
||||
lock_rw_unlock(&e->lock);
|
||||
return; /* expired, or rrset has changed in the meantime */
|
||||
}
|
||||
if(cachedata->security > updata->security) {
|
||||
updata->security = cachedata->security;
|
||||
if(cachedata->security == sec_status_bogus)
|
||||
updata->ttl = cachedata->ttl - now;
|
||||
updata->trust = cachedata->trust;
|
||||
}
|
||||
lock_rw_unlock(&e->lock);
|
||||
}
|
||||
|
||||
Vendored
+25
-2
@@ -47,7 +47,7 @@
|
||||
struct config_file;
|
||||
struct alloc_cache;
|
||||
struct rrset_ref;
|
||||
struct region;
|
||||
struct regional;
|
||||
|
||||
/**
|
||||
* The rrset cache
|
||||
@@ -181,7 +181,30 @@ void rrset_array_unlock(struct rrset_ref* ref, size_t count);
|
||||
* duplicate references are allowed and handled.
|
||||
* @param count: size of array.
|
||||
*/
|
||||
void rrset_array_unlock_touch(struct rrset_cache* r, struct region* scratch,
|
||||
void rrset_array_unlock_touch(struct rrset_cache* r, struct regional* scratch,
|
||||
struct rrset_ref* ref, size_t count);
|
||||
|
||||
/**
|
||||
* Update security status of an rrset. Looks up the rrset.
|
||||
* If found, checks if rdata is equal.
|
||||
* If so, it will update the security, trust and rrset-ttl values.
|
||||
* The values are only updated if security is increased (towards secure).
|
||||
* @param r: the rrset cache.
|
||||
* @param rrset: which rrset to attempt to update. This rrset is left
|
||||
* untouched. The rrset in the cache is updated in-place.
|
||||
*/
|
||||
void rrset_update_sec_status(struct rrset_cache* r,
|
||||
struct ub_packed_rrset_key* rrset);
|
||||
|
||||
/**
|
||||
* Looks up security status of an rrset. Looks up the rrset.
|
||||
* If found, checks if rdata is equal, and entry did not expire.
|
||||
* If so, it will update the security, trust and rrset-ttl values.
|
||||
* @param r: the rrset cache.
|
||||
* @param rrset: This rrset may change security status due to the cache.
|
||||
* But its status will only improve, towards secure.
|
||||
*/
|
||||
void rrset_check_sec_status(struct rrset_cache* r,
|
||||
struct ub_packed_rrset_key* rrset);
|
||||
|
||||
#endif /* SERVICES_CACHE_RRSET_H */
|
||||
|
||||
@@ -74,6 +74,7 @@ verbose_print_addr(struct addrinfo *addr)
|
||||
(socklen_t)sizeof(buf)) == 0) {
|
||||
strncpy(buf, "(null)", sizeof(buf));
|
||||
}
|
||||
buf[sizeof(buf)-1] = 0;
|
||||
verbose(VERB_ALGO, "creating %s%s socket %s %d",
|
||||
addr->ai_socktype==SOCK_DGRAM?"udp":
|
||||
addr->ai_socktype==SOCK_STREAM?"tcp":"otherproto",
|
||||
@@ -288,7 +289,8 @@ listen_cp_insert(struct comm_point* c, struct listen_dnsport* front)
|
||||
|
||||
struct listen_dnsport*
|
||||
listen_create(struct comm_base* base, struct listen_port* ports,
|
||||
size_t bufsize, comm_point_callback_t* cb, void *cb_arg)
|
||||
size_t bufsize, int tcp_accept_count,
|
||||
comm_point_callback_t* cb, void *cb_arg)
|
||||
{
|
||||
struct listen_dnsport* front = (struct listen_dnsport*)
|
||||
malloc(sizeof(struct listen_dnsport));
|
||||
@@ -308,7 +310,7 @@ listen_create(struct comm_base* base, struct listen_port* ports,
|
||||
cp = comm_point_create_udp(base, ports->fd,
|
||||
front->udp_buff, cb, cb_arg);
|
||||
else cp = comm_point_create_tcp(base, ports->fd,
|
||||
TCP_ACCEPT_COUNT, bufsize, cb, cb_arg);
|
||||
tcp_accept_count, bufsize, cb, cb_arg);
|
||||
if(!cp) {
|
||||
log_err("can't create commpoint");
|
||||
listen_delete(front);
|
||||
@@ -381,10 +383,14 @@ listening_ports_open(struct config_file* cfg)
|
||||
struct listen_port* list = NULL;
|
||||
struct addrinfo hints;
|
||||
int i, do_ip4, do_ip6;
|
||||
int do_tcp;
|
||||
char portbuf[32];
|
||||
snprintf(portbuf, sizeof(portbuf), "%d", cfg->port);
|
||||
do_ip4 = cfg->do_ip4;
|
||||
do_ip6 = cfg->do_ip6;
|
||||
do_tcp = cfg->do_tcp;
|
||||
if(cfg->incoming_num_tcp == 0)
|
||||
do_tcp = 0;
|
||||
|
||||
/* getaddrinfo */
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
@@ -403,7 +409,7 @@ listening_ports_open(struct config_file* cfg)
|
||||
if(cfg->num_ifs == 0) {
|
||||
if(do_ip6) {
|
||||
hints.ai_family = AF_INET6;
|
||||
if(!ports_create_if(NULL, cfg->do_udp, cfg->do_tcp,
|
||||
if(!ports_create_if("::1", cfg->do_udp, do_tcp,
|
||||
&hints, portbuf, &list)) {
|
||||
listening_ports_free(list);
|
||||
return NULL;
|
||||
@@ -411,7 +417,7 @@ listening_ports_open(struct config_file* cfg)
|
||||
}
|
||||
if(do_ip4) {
|
||||
hints.ai_family = AF_INET;
|
||||
if(!ports_create_if(NULL, cfg->do_udp, cfg->do_tcp,
|
||||
if(!ports_create_if("127.0.0.1", cfg->do_udp, do_tcp,
|
||||
&hints, portbuf, &list)) {
|
||||
listening_ports_free(list);
|
||||
return NULL;
|
||||
@@ -423,7 +429,7 @@ listening_ports_open(struct config_file* cfg)
|
||||
continue;
|
||||
hints.ai_family = AF_INET6;
|
||||
if(!ports_create_if(cfg->ifs[i], cfg->do_udp,
|
||||
cfg->do_tcp, &hints, portbuf, &list)) {
|
||||
do_tcp, &hints, portbuf, &list)) {
|
||||
listening_ports_free(list);
|
||||
return NULL;
|
||||
}
|
||||
@@ -432,7 +438,7 @@ listening_ports_open(struct config_file* cfg)
|
||||
continue;
|
||||
hints.ai_family = AF_INET;
|
||||
if(!ports_create_if(cfg->ifs[i], cfg->do_udp,
|
||||
cfg->do_tcp, &hints, portbuf, &list)) {
|
||||
do_tcp, &hints, portbuf, &list)) {
|
||||
listening_ports_free(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -48,9 +48,6 @@ struct listen_list;
|
||||
struct addrinfo;
|
||||
struct config_file;
|
||||
|
||||
/** number of simultaneous open TCP connections for queries */
|
||||
#define TCP_ACCEPT_COUNT 10
|
||||
|
||||
/**
|
||||
* Listening for queries structure.
|
||||
* Contains list of query-listen sockets.
|
||||
@@ -111,13 +108,15 @@ void listening_ports_free(struct listen_port* list);
|
||||
* for default all ifs.
|
||||
* @param ports: the list of shared ports.
|
||||
* @param bufsize: size of datagram buffer.
|
||||
* @param tcp_accept_count: max number of simultaneous TCP connections
|
||||
* from clients.
|
||||
* @param cb: callback function when a request arrives. It is passed
|
||||
* the packet and user argument. Return true to send a reply.
|
||||
* @param cb_arg: user data argument for callback function.
|
||||
* @return: the malloced listening structure, ready for use. NULL on error.
|
||||
*/
|
||||
struct listen_dnsport* listen_create(struct comm_base* base,
|
||||
struct listen_port* ports, size_t bufsize,
|
||||
struct listen_port* ports, size_t bufsize, int tcp_accept_count,
|
||||
comm_point_callback_t* cb, void* cb_arg);
|
||||
|
||||
/**
|
||||
|
||||
+141
-48
@@ -45,23 +45,25 @@
|
||||
#include "config.h"
|
||||
#include "services/mesh.h"
|
||||
#include "services/outbound_list.h"
|
||||
#include "services/cache/dns.h"
|
||||
#include "util/log.h"
|
||||
#include "util/net_help.h"
|
||||
#include "util/module.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/data/msgencode.h"
|
||||
#include "util/timehist.h"
|
||||
#include "util/fptr_wlist.h"
|
||||
#include "util/alloc.h"
|
||||
|
||||
/** compare two mesh_states */
|
||||
static int
|
||||
int
|
||||
mesh_state_compare(const void* ap, const void* bp)
|
||||
{
|
||||
struct mesh_state* a = (struct mesh_state*)ap;
|
||||
struct mesh_state* b = (struct mesh_state*)bp;
|
||||
|
||||
if(a->is_priming && !b->is_priming)
|
||||
if(a->s.is_priming && !b->s.is_priming)
|
||||
return -1;
|
||||
if(!a->is_priming && b->is_priming)
|
||||
if(!a->s.is_priming && b->s.is_priming)
|
||||
return 1;
|
||||
|
||||
if((a->s.query_flags&BIT_RD) && !(b->s.query_flags&BIT_RD))
|
||||
@@ -69,11 +71,15 @@ mesh_state_compare(const void* ap, const void* bp)
|
||||
if(!(a->s.query_flags&BIT_RD) && (b->s.query_flags&BIT_RD))
|
||||
return 1;
|
||||
|
||||
if((a->s.query_flags&BIT_CD) && !(b->s.query_flags&BIT_CD))
|
||||
return -1;
|
||||
if(!(a->s.query_flags&BIT_CD) && (b->s.query_flags&BIT_CD))
|
||||
return 1;
|
||||
|
||||
return query_info_compare(&a->s.qinfo, &b->s.qinfo);
|
||||
}
|
||||
|
||||
/** compare two mesh references */
|
||||
static int
|
||||
int
|
||||
mesh_state_ref_compare(const void* ap, const void* bp)
|
||||
{
|
||||
struct mesh_state_ref* a = (struct mesh_state_ref*)ap;
|
||||
@@ -190,15 +196,15 @@ struct mesh_state*
|
||||
mesh_state_create(struct module_env* env, struct query_info* qinfo,
|
||||
uint16_t qflags, int prime)
|
||||
{
|
||||
region_type* region = region_create(malloc, free);
|
||||
struct regional* region = alloc_reg_obtain(env->alloc);
|
||||
struct mesh_state* mstate;
|
||||
int i;
|
||||
if(!region)
|
||||
return NULL;
|
||||
mstate = (struct mesh_state*)region_alloc(region,
|
||||
mstate = (struct mesh_state*)regional_alloc(region,
|
||||
sizeof(struct mesh_state));
|
||||
if(!mstate) {
|
||||
region_destroy(region);
|
||||
alloc_reg_release(env->alloc, region);
|
||||
return NULL;
|
||||
}
|
||||
memset(mstate, 0, sizeof(*mstate));
|
||||
@@ -206,26 +212,28 @@ mesh_state_create(struct module_env* env, struct query_info* qinfo,
|
||||
mstate->run_node = *RBTREE_NULL;
|
||||
mstate->node.key = mstate;
|
||||
mstate->run_node.key = mstate;
|
||||
mstate->debug_flags = 0;
|
||||
mstate->is_priming = prime;
|
||||
mstate->reply_list = NULL;
|
||||
rbtree_init(&mstate->super_set, &mesh_state_ref_compare);
|
||||
rbtree_init(&mstate->sub_set, &mesh_state_ref_compare);
|
||||
mstate->num_activated = 0;
|
||||
/* init module qstate */
|
||||
mstate->s.qinfo.qtype = qinfo->qtype;
|
||||
mstate->s.qinfo.qclass = qinfo->qclass;
|
||||
mstate->s.qinfo.qname_len = qinfo->qname_len;
|
||||
mstate->s.qinfo.qname = region_alloc_init(region, qinfo->qname,
|
||||
mstate->s.qinfo.qname = regional_alloc_init(region, qinfo->qname,
|
||||
qinfo->qname_len);
|
||||
if(!mstate->s.qinfo.qname) {
|
||||
region_destroy(region);
|
||||
alloc_reg_release(env->alloc, region);
|
||||
return NULL;
|
||||
}
|
||||
/* remove all weird bits from qflags */
|
||||
mstate->s.query_flags = (qflags & BIT_RD);
|
||||
mstate->s.query_flags = (qflags & (BIT_RD|BIT_CD));
|
||||
mstate->s.is_priming = prime;
|
||||
mstate->s.reply = NULL;
|
||||
mstate->s.region = region;
|
||||
mstate->s.curmod = 0;
|
||||
mstate->s.return_msg = 0;
|
||||
mstate->s.return_rcode = LDNS_RCODE_NOERROR;
|
||||
mstate->s.env = env;
|
||||
mstate->s.mesh_info = mstate;
|
||||
/* init modules */
|
||||
@@ -246,11 +254,12 @@ mesh_state_cleanup(struct mesh_state* mstate)
|
||||
/* de-init modules */
|
||||
mesh = mstate->s.env->mesh;
|
||||
for(i=0; i<mesh->num_modules; i++) {
|
||||
log_assert(fptr_whitelist_mod_clear(mesh->modfunc[i]->clear));
|
||||
(*mesh->modfunc[i]->clear)(&mstate->s, i);
|
||||
mstate->s.minfo[i] = NULL;
|
||||
mstate->s.ext_state[i] = module_finished;
|
||||
}
|
||||
region_destroy(mstate->s.region);
|
||||
alloc_reg_release(mstate->s.env->alloc, mstate->s.region);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -341,9 +350,9 @@ int mesh_state_attachment(struct mesh_state* super, struct mesh_state* sub)
|
||||
struct rbnode_t* n;
|
||||
struct mesh_state_ref* subref; /* points to sub, inserted in super */
|
||||
struct mesh_state_ref* superref; /* points to super, inserted in sub */
|
||||
if( !(subref = region_alloc(super->s.region,
|
||||
if( !(subref = regional_alloc(super->s.region,
|
||||
sizeof(struct mesh_state_ref))) ||
|
||||
!(superref = region_alloc(sub->s.region,
|
||||
!(superref = regional_alloc(sub->s.region,
|
||||
sizeof(struct mesh_state_ref))) ) {
|
||||
log_err("mesh_state_attachment: out of memory");
|
||||
return 0;
|
||||
@@ -418,6 +427,15 @@ mesh_send_reply(struct mesh_state* m, int rcode, struct reply_info* rep,
|
||||
struct mesh_reply* r)
|
||||
{
|
||||
struct timeval end_time;
|
||||
int secure;
|
||||
/* examine security status */
|
||||
if(m->s.env->need_to_validate && !(r->qflags&BIT_CD) && rep &&
|
||||
rep->security <= sec_status_bogus) {
|
||||
rcode = LDNS_RCODE_SERVFAIL;
|
||||
}
|
||||
if(rep && rep->security == sec_status_secure)
|
||||
secure = 1;
|
||||
else secure = 0;
|
||||
/* send the reply */
|
||||
if(rcode) {
|
||||
error_encode(r->query_reply.c->buffer, rcode, &m->s.qinfo,
|
||||
@@ -432,7 +450,7 @@ mesh_send_reply(struct mesh_state* m, int rcode, struct reply_info* rep,
|
||||
if(!reply_info_answer_encode(&m->s.qinfo, rep, r->qid,
|
||||
r->qflags, r->query_reply.c->buffer, 0, 1,
|
||||
m->s.env->scratch, udp_size, &r->edns,
|
||||
(int)(r->edns.bits & EDNS_DO)))
|
||||
(int)(r->edns.bits & EDNS_DO), secure))
|
||||
{
|
||||
error_encode(r->query_reply.c->buffer,
|
||||
LDNS_RCODE_SERVFAIL, &m->s.qinfo, r->qid,
|
||||
@@ -456,32 +474,28 @@ mesh_send_reply(struct mesh_state* m, int rcode, struct reply_info* rep,
|
||||
}
|
||||
}
|
||||
|
||||
void mesh_query_done(struct module_qstate* qstate, int rcode,
|
||||
struct reply_info* rep)
|
||||
void mesh_query_done(struct mesh_state* mstate)
|
||||
{
|
||||
struct mesh_state* m = qstate->mesh_info;
|
||||
struct mesh_reply* r;
|
||||
log_assert(!(m->debug_flags&1)); /* not twice! */
|
||||
m->debug_flags |= 1;
|
||||
for(r = m->reply_list; r; r = r->next) {
|
||||
mesh_send_reply(m, rcode, rep, r);
|
||||
struct reply_info* rep = (mstate->s.return_msg?
|
||||
mstate->s.return_msg->rep:NULL);
|
||||
for(r = mstate->reply_list; r; r = r->next) {
|
||||
mesh_send_reply(mstate, mstate->s.return_rcode, rep, r);
|
||||
}
|
||||
}
|
||||
|
||||
void mesh_walk_supers(struct module_qstate* qstate, int id,
|
||||
void (*cb)(struct module_qstate*, int, struct module_qstate*))
|
||||
void mesh_walk_supers(struct mesh_area* mesh, struct mesh_state* mstate)
|
||||
{
|
||||
struct mesh_state* m = qstate->mesh_info;
|
||||
struct mesh_area* mesh = m->s.env->mesh;
|
||||
struct mesh_state_ref* ref;
|
||||
log_assert(!(m->debug_flags&2)); /* not twice! */
|
||||
m->debug_flags |= 2;
|
||||
RBTREE_FOR(ref, struct mesh_state_ref*, &qstate->mesh_info->super_set)
|
||||
RBTREE_FOR(ref, struct mesh_state_ref*, &mstate->super_set)
|
||||
{
|
||||
/* make super runnable */
|
||||
(void)rbtree_insert(&mesh->run, &ref->s->run_node);
|
||||
/* callback */
|
||||
(*cb)(qstate, id, &ref->s->s);
|
||||
/* callback the function to inform super of result */
|
||||
log_assert(fptr_whitelist_mod_inform_super(
|
||||
mesh->modfunc[ref->s->s.curmod]->inform_super));
|
||||
(*mesh->modfunc[ref->s->s.curmod]->inform_super)(&mstate->s,
|
||||
ref->s->s.curmod, &ref->s->s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,7 +506,7 @@ struct mesh_state* mesh_area_find(struct mesh_area* mesh,
|
||||
struct mesh_state* result;
|
||||
|
||||
key.node.key = &key;
|
||||
key.is_priming = prime;
|
||||
key.s.is_priming = prime;
|
||||
key.s.qinfo = *qinfo;
|
||||
key.s.query_flags = qflags;
|
||||
|
||||
@@ -503,7 +517,7 @@ struct mesh_state* mesh_area_find(struct mesh_area* mesh,
|
||||
int mesh_state_add_reply(struct mesh_state* s, struct edns_data* edns,
|
||||
struct comm_reply* rep, uint16_t qid, uint16_t qflags)
|
||||
{
|
||||
struct mesh_reply* r = region_alloc(s->s.region,
|
||||
struct mesh_reply* r = regional_alloc(s->s.region,
|
||||
sizeof(struct mesh_reply));
|
||||
if(!r)
|
||||
return 0;
|
||||
@@ -521,6 +535,65 @@ int mesh_state_add_reply(struct mesh_state* s, struct edns_data* edns,
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Continue processing the mesh state at another module.
|
||||
* Handles module to modules tranfer of control.
|
||||
* Handles module finished.
|
||||
* @param mesh: the mesh area.
|
||||
* @param mstate: currently active mesh state.
|
||||
* Deleted if finished, calls _done and _supers to
|
||||
* send replies to clients and inform other mesh states.
|
||||
* This in turn may create additional runnable mesh states.
|
||||
* @param s: state at which the current module exited.
|
||||
* @param ev: the event sent to the module.
|
||||
* returned is the event to send to the next module.
|
||||
* @return true if continue processing at the new module.
|
||||
* false if not continued processing is needed.
|
||||
*/
|
||||
static int
|
||||
mesh_continue(struct mesh_area* mesh, struct mesh_state* mstate,
|
||||
enum module_ext_state s, enum module_ev* ev)
|
||||
{
|
||||
mstate->num_activated++;
|
||||
if(mstate->num_activated > MESH_MAX_ACTIVATION) {
|
||||
/* module is looping. Stop it. */
|
||||
log_err("internal error: looping module stopped");
|
||||
log_query_info(VERB_DETAIL, "pass error for qstate",
|
||||
&mstate->s.qinfo);
|
||||
s = module_error;
|
||||
}
|
||||
if(s == module_wait_module) {
|
||||
/* start next module */
|
||||
mstate->s.curmod++;
|
||||
if(mesh->num_modules == mstate->s.curmod) {
|
||||
log_err("Cannot pass to next module; at last module");
|
||||
log_query_info(VERB_DETAIL, "pass error for qstate",
|
||||
&mstate->s.qinfo);
|
||||
mstate->s.curmod--;
|
||||
return mesh_continue(mesh, mstate, module_error, ev);
|
||||
}
|
||||
*ev = module_event_pass;
|
||||
return 1;
|
||||
}
|
||||
if(s == module_error && mstate->s.return_rcode == LDNS_RCODE_NOERROR) {
|
||||
/* error is bad, handle pass back up below */
|
||||
mstate->s.return_rcode = LDNS_RCODE_SERVFAIL;
|
||||
}
|
||||
if(s == module_error || s == module_finished) {
|
||||
if(mstate->s.curmod == 0) {
|
||||
mesh_query_done(mstate);
|
||||
mesh_walk_supers(mesh, mstate);
|
||||
mesh_state_delete(&mstate->s);
|
||||
return 0;
|
||||
}
|
||||
/* pass along the locus of control */
|
||||
mstate->s.curmod --;
|
||||
*ev = module_event_moddone;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mesh_run(struct mesh_area* mesh, struct mesh_state* mstate,
|
||||
enum module_ev ev, struct outbound_entry* e)
|
||||
{
|
||||
@@ -528,32 +601,51 @@ void mesh_run(struct mesh_area* mesh, struct mesh_state* mstate,
|
||||
verbose(VERB_ALGO, "mesh_run: start");
|
||||
while(mstate) {
|
||||
/* run the module */
|
||||
log_assert(fptr_whitelist_mod_operate(
|
||||
mesh->modfunc[mstate->s.curmod]->operate));
|
||||
(*mesh->modfunc[mstate->s.curmod]->operate)
|
||||
(&mstate->s, ev, mstate->s.curmod, e);
|
||||
|
||||
/* examine results */
|
||||
mstate->s.reply = NULL;
|
||||
region_free_all(mstate->s.env->scratch);
|
||||
regional_free_all(mstate->s.env->scratch);
|
||||
s = mstate->s.ext_state[mstate->s.curmod];
|
||||
verbose(VERB_ALGO, "mesh_run: %s module exit state is %s",
|
||||
mesh->modfunc[mstate->s.curmod]->name, strextstate(s));
|
||||
if(s == module_error || s == module_finished) {
|
||||
/* must have called _done and _supers */
|
||||
log_assert(mstate->debug_flags == 3);
|
||||
mesh_state_delete(&mstate->s);
|
||||
}
|
||||
e = NULL;
|
||||
if(mesh_continue(mesh, mstate, s, &ev))
|
||||
continue;
|
||||
|
||||
/* run more modules */
|
||||
ev = module_event_pass;
|
||||
e = NULL;
|
||||
if(mesh->run.count > 0) {
|
||||
/* pop random element off the runnable tree */
|
||||
mstate = (struct mesh_state*)mesh->run.root->key;
|
||||
(void)rbtree_delete(&mesh->run, mstate);
|
||||
} else mstate = NULL;
|
||||
}
|
||||
if(verbosity >= VERB_ALGO)
|
||||
if(verbosity >= VERB_ALGO) {
|
||||
mesh_stats(mesh, "mesh_run: end");
|
||||
mesh_log_list(mesh);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mesh_log_list(struct mesh_area* mesh)
|
||||
{
|
||||
char buf[30];
|
||||
struct mesh_state* m;
|
||||
int num = 0;
|
||||
RBTREE_FOR(m, struct mesh_state*, &mesh->all) {
|
||||
snprintf(buf, sizeof(buf), "%d%s%s%s%s%s mod%d %s",
|
||||
num++, (m->s.is_priming)?"p":"", /* prime */
|
||||
(m->s.query_flags&BIT_RD)?"RD":"",
|
||||
(m->s.query_flags&BIT_CD)?"CD":"",
|
||||
(m->super_set.count==0)?"d":"", /* detached */
|
||||
(m->sub_set.count!=0)?"c":"", /* children */
|
||||
m->s.curmod, (m->reply_list)?"hr":"nr"); /*hasreply*/
|
||||
log_query_info(VERB_ALGO, buf, &m->s.qinfo);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -584,7 +676,7 @@ mesh_get_mem(struct mesh_area* mesh)
|
||||
sizeof(struct th_buck)*mesh->histogram->num;
|
||||
RBTREE_FOR(m, struct mesh_state*, &mesh->all) {
|
||||
/* all, including m itself allocated in qstate region */
|
||||
s += region_get_mem(m->s.region);
|
||||
s += regional_get_mem(m->s.region);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@@ -602,11 +694,12 @@ find_in_subsub(struct mesh_state* m, struct mesh_state* tofind)
|
||||
}
|
||||
|
||||
int
|
||||
mesh_detect_cycle(struct module_qstate* qstate, struct query_info* qinfo)
|
||||
mesh_detect_cycle(struct module_qstate* qstate, struct query_info* qinfo,
|
||||
uint16_t flags, int prime)
|
||||
{
|
||||
struct mesh_area* mesh = qstate->env->mesh;
|
||||
struct mesh_state* cyc_m = qstate->mesh_info;
|
||||
struct mesh_state* dep_m = mesh_area_find(mesh, qinfo, BIT_RD, 0);
|
||||
struct mesh_state* dep_m = mesh_area_find(mesh, qinfo, flags, prime);
|
||||
if(!dep_m)
|
||||
return 0;
|
||||
if(dep_m == cyc_m || find_in_subsub(dep_m, cyc_m))
|
||||
|
||||
+40
-24
@@ -57,6 +57,12 @@ struct reply_info;
|
||||
struct outbound_entry;
|
||||
struct timehist;
|
||||
|
||||
/**
|
||||
* Maximum number of mesh state activations. Any more is likely an
|
||||
* infinite loop in the module. It is then terminated.
|
||||
*/
|
||||
#define MESH_MAX_ACTIVATION 1000
|
||||
|
||||
/**
|
||||
* Mesh of query states
|
||||
*/
|
||||
@@ -95,7 +101,7 @@ struct mesh_area {
|
||||
/**
|
||||
* A mesh query state
|
||||
* Unique per qname, qtype, qclass (from the qstate).
|
||||
* And RD flag; in case a client turns it off.
|
||||
* And RD / CD flag; in case a client turns it off.
|
||||
* And priming queries are different from ordinary queries (because of hints).
|
||||
*
|
||||
* The entire structure is allocated in a region, this region is the qstate
|
||||
@@ -106,21 +112,19 @@ struct mesh_state {
|
||||
rbnode_t node;
|
||||
/** node in mesh_area runnable tree, key is this struct */
|
||||
rbnode_t run_node;
|
||||
/** if this is a (stub or root) priming query (with hints) */
|
||||
int is_priming;
|
||||
/** the query state. Note that the qinfo and query_flags
|
||||
* may not change. */
|
||||
struct module_qstate s;
|
||||
/** the list of replies to clients for the results */
|
||||
struct mesh_reply* reply_list;
|
||||
/** debug flags */
|
||||
int debug_flags;
|
||||
/** set of superstates (that want this state's result)
|
||||
* contains struct mesh_state_ref* */
|
||||
rbtree_t super_set;
|
||||
/** set of substates (that this state needs to continue)
|
||||
* contains struct mesh_state_ref* */
|
||||
rbtree_t sub_set;
|
||||
/** number of activations for the mesh state */
|
||||
size_t num_activated;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -226,7 +230,7 @@ void mesh_detach_subs(struct module_qstate* qstate);
|
||||
* @param qstate: the state to find mesh state, and that wants to receive
|
||||
* the results from the new subquery.
|
||||
* @param qinfo: what to query for (copied).
|
||||
* @param qflags: what flags to use (RD flag or not).
|
||||
* @param qflags: what flags to use (RD / CD flag or not).
|
||||
* @param prime: if it is a (stub) priming query.
|
||||
* @param newq: If the new subquery needs initialisation, it is returned,
|
||||
* otherwise NULL is returned.
|
||||
@@ -244,28 +248,25 @@ int mesh_attach_sub(struct module_qstate* qstate, struct query_info* qinfo,
|
||||
* Must be called before a module can module_finished or return module_error.
|
||||
* The module must handle the super query states itself as well.
|
||||
*
|
||||
* @param qstate: used for original query info. And to find mesh info.
|
||||
* @param rcode: if not 0 (NOERROR) an error is sent back (and rep ignored).
|
||||
* @param rep: reply to encode and send back to clients.
|
||||
* @param mstate: mesh state that is done. return_rcode and return_msg
|
||||
* are used for replies.
|
||||
* return_rcode: if not 0 (NOERROR) an error is sent back (and
|
||||
* return_msg is ignored).
|
||||
* return_msg: reply to encode and send back to clients.
|
||||
*/
|
||||
void mesh_query_done(struct module_qstate* qstate, int rcode,
|
||||
struct reply_info* rep);
|
||||
void mesh_query_done(struct mesh_state* mstate);
|
||||
|
||||
/**
|
||||
* Get a callback for the super query states that are interested in the
|
||||
* Call inform_super for the super query states that are interested in the
|
||||
* results from this query state. These can then be changed for error
|
||||
* or results.
|
||||
* Must be called befor a module can module_finished or return module_error.
|
||||
* After finishing or module error, the super query states become runnable
|
||||
* with event module_event_pass.
|
||||
* Called when a module is module_finished or returns module_error.
|
||||
* The super query states become runnable with event module_event_pass.
|
||||
*
|
||||
* @param qstate: the state that has results, used to find mesh state.
|
||||
* @param id: module id.
|
||||
* @param cb: callback function. Called as
|
||||
* cb(qstate, id, super_qstate) for every super query state.
|
||||
* @param mesh: mesh area to add newly runnable modules to.
|
||||
* @param mstate: the state that has results, used to find mesh state.
|
||||
*/
|
||||
void mesh_walk_supers(struct module_qstate* qstate, int id,
|
||||
void (*cb)(struct module_qstate*, int, struct module_qstate*));
|
||||
void mesh_walk_supers(struct mesh_area* mesh, struct mesh_state* mstate);
|
||||
|
||||
/**
|
||||
* Delete mesh state, cleanup and also rbtrees and so on.
|
||||
@@ -281,7 +282,7 @@ void mesh_state_delete(struct module_qstate* qstate);
|
||||
* Does not put the mesh state into rbtrees and so on.
|
||||
* @param env: module environment to set.
|
||||
* @param qinfo: query info that the mesh is for.
|
||||
* @param qflags: flags for query (RD flag).
|
||||
* @param qflags: flags for query (RD / CD flag).
|
||||
* @param prime: if true, it is a priming query, set is_priming on mesh state.
|
||||
* @return: new mesh state or NULL on allocation error.
|
||||
*/
|
||||
@@ -301,7 +302,7 @@ void mesh_state_cleanup(struct mesh_state* mstate);
|
||||
*
|
||||
* @param mesh: the mesh area to look in.
|
||||
* @param qinfo: what query
|
||||
* @param qflags: if RD bit is set or not.
|
||||
* @param qflags: if RD / CD bit is set or not.
|
||||
* @param prime: if it is a priming query.
|
||||
* @return: mesh state or NULL if not found.
|
||||
*/
|
||||
@@ -350,6 +351,12 @@ void mesh_run(struct mesh_area* mesh, struct mesh_state* mstate,
|
||||
*/
|
||||
void mesh_stats(struct mesh_area* mesh, const char* str);
|
||||
|
||||
/**
|
||||
* Print all the states in the mesh to the log.
|
||||
* @param mesh: the mesh to print all states of.
|
||||
*/
|
||||
void mesh_log_list(struct mesh_area* mesh);
|
||||
|
||||
/**
|
||||
* Calculate memory size in use by mesh and all queries inside it.
|
||||
* @param mesh: the mesh to examine.
|
||||
@@ -362,10 +369,19 @@ size_t mesh_get_mem(struct mesh_area* mesh);
|
||||
* trees.
|
||||
* @param qstate: given mesh querystate.
|
||||
* @param qinfo: query info for dependency.
|
||||
* @param flags: query flags of dependency.
|
||||
* @param prime: if dependency is a priming query or not.
|
||||
* @return true if the name,type,class exists and the given qstate mesh exists
|
||||
* as a dependency of that name. Thus if qstate becomes dependent on
|
||||
* name,type,class then a cycle is created.
|
||||
*/
|
||||
int mesh_detect_cycle(struct module_qstate* qstate, struct query_info* qinfo);
|
||||
int mesh_detect_cycle(struct module_qstate* qstate, struct query_info* qinfo,
|
||||
uint16_t flags, int prime);
|
||||
|
||||
/** compare two mesh_states */
|
||||
int mesh_state_compare(const void* ap, const void* bp);
|
||||
|
||||
/** compare two mesh references */
|
||||
int mesh_state_ref_compare(const void* ap, const void* bp);
|
||||
|
||||
#endif /* SERVICES_MESH_H */
|
||||
|
||||
@@ -57,7 +57,7 @@ outbound_list_clear(struct outbound_list* list)
|
||||
while(p) {
|
||||
np = p->next;
|
||||
outnet_serviced_query_stop(p->qsent, p);
|
||||
free(p);
|
||||
/* in region, no free needed */
|
||||
p = np;
|
||||
}
|
||||
outbound_list_init(list);
|
||||
@@ -84,5 +84,5 @@ outbound_list_remove(struct outbound_list* list, struct outbound_entry* e)
|
||||
if(e->prev)
|
||||
e->prev->next = e->next;
|
||||
else list->first = e->next;
|
||||
free(e);
|
||||
/* in region, no free needed */
|
||||
}
|
||||
|
||||
+120
-64
@@ -50,6 +50,7 @@
|
||||
#include "util/log.h"
|
||||
#include "util/net_help.h"
|
||||
#include "util/random.h"
|
||||
#include "util/fptr_wlist.h"
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
@@ -60,17 +61,13 @@
|
||||
/** number of times to retry making a random ID that is unique. */
|
||||
#define MAX_ID_RETRY 1000
|
||||
/** number of retries on outgoing UDP queries */
|
||||
#define OUTBOUND_UDP_RETRY 4
|
||||
#define OUTBOUND_UDP_RETRY 1
|
||||
|
||||
/** callback for serviced query UDP answers */
|
||||
static int serviced_udp_callback(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* rep);
|
||||
/** initiate TCP transaction for serviced query */
|
||||
static void serviced_tcp_initiate(struct outside_network* outnet,
|
||||
struct serviced_query* sq, ldns_buffer* buff);
|
||||
|
||||
/** compare function of pending rbtree */
|
||||
static int
|
||||
int
|
||||
pending_cmp(const void* key1, const void* key2)
|
||||
{
|
||||
struct pending *p1 = (struct pending*)key1;
|
||||
@@ -83,8 +80,7 @@ pending_cmp(const void* key1, const void* key2)
|
||||
return sockaddr_cmp(&p1->addr, p1->addrlen, &p2->addr, p2->addrlen);
|
||||
}
|
||||
|
||||
/** compare function of serviced query rbtree */
|
||||
static int
|
||||
int
|
||||
serviced_cmp(const void* key1, const void* key2)
|
||||
{
|
||||
struct serviced_query* q1 = (struct serviced_query*)key1;
|
||||
@@ -95,7 +91,7 @@ serviced_cmp(const void* key1, const void* key2)
|
||||
if(q1->qbuflen > q2->qbuflen)
|
||||
return 1;
|
||||
log_assert(q1->qbuflen == q2->qbuflen);
|
||||
/* FIXME: will not detect alternate casing of qname */
|
||||
/* will not detect alternate casing of qname */
|
||||
if((r = memcmp(q1->qbuf, q2->qbuf, q1->qbuflen)) != 0)
|
||||
return r;
|
||||
if(q1->dnssec != q2->dnssec) {
|
||||
@@ -120,29 +116,30 @@ waiting_tcp_delete(struct waiting_tcp* w)
|
||||
|
||||
/** use next free buffer to service a tcp query */
|
||||
static int
|
||||
outnet_tcp_take_into_use(struct waiting_tcp* w, uint8_t* pkt)
|
||||
outnet_tcp_take_into_use(struct waiting_tcp* w, uint8_t* pkt, size_t pkt_len)
|
||||
{
|
||||
struct pending_tcp* pend = w->outnet->tcp_free;
|
||||
int s;
|
||||
log_assert(pend);
|
||||
log_assert(pkt);
|
||||
log_assert(w->addrlen > 0);
|
||||
/* open socket */
|
||||
#ifndef INET6
|
||||
if(addr_is_ip6(addr))
|
||||
#ifdef INET6
|
||||
if(addr_is_ip6(&w->addr, w->addrlen))
|
||||
s = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||
else
|
||||
#endif
|
||||
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if(s == -1) {
|
||||
log_err("outgoing tcp: socket: %s", strerror(errno));
|
||||
log_addr("failed address", &w->addr, w->addrlen);
|
||||
log_addr(0, "failed address", &w->addr, w->addrlen);
|
||||
return 0;
|
||||
}
|
||||
fd_set_nonblock(s);
|
||||
if(connect(s, (struct sockaddr*)&w->addr, w->addrlen) == -1) {
|
||||
if(errno != EINPROGRESS) {
|
||||
log_err("outgoing tcp: connect: %s", strerror(errno));
|
||||
log_addr("failed address", &w->addr, w->addrlen);
|
||||
log_addr(0, "failed address", &w->addr, w->addrlen);
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
@@ -154,7 +151,7 @@ outnet_tcp_take_into_use(struct waiting_tcp* w, uint8_t* pkt)
|
||||
pend->next_free = NULL;
|
||||
pend->query = w;
|
||||
ldns_buffer_clear(pend->c->buffer);
|
||||
ldns_buffer_write(pend->c->buffer, pkt, w->pkt_len);
|
||||
ldns_buffer_write(pend->c->buffer, pkt, pkt_len);
|
||||
ldns_buffer_flip(pend->c->buffer);
|
||||
pend->c->tcp_is_reading = 0;
|
||||
pend->c->tcp_byte_count = 0;
|
||||
@@ -172,9 +169,12 @@ use_free_buffer(struct outside_network* outnet)
|
||||
outnet->tcp_wait_first = w->next_waiting;
|
||||
if(outnet->tcp_wait_last == w)
|
||||
outnet->tcp_wait_last = NULL;
|
||||
if(!outnet_tcp_take_into_use(w, w->pkt)) {
|
||||
(void)(*w->cb)(NULL, w->cb_arg, NETEVENT_CLOSED, NULL);
|
||||
if(!outnet_tcp_take_into_use(w, w->pkt, w->pkt_len)) {
|
||||
comm_point_callback_t* cb = w->cb;
|
||||
void* cb_arg = w->cb_arg;
|
||||
waiting_tcp_delete(w);
|
||||
log_assert(fptr_whitelist_pending_tcp(cb));
|
||||
(void)(*cb)(NULL, cb_arg, NETEVENT_CLOSED, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,8 +192,7 @@ decomission_pending_tcp(struct outside_network* outnet,
|
||||
use_free_buffer(outnet);
|
||||
}
|
||||
|
||||
/** callback for pending tcp connections */
|
||||
static int
|
||||
int
|
||||
outnet_tcp_cb(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply *reply_info)
|
||||
{
|
||||
@@ -207,18 +206,19 @@ outnet_tcp_cb(struct comm_point* c, void* arg, int error,
|
||||
/* check ID */
|
||||
if(ldns_buffer_limit(c->buffer) < sizeof(uint16_t) ||
|
||||
LDNS_ID_WIRE(ldns_buffer_begin(c->buffer))!=pend->id) {
|
||||
log_addr("outnettcp: bad ID in reply, from:",
|
||||
log_addr(VERB_DETAIL,
|
||||
"outnettcp: bad ID in reply, from:",
|
||||
&pend->query->addr, pend->query->addrlen);
|
||||
error = NETEVENT_CLOSED;
|
||||
}
|
||||
}
|
||||
log_assert(fptr_whitelist_pending_tcp(pend->query->cb));
|
||||
(void)(*pend->query->cb)(c, pend->query->cb_arg, error, reply_info);
|
||||
decomission_pending_tcp(outnet, pend);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** callback for incoming udp answers from the network */
|
||||
static int
|
||||
int
|
||||
outnet_udp_cb(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply *reply_info)
|
||||
{
|
||||
@@ -242,23 +242,20 @@ outnet_udp_cb(struct comm_point* c, void* arg, int error,
|
||||
memcpy(&key.addr, &reply_info->addr, reply_info->addrlen);
|
||||
key.addrlen = reply_info->addrlen;
|
||||
verbose(VERB_ALGO, "Incoming reply id = %4.4x", key.id);
|
||||
if(verbosity >= VERB_ALGO) {
|
||||
log_addr("Incoming reply addr =", &reply_info->addr, reply_info->addrlen);
|
||||
}
|
||||
log_addr(VERB_ALGO, "Incoming reply addr =",
|
||||
&reply_info->addr, reply_info->addrlen);
|
||||
|
||||
/* find it, see if this thing is a valid query response */
|
||||
verbose(VERB_ALGO, "lookup size is %d entries", (int)outnet->pending->count);
|
||||
p = (struct pending*)rbtree_search(outnet->pending, &key);
|
||||
if(!p) {
|
||||
verbose(VERB_DETAIL, "received unwanted or unsolicited udp reply dropped.");
|
||||
if(verbosity >= VERB_ALGO)
|
||||
log_hex("dropped message",
|
||||
ldns_buffer_begin(c->buffer),
|
||||
ldns_buffer_limit(c->buffer));
|
||||
log_buf(VERB_ALGO, "dropped message", c->buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
verbose(VERB_ALGO, "received udp reply.");
|
||||
log_buf(VERB_ALGO, "udp message", c->buffer);
|
||||
if(p->c != c) {
|
||||
verbose(VERB_DETAIL, "received reply id,addr on wrong port. "
|
||||
"dropped.");
|
||||
@@ -268,6 +265,7 @@ outnet_udp_cb(struct comm_point* c, void* arg, int error,
|
||||
verbose(VERB_ALGO, "outnet handle udp reply");
|
||||
/* delete from tree first in case callback creates a retry */
|
||||
(void)rbtree_delete(outnet->pending, p->node.key);
|
||||
log_assert(fptr_whitelist_pending_udp(p->cb));
|
||||
(void)(*p->cb)(p->c, p->cb_arg, NETEVENT_NOERROR, reply_info);
|
||||
pending_delete(NULL, p);
|
||||
return 0;
|
||||
@@ -376,13 +374,13 @@ calc_num46(char** ifs, int num_ifs, int do_ip4, int do_ip6,
|
||||
|
||||
}
|
||||
|
||||
/** callback for udp timeout */
|
||||
static void
|
||||
void
|
||||
pending_udp_timer_cb(void *arg)
|
||||
{
|
||||
struct pending* p = (struct pending*)arg;
|
||||
/* it timed out */
|
||||
verbose(VERB_ALGO, "timeout udp");
|
||||
log_assert(fptr_whitelist_pending_udp(p->cb));
|
||||
(void)(*p->cb)(p->c, p->cb_arg, NETEVENT_TIMEOUT, NULL);
|
||||
pending_delete(p->outnet, p);
|
||||
}
|
||||
@@ -429,7 +427,7 @@ outside_network_create(struct comm_base *base, size_t bufsize,
|
||||
outnet->num_tcp = num_tcp;
|
||||
outnet->infra = infra;
|
||||
outnet->rnd = rnd;
|
||||
outnet->udp_second = 0;
|
||||
outnet->svcd_overhead = 0;
|
||||
#ifndef INET6
|
||||
do_ip6 = 0;
|
||||
#endif
|
||||
@@ -487,16 +485,14 @@ outside_network_create(struct comm_base *base, size_t bufsize,
|
||||
outnet->num_udp6 = done_6;
|
||||
outnet->num_udp4 = done_4;
|
||||
}
|
||||
if(outnet->num_udp4 + outnet->num_udp6 == 0) {
|
||||
log_err("Could not open any ports on outgoing interfaces");
|
||||
outside_network_delete(outnet);
|
||||
return NULL;
|
||||
}
|
||||
return outnet;
|
||||
}
|
||||
|
||||
void
|
||||
outside_network_set_secondary_buffer(struct outside_network* outnet,
|
||||
ldns_buffer* buf)
|
||||
{
|
||||
outnet->udp_second = buf;
|
||||
}
|
||||
|
||||
/** helper pending delete */
|
||||
static void
|
||||
pending_node_del(rbnode_t* node, void* arg)
|
||||
@@ -607,7 +603,6 @@ new_pending(struct outside_network* outnet, ldns_buffer* packet,
|
||||
return NULL;
|
||||
}
|
||||
/* set */
|
||||
/* id uses lousy random() TODO use better and entropy */
|
||||
pend->id = ((unsigned)ub_random(rnd)>>8) & 0xffff;
|
||||
LDNS_ID_SET(ldns_buffer_begin(packet), pend->id);
|
||||
memcpy(&pend->addr, addr, addrlen);
|
||||
@@ -648,7 +643,7 @@ select_port(struct outside_network* outnet, struct pending* pend,
|
||||
|
||||
log_assert(outnet && pend);
|
||||
/* first select ip4 or ip6. */
|
||||
if(addr_is_ip6(&pend->addr))
|
||||
if(addr_is_ip6(&pend->addr, pend->addrlen))
|
||||
nummax = (int)outnet->num_udp6;
|
||||
else nummax = (int)outnet->num_udp4;
|
||||
|
||||
@@ -659,7 +654,6 @@ select_port(struct outside_network* outnet, struct pending* pend,
|
||||
}
|
||||
|
||||
/* choose a random outgoing port and interface */
|
||||
/* TODO: entropy source. */
|
||||
precho = (double)ub_random(rnd) * (double)nummax /
|
||||
((double)RAND_MAX + 1.0);
|
||||
chosen = (int)precho;
|
||||
@@ -668,7 +662,7 @@ select_port(struct outside_network* outnet, struct pending* pend,
|
||||
if(chosen < 0) chosen = 0;
|
||||
if(chosen >= nummax) chosen = nummax-1;
|
||||
|
||||
if(addr_is_ip6(&pend->addr))
|
||||
if(addr_is_ip6(&pend->addr, pend->addrlen))
|
||||
pend->c = outnet->udp6_ports[chosen];
|
||||
else pend->c = outnet->udp4_ports[chosen];
|
||||
log_assert(pend->c);
|
||||
@@ -711,12 +705,13 @@ pending_udp_query(struct outside_network* outnet, ldns_buffer* packet,
|
||||
return pend;
|
||||
}
|
||||
|
||||
/** callback for outgoing TCP timer event */
|
||||
static void
|
||||
void
|
||||
outnet_tcptimer(void* arg)
|
||||
{
|
||||
struct waiting_tcp* w = (struct waiting_tcp*)arg;
|
||||
struct outside_network* outnet = w->outnet;
|
||||
comm_point_callback_t* cb;
|
||||
void* cb_arg;
|
||||
if(w->pkt) {
|
||||
/* it is on the waiting list */
|
||||
struct waiting_tcp* p=outnet->tcp_wait_first, *prev=NULL;
|
||||
@@ -738,8 +733,11 @@ outnet_tcptimer(void* arg)
|
||||
pend->next_free = outnet->tcp_free;
|
||||
outnet->tcp_free = pend;
|
||||
}
|
||||
(void)(*w->cb)(NULL, w->cb_arg, NETEVENT_TIMEOUT, NULL);
|
||||
cb = w->cb;
|
||||
cb_arg = w->cb_arg;
|
||||
waiting_tcp_delete(w);
|
||||
log_assert(fptr_whitelist_pending_tcp(cb));
|
||||
(void)(*cb)(NULL, cb_arg, NETEVENT_TIMEOUT, NULL);
|
||||
use_free_buffer(outnet);
|
||||
}
|
||||
|
||||
@@ -764,8 +762,7 @@ pending_tcp_query(struct outside_network* outnet, ldns_buffer* packet,
|
||||
return NULL;
|
||||
}
|
||||
w->pkt = NULL;
|
||||
w->pkt_len = ldns_buffer_limit(packet);
|
||||
/* id uses lousy random() TODO use better and entropy */
|
||||
w->pkt_len = 0;
|
||||
id = ((unsigned)ub_random(rnd)>>8) & 0xffff;
|
||||
LDNS_ID_SET(ldns_buffer_begin(packet), id);
|
||||
memcpy(&w->addr, addr, addrlen);
|
||||
@@ -778,13 +775,15 @@ pending_tcp_query(struct outside_network* outnet, ldns_buffer* packet,
|
||||
comm_timer_set(w->timer, &tv);
|
||||
if(pend) {
|
||||
/* we have a buffer available right now */
|
||||
if(!outnet_tcp_take_into_use(w, ldns_buffer_begin(packet))) {
|
||||
if(!outnet_tcp_take_into_use(w, ldns_buffer_begin(packet),
|
||||
ldns_buffer_limit(packet))) {
|
||||
waiting_tcp_delete(w);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
/* queue up */
|
||||
w->pkt = (uint8_t*)w + sizeof(struct waiting_tcp);
|
||||
w->pkt_len = ldns_buffer_limit(packet);
|
||||
memmove(w->pkt, ldns_buffer_begin(packet), w->pkt_len);
|
||||
w->next_waiting = NULL;
|
||||
if(outnet->tcp_wait_last)
|
||||
@@ -897,6 +896,7 @@ serviced_delete(struct serviced_query* sq)
|
||||
(struct pending_tcp*)p->next_waiting);
|
||||
} else {
|
||||
waiting_list_remove(sq->outnet, p);
|
||||
waiting_tcp_delete(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -921,8 +921,10 @@ serviced_encode(struct serviced_query* sq, ldns_buffer* buff, int with_edns)
|
||||
edns.edns_version = EDNS_ADVERTISED_VERSION;
|
||||
edns.udp_size = EDNS_ADVERTISED_SIZE;
|
||||
edns.bits = 0;
|
||||
if(sq->dnssec)
|
||||
if(sq->dnssec & EDNS_DO)
|
||||
edns.bits = EDNS_DO;
|
||||
if(sq->dnssec & BIT_CD)
|
||||
LDNS_CD_SET(ldns_buffer_begin(buff));
|
||||
attach_edns_record(buff, &edns);
|
||||
}
|
||||
}
|
||||
@@ -968,6 +970,8 @@ serviced_callbacks(struct serviced_query* sq, int error, struct comm_point* c,
|
||||
{
|
||||
struct service_callback* p = sq->cblist, *n;
|
||||
int dobackup = (sq->cblist && sq->cblist->next); /* >1 cb*/
|
||||
uint8_t *backup_p = NULL;
|
||||
size_t backlen = 0;
|
||||
rbnode_t* rem;
|
||||
/* remove from tree, and schedule for deletion, so that callbacks
|
||||
* can safely deregister themselves and even create new serviced
|
||||
@@ -981,31 +985,48 @@ serviced_callbacks(struct serviced_query* sq, int error, struct comm_point* c,
|
||||
* may send outgoing queries that overwrite the buffer.
|
||||
* use secondary buffer to store the query.
|
||||
* This is a data copy, but faster than packet to server */
|
||||
ldns_buffer_copy(sq->outnet->udp_second, c->buffer);
|
||||
backlen = ldns_buffer_limit(c->buffer);
|
||||
backup_p = memdup(ldns_buffer_begin(c->buffer), backlen);
|
||||
if(!backup_p) {
|
||||
log_err("malloc failure in serviced query callbacks");
|
||||
error = NETEVENT_CLOSED;
|
||||
c = NULL;
|
||||
}
|
||||
sq->outnet->svcd_overhead = backlen;
|
||||
}
|
||||
while(p) {
|
||||
n = p->next;
|
||||
if(dobackup && c) {
|
||||
ldns_buffer_copy(c->buffer, sq->outnet->udp_second);
|
||||
ldns_buffer_clear(c->buffer);
|
||||
ldns_buffer_write(c->buffer, backup_p, backlen);
|
||||
ldns_buffer_flip(c->buffer);
|
||||
}
|
||||
log_assert(fptr_whitelist_serviced_query(p->cb));
|
||||
(void)(*p->cb)(c, p->cb_arg, error, rep);
|
||||
p = n;
|
||||
}
|
||||
if(backup_p) {
|
||||
free(backup_p);
|
||||
sq->outnet->svcd_overhead = 0;
|
||||
}
|
||||
verbose(VERB_ALGO, "svcd callbacks end");
|
||||
log_assert(sq->cblist == NULL);
|
||||
serviced_delete(sq);
|
||||
}
|
||||
|
||||
/** TCP reply or error callback for serviced queries */
|
||||
static int
|
||||
int
|
||||
serviced_tcp_callback(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* rep)
|
||||
{
|
||||
struct serviced_query* sq = (struct serviced_query*)arg;
|
||||
struct comm_reply r2;
|
||||
sq->pending = NULL; /* removed after this callback */
|
||||
if(error != NETEVENT_NOERROR && verbosity >= VERB_DETAIL)
|
||||
log_addr("tcp error for address", &sq->addr, sq->addrlen);
|
||||
if(error != NETEVENT_NOERROR)
|
||||
log_addr(VERB_DETAIL, "tcp error for address",
|
||||
&sq->addr, sq->addrlen);
|
||||
if(error==NETEVENT_NOERROR)
|
||||
infra_update_tcp_works(sq->outnet->infra, &sq->addr,
|
||||
sq->addrlen);
|
||||
if(error==NETEVENT_NOERROR && LDNS_RCODE_WIRE(ldns_buffer_begin(
|
||||
c->buffer)) == LDNS_RCODE_FORMERR &&
|
||||
sq->status == serviced_query_TCP_EDNS) {
|
||||
@@ -1044,13 +1065,14 @@ serviced_tcp_initiate(struct outside_network* outnet,
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
serviced_udp_callback(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* rep)
|
||||
{
|
||||
struct serviced_query* sq = (struct serviced_query*)arg;
|
||||
struct outside_network* outnet = sq->outnet;
|
||||
struct timeval now;
|
||||
int fallback_tcp = 0;
|
||||
if(gettimeofday(&now, NULL) < 0) {
|
||||
log_err("gettimeofday: %s", strerror(errno));
|
||||
/* this option does not need current time */
|
||||
@@ -1058,9 +1080,10 @@ serviced_udp_callback(struct comm_point* c, void* arg, int error,
|
||||
}
|
||||
sq->pending = NULL; /* removed after callback */
|
||||
if(error == NETEVENT_TIMEOUT) {
|
||||
int rto = 0;
|
||||
sq->retry++;
|
||||
if(!infra_rtt_update(outnet->infra, &sq->addr, sq->addrlen,
|
||||
-1, (time_t)now.tv_sec))
|
||||
if(!(rto=infra_rtt_update(outnet->infra, &sq->addr, sq->addrlen,
|
||||
-1, (time_t)now.tv_sec)))
|
||||
log_err("out of memory in UDP exponential backoff");
|
||||
if(sq->retry < OUTBOUND_UDP_RETRY) {
|
||||
log_name_addr(VERB_ALGO, "retry query", sq->qbuf+10,
|
||||
@@ -1070,8 +1093,13 @@ serviced_udp_callback(struct comm_point* c, void* arg, int error,
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
error = NETEVENT_TIMEOUT;
|
||||
/* UDP does not work, fallback to TCP below */
|
||||
if(rto >= RTT_MAX_TIMEOUT) {
|
||||
fallback_tcp = 1;
|
||||
/* UDP does not work, fallback to TCP below */
|
||||
} else {
|
||||
serviced_callbacks(sq, NETEVENT_TIMEOUT, c, rep);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(error == NETEVENT_NOERROR && sq->status == serviced_query_UDP_EDNS
|
||||
&& LDNS_RCODE_WIRE(ldns_buffer_begin(c->buffer))
|
||||
@@ -1088,8 +1116,8 @@ serviced_udp_callback(struct comm_point* c, void* arg, int error,
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if(error != NETEVENT_NOERROR ||
|
||||
LDNS_TC_WIRE(ldns_buffer_begin(c->buffer))) {
|
||||
if(LDNS_TC_WIRE(ldns_buffer_begin(c->buffer)) ||
|
||||
(error != NETEVENT_NOERROR && fallback_tcp) ) {
|
||||
/* fallback to TCP */
|
||||
/* this discards partial UDP contents */
|
||||
if(sq->status == serviced_query_UDP_EDNS)
|
||||
@@ -1106,6 +1134,7 @@ serviced_udp_callback(struct comm_point* c, void* arg, int error,
|
||||
int roundtime = (now.tv_sec - sq->last_sent_time.tv_sec)*1000
|
||||
+ ((int)now.tv_usec - (int)sq->last_sent_time.tv_usec)/1000;
|
||||
verbose(VERB_ALGO, "measured roundtrip at %d msec", roundtime);
|
||||
log_assert(roundtime >= 0);
|
||||
if(!infra_rtt_update(outnet->infra, &sq->addr, sq->addrlen,
|
||||
roundtime, (time_t)now.tv_sec))
|
||||
log_err("out of memory noting rtt.");
|
||||
@@ -1239,8 +1268,10 @@ size_t outnet_get_mem(struct outside_network* outnet)
|
||||
for(w=outnet->tcp_wait_first; w; w = w->next_waiting)
|
||||
s += waiting_tcp_get_mem(w);
|
||||
s += sizeof(*outnet->pending);
|
||||
s += sizeof(struct pending) * outnet->pending->count;
|
||||
s += (sizeof(struct pending) + comm_timer_get_mem(NULL)) *
|
||||
outnet->pending->count;
|
||||
s += sizeof(*outnet->serviced);
|
||||
s += outnet->svcd_overhead;
|
||||
RBTREE_FOR(sq, struct serviced_query*, outnet->serviced) {
|
||||
s += sizeof(*sq) + sq->qbuflen;
|
||||
for(sb = sq->cblist; sb; sb = sb->next)
|
||||
@@ -1248,3 +1279,28 @@ size_t outnet_get_mem(struct outside_network* outnet)
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
size_t
|
||||
serviced_get_mem(struct serviced_query* sq)
|
||||
{
|
||||
struct service_callback* sb;
|
||||
size_t s;
|
||||
s = sizeof(*sq) + sq->qbuflen;
|
||||
for(sb = sq->cblist; sb; sb = sb->next)
|
||||
s += sizeof(*sb);
|
||||
if(sq->status == serviced_query_UDP_EDNS ||
|
||||
sq->status == serviced_query_UDP) {
|
||||
s += sizeof(struct pending);
|
||||
s += comm_timer_get_mem(NULL);
|
||||
} else {
|
||||
/* does not have size of the pkt pointer */
|
||||
/* always has a timer except on malloc failures */
|
||||
|
||||
/* these sizes are part of the main outside network mem */
|
||||
/*
|
||||
s += sizeof(struct waiting_tcp);
|
||||
s += comm_timer_get_mem(NULL);
|
||||
*/
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
+43
-17
@@ -64,12 +64,9 @@ struct outside_network {
|
||||
/** buffer shared by UDP connections, since there is only one
|
||||
datagram at any time. */
|
||||
ldns_buffer* udp_buff;
|
||||
|
||||
/** buffer for storage. (buffer for incoming connections, since
|
||||
* either an event to outside or incoming happens, but not both
|
||||
* This buffer is used during callbacks, so that the datagram
|
||||
* that just arrived does not collide with new datagrams sent out. */
|
||||
ldns_buffer* udp_second;
|
||||
/** serviced_callbacks malloc overhead when processing multiple
|
||||
* identical serviced queries to the same server. */
|
||||
size_t svcd_overhead;
|
||||
|
||||
/**
|
||||
* Array of udp comm point* that are used to listen to pending events.
|
||||
@@ -210,7 +207,7 @@ struct serviced_query {
|
||||
uint8_t* qbuf;
|
||||
/** length of qbuf. */
|
||||
size_t qbuflen;
|
||||
/** If an EDNS section is included, the DO bit will be turned on. */
|
||||
/** If an EDNS section is included, the DO/CD bit will be turned on. */
|
||||
int dnssec;
|
||||
/** where to send it */
|
||||
struct sockaddr_storage addr;
|
||||
@@ -271,16 +268,6 @@ struct outside_network* outside_network_create(struct comm_base* base,
|
||||
*/
|
||||
void outside_network_delete(struct outside_network* outnet);
|
||||
|
||||
/**
|
||||
* Set secondary UDP buffer. Make sure it is not used during outside network
|
||||
* callbacks. Such as the incoming network UDP buffer. Caller responsible
|
||||
* for deletion.
|
||||
* @param outnet: outside network.
|
||||
* @param buf: buffer to use as secondary buffer.
|
||||
*/
|
||||
void outside_network_set_secondary_buffer(struct outside_network* outnet,
|
||||
ldns_buffer* buf);
|
||||
|
||||
/**
|
||||
* Send UDP query, create pending answer.
|
||||
* Changes the ID for the query to be random and unique for that destination.
|
||||
@@ -337,6 +324,8 @@ void pending_delete(struct outside_network* outnet, struct pending* p);
|
||||
* @param qclass: query class. (host format)
|
||||
* @param flags: flags u16 (host format), includes opcode, CD bit.
|
||||
* @param dnssec: if set, DO bit is set in EDNS queries.
|
||||
* If the value includes BIT_CD, CD bit is set when in EDNS queries.
|
||||
* If the value includes BIT_DO, DO bit is set when in EDNS queries.
|
||||
* @param callback: callback function.
|
||||
* @param callback_arg: user argument to callback function.
|
||||
* @param addr: to which server to send the query.
|
||||
@@ -371,4 +360,41 @@ void outnet_serviced_query_stop(struct serviced_query* sq, void* cb_arg);
|
||||
*/
|
||||
size_t outnet_get_mem(struct outside_network* outnet);
|
||||
|
||||
/**
|
||||
* Get memory size in use by serviced query while it is servicing callbacks.
|
||||
* This takes into account the pre-deleted status of it; it will be deleted
|
||||
* when the callbacks are done.
|
||||
* @param sq: serviced query.
|
||||
* @return size in bytes.
|
||||
*/
|
||||
size_t serviced_get_mem(struct serviced_query* sq);
|
||||
|
||||
/** callback for incoming udp answers from the network */
|
||||
int outnet_udp_cb(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply *reply_info);
|
||||
|
||||
/** callback for pending tcp connections */
|
||||
int outnet_tcp_cb(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply *reply_info);
|
||||
|
||||
/** callback for udp timeout */
|
||||
void pending_udp_timer_cb(void *arg);
|
||||
|
||||
/** callback for outgoing TCP timer event */
|
||||
void outnet_tcptimer(void* arg);
|
||||
|
||||
/** callback for serviced query UDP answers */
|
||||
int serviced_udp_callback(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* rep);
|
||||
|
||||
/** TCP reply or error callback for serviced queries */
|
||||
int serviced_tcp_callback(struct comm_point* c, void* arg, int error,
|
||||
struct comm_reply* rep);
|
||||
|
||||
/** compare function of pending rbtree */
|
||||
int pending_cmp(const void* key1, const void* key2);
|
||||
|
||||
/** compare function of serviced query rbtree */
|
||||
int serviced_cmp(const void* key1, const void* key2);
|
||||
|
||||
#endif /* OUTSIDE_NETWORK_H */
|
||||
|
||||
+36
-2
@@ -63,7 +63,7 @@ static ub_thread_key_t thr_debug_key;
|
||||
/** the list of threads, so all threads can be examined. NULL if unused. */
|
||||
static struct thr_check* thread_infos[THRDEBUG_MAX_THREADS];
|
||||
/** do we check locking order */
|
||||
int check_locking_order = 0;
|
||||
int check_locking_order = 1;
|
||||
/** the pid of this runset, reasonably unique. */
|
||||
static pid_t check_lock_pid;
|
||||
|
||||
@@ -205,6 +205,23 @@ prot_store(struct checked_lock* lock)
|
||||
}
|
||||
}
|
||||
|
||||
/** get memory held by lock */
|
||||
size_t
|
||||
lock_get_mem(void* pp)
|
||||
{
|
||||
size_t s;
|
||||
struct checked_lock* lock = *(struct checked_lock**)pp;
|
||||
struct protected_area* p;
|
||||
s = sizeof(struct checked_lock);
|
||||
acquire_locklock(lock, __func__, __FILE__, __LINE__);
|
||||
for(p = lock->prot; p; p = p->next) {
|
||||
s += sizeof(struct protected_area);
|
||||
s += p->size;
|
||||
}
|
||||
LOCKRET(pthread_mutex_unlock(&lock->lock));
|
||||
return s;
|
||||
}
|
||||
|
||||
/** write lock trace info to file, while you hold those locks */
|
||||
static void
|
||||
ordercheck_locklock(struct thr_check* thr, struct checked_lock* lock)
|
||||
@@ -340,7 +357,7 @@ checklock_destroy(enum check_lock_type type, struct checked_lock** lock,
|
||||
e->create_func, e->create_file, e->create_line,
|
||||
(unsigned int)e->contention_count,
|
||||
(unsigned int)e->history_count,
|
||||
100*e->contention_count/e->history_count);
|
||||
(int)(100*e->contention_count/e->history_count));
|
||||
}
|
||||
|
||||
/* delete it */
|
||||
@@ -813,3 +830,20 @@ checklock_thrjoin(pthread_t thread)
|
||||
}
|
||||
|
||||
#endif /* USE_THREAD_DEBUG */
|
||||
|
||||
int order_lock_cmp(const void* e1, const void* e2)
|
||||
{
|
||||
struct order_id* o1 = (struct order_id*)e1;
|
||||
struct order_id* o2 = (struct order_id*)e2;
|
||||
if(o1->thr < o2->thr) return -1;
|
||||
if(o1->thr > o2->thr) return 1;
|
||||
if(o1->instance < o2->instance) return -1;
|
||||
if(o1->instance > o2->instance) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
codeline_cmp(const void* a, const void* b)
|
||||
{
|
||||
return strcmp((const char*)a, (const char*)b);
|
||||
}
|
||||
|
||||
@@ -196,6 +196,13 @@ void lock_protect(void* lock, void* area, size_t size);
|
||||
*/
|
||||
void lock_unprotect(void* lock, void* area);
|
||||
|
||||
/**
|
||||
* Get memory associated with a checked lock
|
||||
* @param lock: the checked lock, any type. (struct checked_lock**).
|
||||
* @return: in bytes, including protected areas.
|
||||
*/
|
||||
size_t lock_get_mem(void* lock);
|
||||
|
||||
/**
|
||||
* Initialise checklock. Sets up internal debug structures.
|
||||
*/
|
||||
@@ -334,4 +341,16 @@ typedef pthread_key_t ub_thread_key_t;
|
||||
|
||||
#endif /* USE_THREAD_DEBUG */
|
||||
|
||||
/** keep track of lock id in lock-verify application */
|
||||
struct order_id {
|
||||
/** the thread id that created it */
|
||||
int thr;
|
||||
/** the instance number of creation */
|
||||
int instance;
|
||||
};
|
||||
/** compare two order_ids */
|
||||
int order_lock_cmp(const void* e1, const void* e2);
|
||||
/** compare two codeline structs for rbtree */
|
||||
int codeline_cmp(const void* a, const void* b);
|
||||
|
||||
#endif /* TESTCODE_CHECK_LOCKS_H */
|
||||
|
||||
+21
-1
@@ -2,8 +2,12 @@
|
||||
|
||||
NEED_SPLINT='00-lint.tpkg'
|
||||
NEED_DOXYGEN='01-doc.tpkg'
|
||||
NEED_LDNS_TESTNS='fwd_no_edns.tpkg fwd_tcp_tc.tpkg fwd_tcp.tpkg fwd_three_service.tpkg fwd_three.tpkg fwd_ttlexpire.tpkg fwd_udp.tpkg fwd_tcp_tc6.tpkg fwd_compress_c00c.tpkg'
|
||||
NEED_XXD='fwd_compress_c00c.tpkg'
|
||||
NEED_NC='fwd_compress_c00c.tpkg'
|
||||
|
||||
cd testdata;
|
||||
sh ../testcode/mini_tpkg.sh clean
|
||||
for test in `ls *.tpkg`; do
|
||||
SKIP=0
|
||||
if echo $NEED_SPLINT | grep $test >/dev/null; then
|
||||
@@ -16,10 +20,26 @@ for test in `ls *.tpkg`; do
|
||||
SKIP=1;
|
||||
fi
|
||||
fi
|
||||
if echo $NEED_LDNS_TESTNS | grep $test >/dev/null; then
|
||||
if test ! -x "`which ldns-testns`"; then
|
||||
SKIP=1;
|
||||
fi
|
||||
fi
|
||||
if echo $NEED_XXD | grep $test >/dev/null; then
|
||||
if test ! -x "`which xxd`"; then
|
||||
SKIP=1;
|
||||
fi
|
||||
fi
|
||||
if echo $NEED_NC | grep $test >/dev/null; then
|
||||
if test ! -x "`which nc`"; then
|
||||
SKIP=1;
|
||||
fi
|
||||
fi
|
||||
if test $SKIP -eq 0; then
|
||||
echo $test
|
||||
tpkg -a ../.. exe $test
|
||||
sh ../testcode/mini_tpkg.sh -a ../.. exe $test
|
||||
else
|
||||
echo "skip $test"
|
||||
fi
|
||||
done
|
||||
sh ../testcode/mini_tpkg.sh report
|
||||
|
||||
+127
-16
@@ -56,6 +56,7 @@
|
||||
#include "testcode/replay.h"
|
||||
#include "testcode/ldns-testpkts.h"
|
||||
#include "util/log.h"
|
||||
#include <signal.h>
|
||||
|
||||
/** Global variable: the scenario. Saved here for when event_init is done. */
|
||||
static struct replay_scenario* saved_scenario = NULL;
|
||||
@@ -178,7 +179,8 @@ pending_find_match(struct replay_runtime* runtime, struct entry** entry,
|
||||
"with entry line %d", timenow,
|
||||
p->start_step, p->end_step, (*entry)->lineno);
|
||||
if(p->addrlen != 0)
|
||||
log_addr("matched ip", &p->addr, p->addrlen);
|
||||
log_addr(0, "matched ip", &p->addr, p->addrlen);
|
||||
log_pkt("matched pkt: ", (*entry)->reply_list->reply);
|
||||
return 1;
|
||||
}
|
||||
p = p->next_range;
|
||||
@@ -353,9 +355,12 @@ fake_front_query(struct replay_runtime* runtime, struct replay_moment *todo)
|
||||
repinfo.c->fd = -1;
|
||||
repinfo.c->ev = (struct internal_event*)runtime;
|
||||
repinfo.c->buffer = ldns_buffer_new(runtime->bufsize);
|
||||
repinfo.c->type = comm_udp;
|
||||
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);
|
||||
log_info("testbound: incoming QUERY");
|
||||
log_pkt("query pkt", todo->match->reply_list->reply);
|
||||
/* call the callback for incoming queries */
|
||||
if((*runtime->callback_query)(repinfo.c, runtime->cb_arg,
|
||||
NETEVENT_NOERROR, &repinfo)) {
|
||||
@@ -376,6 +381,9 @@ fake_pending_callback(struct replay_runtime* runtime,
|
||||
struct fake_pending* p = runtime->pending_list;
|
||||
struct comm_reply repinfo;
|
||||
struct comm_point c;
|
||||
void* cb_arg = p->cb_arg;
|
||||
comm_point_callback_t* cb = p->callback;
|
||||
|
||||
memset(&c, 0, sizeof(c));
|
||||
if(!p) fatal_exit("No pending queries.");
|
||||
log_assert(todo->qname == NULL); /* or find that one */
|
||||
@@ -389,12 +397,13 @@ fake_pending_callback(struct replay_runtime* runtime,
|
||||
repinfo.c = &c;
|
||||
repinfo.addrlen = p->addrlen;
|
||||
memcpy(&repinfo.addr, &p->addr, p->addrlen);
|
||||
if((*p->callback)(&c, p->cb_arg, error, &repinfo)) {
|
||||
if(!p->serviced)
|
||||
pending_list_delete(runtime, p);
|
||||
if((*cb)(&c, cb_arg, error, &repinfo)) {
|
||||
fatal_exit("unexpected: pending callback returned 1");
|
||||
}
|
||||
/* delete the pending item. */
|
||||
ldns_buffer_free(c.buffer);
|
||||
pending_list_delete(runtime, p);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -514,13 +523,15 @@ run_scenario(struct replay_runtime* runtime)
|
||||
fatal_exit("testbound: there are unmatched answers.");
|
||||
}
|
||||
log_info("testbound: exiting fake runloop.");
|
||||
runtime->exit_cleanly = 1;
|
||||
}
|
||||
|
||||
/*********** Dummy routines ***********/
|
||||
|
||||
struct listen_dnsport*
|
||||
listen_create(struct comm_base* base, struct listen_port* ATTR_UNUSED(ports),
|
||||
size_t bufsize, comm_point_callback_t* cb, void* cb_arg)
|
||||
size_t bufsize, int ATTR_UNUSED(tcp_accept_count),
|
||||
comm_point_callback_t* cb, void* cb_arg)
|
||||
{
|
||||
struct replay_runtime* runtime = (struct replay_runtime*)base;
|
||||
struct listen_dnsport* l= calloc(1, sizeof(struct listen_dnsport));
|
||||
@@ -586,13 +597,19 @@ comm_base_dispatch(struct comm_base* b)
|
||||
{
|
||||
struct replay_runtime* runtime = (struct replay_runtime*)b;
|
||||
run_scenario(runtime);
|
||||
if(runtime->sig_cb)
|
||||
(*runtime->sig_cb)(SIGTERM, runtime->sig_cb_arg);
|
||||
else exit(0); /* OK exit when LIBEVENT_SIGNAL_PROBLEM exists */
|
||||
}
|
||||
|
||||
void
|
||||
comm_base_exit(struct comm_base* ATTR_UNUSED(b))
|
||||
comm_base_exit(struct comm_base* b)
|
||||
{
|
||||
/* some sort of failure */
|
||||
fatal_exit("testbound: comm_base_exit was called.");
|
||||
struct replay_runtime* runtime = (struct replay_runtime*)b;
|
||||
if(!runtime->exit_cleanly) {
|
||||
/* some sort of failure */
|
||||
fatal_exit("testbound: comm_base_exit was called.");
|
||||
}
|
||||
}
|
||||
|
||||
struct comm_signal*
|
||||
@@ -692,13 +709,6 @@ outside_network_delete(struct outside_network* outnet)
|
||||
free(outnet);
|
||||
}
|
||||
|
||||
void
|
||||
outside_network_set_secondary_buffer(struct outside_network*
|
||||
ATTR_UNUSED(outnet), ldns_buffer* ATTR_UNUSED(buf))
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
|
||||
struct pending*
|
||||
pending_udp_query(struct outside_network* outnet, ldns_buffer* packet,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen, int timeout,
|
||||
@@ -818,6 +828,11 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
|
||||
ldns_status status;
|
||||
(void)arg_compare;
|
||||
log_assert(pend);
|
||||
log_nametypeclass(VERB_OPS, "pending serviced query",
|
||||
qname, qtype, qclass);
|
||||
verbose(VERB_OPS, "pending serviced query flags%s%s%s%s",
|
||||
(flags&BIT_RD)?" RD":"", (flags&BIT_CD)?" CD":"",
|
||||
(flags&~(BIT_RD|BIT_CD))?" MORE":"", (dnssec)?" DO":"");
|
||||
|
||||
/* create packet with EDNS */
|
||||
pend->buffer = ldns_buffer_new(512);
|
||||
@@ -859,7 +874,7 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet,
|
||||
ldns_get_errorstr_by_id(status));
|
||||
fatal_exit("internal error");
|
||||
}
|
||||
log_pkt("pending serviced query: ", pend->pkt);
|
||||
/*log_pkt("pending serviced query: ", pend->pkt);*/
|
||||
|
||||
/* see if it matches the current moment */
|
||||
if(runtime->now && runtime->now->evt_type == repevt_back_query &&
|
||||
@@ -952,4 +967,100 @@ size_t comm_point_get_mem(struct comm_point* ATTR_UNUSED(c))
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t serviced_get_mem(struct serviced_query* ATTR_UNUSED(c))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* fake for fptr wlist */
|
||||
int outnet_udp_cb(struct comm_point* ATTR_UNUSED(c),
|
||||
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
||||
struct comm_reply *ATTR_UNUSED(reply_info))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int outnet_tcp_cb(struct comm_point* ATTR_UNUSED(c),
|
||||
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
||||
struct comm_reply *ATTR_UNUSED(reply_info))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pending_udp_timer_cb(void *ATTR_UNUSED(arg))
|
||||
{
|
||||
log_assert(0);
|
||||
}
|
||||
|
||||
void outnet_tcptimer(void* ATTR_UNUSED(arg))
|
||||
{
|
||||
log_assert(0);
|
||||
}
|
||||
|
||||
void comm_point_udp_callback(int ATTR_UNUSED(fd), short ATTR_UNUSED(event),
|
||||
void* ATTR_UNUSED(arg))
|
||||
{
|
||||
log_assert(0);
|
||||
}
|
||||
|
||||
void comm_point_tcp_accept_callback(int ATTR_UNUSED(fd),
|
||||
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
||||
{
|
||||
log_assert(0);
|
||||
}
|
||||
|
||||
void comm_point_tcp_handle_callback(int ATTR_UNUSED(fd),
|
||||
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
||||
{
|
||||
log_assert(0);
|
||||
}
|
||||
|
||||
void comm_timer_callback(int ATTR_UNUSED(fd),
|
||||
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
||||
{
|
||||
log_assert(0);
|
||||
}
|
||||
|
||||
void comm_signal_callback(int ATTR_UNUSED(fd),
|
||||
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
||||
{
|
||||
log_assert(0);
|
||||
}
|
||||
|
||||
void comm_point_local_handle_callback(int ATTR_UNUSED(fd),
|
||||
short ATTR_UNUSED(event), void* ATTR_UNUSED(arg))
|
||||
{
|
||||
log_assert(0);
|
||||
}
|
||||
|
||||
int serviced_udp_callback(struct comm_point* ATTR_UNUSED(c),
|
||||
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
||||
struct comm_reply* ATTR_UNUSED(reply_info))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int serviced_tcp_callback(struct comm_point* ATTR_UNUSED(c),
|
||||
void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
|
||||
struct comm_reply* ATTR_UNUSED(reply_info))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pending_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int serviced_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
|
||||
{
|
||||
log_assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********** End of Dummy routines ***********/
|
||||
|
||||
@@ -68,7 +68,7 @@ static bool str_keyword(const char** str, const char* keyword)
|
||||
if(strncmp(*str, keyword, len) != 0)
|
||||
return false;
|
||||
*str += len;
|
||||
while(isspace(**str))
|
||||
while(isspace((int)**str))
|
||||
(*str)++;
|
||||
return true;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ static void matchline(const char* line, struct entry* e)
|
||||
error("expected = or : in MATCH: %s", line);
|
||||
parse++;
|
||||
e->ixfr_soa_serial = (uint32_t)strtol(parse, (char**)&parse, 10);
|
||||
while(isspace(*parse))
|
||||
while(isspace((int)*parse))
|
||||
parse++;
|
||||
} else {
|
||||
error("could not parse MATCH: '%s'", parse);
|
||||
@@ -184,6 +184,9 @@ static void replyline(const char* line, ldns_pkt *reply)
|
||||
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);
|
||||
}
|
||||
@@ -200,13 +203,15 @@ static void adjustline(const char* line, struct entry* e,
|
||||
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(*parse))
|
||||
while(isspace((int)*parse))
|
||||
parse++;
|
||||
} else if(str_keyword(&parse, "packet_sleep=")) {
|
||||
pkt->packet_sleep = (unsigned int) strtol(parse, (char**)&parse, 10);
|
||||
while(isspace(*parse))
|
||||
while(isspace((int)*parse))
|
||||
parse++;
|
||||
} else {
|
||||
error("could not parse ADJUST: '%s'", parse);
|
||||
@@ -230,6 +235,7 @@ static struct entry* new_entry()
|
||||
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;
|
||||
@@ -385,7 +391,7 @@ get_origin(const char* name, int lineno, ldns_rdf** origin, char* parse)
|
||||
*origin = NULL;
|
||||
|
||||
end=parse;
|
||||
while(!isspace(*end) && !isendline(*end))
|
||||
while(!isspace((int)*end) && !isendline(*end))
|
||||
end++;
|
||||
store = *end;
|
||||
*end = 0;
|
||||
@@ -415,7 +421,7 @@ read_entry(FILE* in, const char* name, int *lineno, uint32_t* default_ttl,
|
||||
parse = line;
|
||||
(*lineno) ++;
|
||||
|
||||
while(isspace(*parse))
|
||||
while(isspace((int)*parse))
|
||||
parse++;
|
||||
/* test for keywords */
|
||||
if(isendline(*parse))
|
||||
@@ -528,6 +534,8 @@ read_datafile(const char* name)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -692,6 +700,12 @@ 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);
|
||||
sleep(match->sleeptime);
|
||||
|
||||
@@ -54,11 +54,13 @@
|
||||
(opcode) QUERY IQUERY STATUS NOTIFY UPDATE
|
||||
(rcode) NOERROR FORMERR SERVFAIL NXDOMAIN NOTIMPL YXDOMAIN
|
||||
YXRRSET NXRRSET NOTAUTH NOTZONE
|
||||
(flags) QR AA TC RD CD RA AD
|
||||
(flags) QR AA TC RD CD RA AD DO
|
||||
REPLY ...
|
||||
; any additional actions to do.
|
||||
; 'copy_id' copies the ID from the query to the answer.
|
||||
ADJUST copy_id
|
||||
; 'copy_query' copies the query name, type and class to the answer.
|
||||
ADJUST copy_query
|
||||
; 'sleep=10' sleeps for 10 seconds before giving the answer (TCP is open)
|
||||
ADJUST [sleep=<num>] ; sleep before giving any reply
|
||||
ADJUST [packet_sleep=<num>] ; sleep before this packet in sequence
|
||||
@@ -174,6 +176,8 @@ struct entry {
|
||||
/** how to adjust the reply packet */
|
||||
/** copy over the ID from the query into the answer */
|
||||
bool copy_id;
|
||||
/** copy the query nametypeclass from query into the answer */
|
||||
bool copy_query;
|
||||
/** in seconds */
|
||||
unsigned int sleeptime;
|
||||
|
||||
|
||||
+3
-21
@@ -46,18 +46,12 @@
|
||||
#include "config.h"
|
||||
#include "util/log.h"
|
||||
#include "util/rbtree.h"
|
||||
#include "util/locks.h"
|
||||
#include "testcode/checklocks.h"
|
||||
|
||||
/* --- data structures --- */
|
||||
struct lock_ref;
|
||||
|
||||
/** key for lock lookup */
|
||||
struct order_id {
|
||||
/** the thread id that created it */
|
||||
int thr;
|
||||
/** the instance number of creation */
|
||||
int instance;
|
||||
};
|
||||
|
||||
/** a lock */
|
||||
struct order_lock {
|
||||
/** rbnode in all tree */
|
||||
@@ -103,18 +97,6 @@ usage()
|
||||
printf("lock_verify <trace files>\n");
|
||||
}
|
||||
|
||||
/** compare two order_ids */
|
||||
int order_lock_cmp(const void* e1, const void* e2)
|
||||
{
|
||||
struct order_id* o1 = (struct order_id*)e1;
|
||||
struct order_id* o2 = (struct order_id*)e2;
|
||||
if(o1->thr < o2->thr) return -1;
|
||||
if(o1->thr > o2->thr) return 1;
|
||||
if(o1->instance < o2->instance) return -1;
|
||||
if(o1->instance > o2->instance) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** read header entry.
|
||||
* @param in: file to read header of.
|
||||
* @return: False if it does not belong to the rest. */
|
||||
@@ -403,7 +385,7 @@ main(int argc, char* argv[])
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
log_init(NULL);
|
||||
log_init(NULL, 0, NULL);
|
||||
log_ident_set("lock-verify");
|
||||
/* init */
|
||||
all_locks = rbtree_create(order_lock_cmp);
|
||||
|
||||
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
* testcode/memstats.c - debug tool to show memory allocation statistics.
|
||||
*
|
||||
* Copyright (c) 2007, 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 reads a log file and prints the memory allocation summed
|
||||
* up.
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "util/log.h"
|
||||
#include "util/rbtree.h"
|
||||
#include "util/locks.h"
|
||||
#include "testcode/checklocks.h"
|
||||
#include <sys/stat.h>
|
||||
|
||||
/**
|
||||
* The allocation statistics block
|
||||
*/
|
||||
struct codeline {
|
||||
/** rbtree node */
|
||||
rbnode_t node;
|
||||
/** the name of the file:linenumber */
|
||||
char* codeline;
|
||||
/** the name of the function */
|
||||
char* func;
|
||||
/** number of bytes allocated */
|
||||
uint64_t alloc;
|
||||
/** number of bytes freed */
|
||||
uint64_t free;
|
||||
};
|
||||
|
||||
/**
|
||||
* Other allocation stats
|
||||
*/
|
||||
struct alloc_misc {
|
||||
/** number of region allocs */
|
||||
uint64_t region_alloc;
|
||||
};
|
||||
|
||||
/** print usage and exit */
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
printf("usage: memstats <logfile>\n");
|
||||
printf("statistics are printed on stdout.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/** match logfile line to see if it needs accounting processing */
|
||||
static int
|
||||
match(char* line)
|
||||
{
|
||||
/* f.e.:
|
||||
* [1187340064] unbound[24604:0] info: ul/rb.c:81 r_create malloc(12)
|
||||
* 0123456789 123456789 123456789 123456789
|
||||
*/
|
||||
if(strlen(line) < 36) /* up to 'info: ' */
|
||||
return 0;
|
||||
if(strncmp(line+30, "info: ", 6) != 0)
|
||||
return 0;
|
||||
if(strncmp(line+36, "stat ", 5) == 0)
|
||||
return 0; /* skip the hex dumps */
|
||||
if(strstr(line+36, "malloc("))
|
||||
return 1;
|
||||
else if(strstr(line+36, "calloc("))
|
||||
return 1;
|
||||
/* skip reallocs */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** read up the region stats */
|
||||
static void
|
||||
read_region_stat(char* line, struct alloc_misc* misc)
|
||||
{
|
||||
long num = 0;
|
||||
if(sscanf(line+50, "%ld", &num) != 1) {
|
||||
printf("%s\n%s\n", line, line+50);
|
||||
fatal_exit("unhandled region");
|
||||
}
|
||||
misc->region_alloc += num;
|
||||
}
|
||||
|
||||
/** find or alloc codeline in tree */
|
||||
static struct codeline*
|
||||
get_codeline(rbtree_t* tree, char* key, char* func)
|
||||
{
|
||||
struct codeline* cl = (struct codeline*)rbtree_search(tree, key);
|
||||
if(!cl) {
|
||||
cl = calloc(1, sizeof(*cl));
|
||||
if(!cl) return 0;
|
||||
cl->codeline = strdup(key);
|
||||
if(!cl->codeline) return 0;
|
||||
cl->func = strdup(func);
|
||||
if(!cl->func) return 0;
|
||||
cl->alloc = 0;
|
||||
cl->node.key = cl->codeline;
|
||||
(void)rbtree_insert(tree, &cl->node);
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
|
||||
/** read up the malloc stats */
|
||||
static void
|
||||
read_malloc_stat(char* line, rbtree_t* tree)
|
||||
{
|
||||
char codeline[10240];
|
||||
char name[10240];
|
||||
int skip = 0;
|
||||
long num = 0;
|
||||
struct codeline* cl = 0;
|
||||
if(sscanf(line+36, "%s %s %n", codeline, name, &skip) != 2) {
|
||||
printf("%s\n%s\n", line, line+36);
|
||||
fatal_exit("unhandled malloc");
|
||||
}
|
||||
if(sscanf(line+36+skip+7, "%ld", &num) != 1) {
|
||||
printf("%s\n%s\n", line, line+36+skip+7);
|
||||
fatal_exit("unhandled malloc");
|
||||
}
|
||||
cl = get_codeline(tree, codeline, name);
|
||||
if(!cl)
|
||||
fatal_exit("alloc failure");
|
||||
cl->alloc += num;
|
||||
}
|
||||
|
||||
/** read up the calloc stats */
|
||||
static void
|
||||
read_calloc_stat(char* line, rbtree_t* tree)
|
||||
{
|
||||
char codeline[10240];
|
||||
char name[10240];
|
||||
int skip = 0;
|
||||
long num = 0, sz = 0;
|
||||
struct codeline* cl = 0;
|
||||
if(sscanf(line+36, "%s %s %n", codeline, name, &skip) != 2) {
|
||||
printf("%s\n%s\n", line, line+36);
|
||||
fatal_exit("unhandled calloc");
|
||||
}
|
||||
if(sscanf(line+36+skip+7, "%ld, %ld", &num, &sz) != 2) {
|
||||
printf("%s\n%s\n", line, line+36+skip+7);
|
||||
fatal_exit("unhandled calloc");
|
||||
}
|
||||
|
||||
cl = get_codeline(tree, codeline, name);
|
||||
if(!cl)
|
||||
fatal_exit("alloc failure");
|
||||
cl->alloc += num*sz;
|
||||
}
|
||||
|
||||
/** get size of file */
|
||||
static off_t
|
||||
get_file_size(const char* fname)
|
||||
{
|
||||
struct stat s;
|
||||
if(stat(fname, &s) < 0) {
|
||||
fatal_exit("could not stat %s: %s", fname, strerror(errno));
|
||||
}
|
||||
return s.st_size;
|
||||
}
|
||||
|
||||
/** read the logfile */
|
||||
static void
|
||||
readfile(rbtree_t* tree, const char* fname, struct alloc_misc* misc)
|
||||
{
|
||||
off_t total = get_file_size(fname);
|
||||
off_t done = (off_t)0;
|
||||
int report = 0;
|
||||
FILE* in = fopen(fname, "r");
|
||||
char buf[102400];
|
||||
if(!in)
|
||||
fatal_exit("could not open %s: %s", fname, strerror(errno));
|
||||
printf("Reading %s of size %lld\n", fname, (long long)total);
|
||||
while(fgets(buf, 102400, in)) {
|
||||
buf[102400-1] = 0;
|
||||
done += (off_t)strlen(buf);
|
||||
/* progress count */
|
||||
if((int)(((double)done / (double)total)*100.) > report) {
|
||||
report = (int)(((double)done / (double)total)*100.);
|
||||
fprintf(stderr, " %d%%", report);
|
||||
}
|
||||
|
||||
if(!match(buf))
|
||||
continue;
|
||||
if(strncmp(buf+36, "region ", 7) == 0)
|
||||
read_region_stat(buf, misc);
|
||||
else if(strstr(buf+36, "malloc("))
|
||||
read_malloc_stat(buf, tree);
|
||||
else if(strstr(buf+36, "calloc("))
|
||||
read_calloc_stat(buf, tree);
|
||||
else {
|
||||
printf("%s\n", buf);
|
||||
fatal_exit("unhandled input");
|
||||
}
|
||||
}
|
||||
fprintf(stderr, " done\n");
|
||||
fclose(in);
|
||||
}
|
||||
|
||||
/** print memory stats */
|
||||
static void
|
||||
printstats(rbtree_t* tree, struct alloc_misc* misc)
|
||||
{
|
||||
struct codeline* cl;
|
||||
uint64_t total = 0;
|
||||
printf("%12lld in region alloc\n", (long long)misc->region_alloc);
|
||||
total += misc->region_alloc;
|
||||
RBTREE_FOR(cl, struct codeline*, tree) {
|
||||
printf("%12lld in %s %s\n", (long long)cl->alloc,
|
||||
cl->codeline, cl->func);
|
||||
total += cl->alloc;
|
||||
}
|
||||
printf("------------\n");
|
||||
printf("%12lld total in %ld code lines\n", (long long)total,
|
||||
(long)tree->count);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/** main program */
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
rbtree_t* tree = 0;
|
||||
struct alloc_misc misc;
|
||||
if(argc != 2) {
|
||||
usage();
|
||||
}
|
||||
tree = rbtree_create(codeline_cmp);
|
||||
if(!tree)
|
||||
fatal_exit("alloc failure");
|
||||
memset(&misc, 0, sizeof(misc));
|
||||
readfile(tree, argv[1], &misc);
|
||||
printstats(tree, &misc);
|
||||
return 0;
|
||||
}
|
||||
Executable
+111
@@ -0,0 +1,111 @@
|
||||
# tpkg that only exes the files.
|
||||
args="../.."
|
||||
if test "$1" = "-a"; then
|
||||
args=$2
|
||||
shift
|
||||
shift
|
||||
fi
|
||||
|
||||
if test "$1" = "clean"; then
|
||||
echo "rm -f result.* .done* .tpkg.var.master .tpkg.var.test"
|
||||
rm -f result.* .done* .tpkg.var.master .tpkg.var.test
|
||||
exit 0
|
||||
fi
|
||||
if test "$1" = "fake"; then
|
||||
echo "minitpkg fake $2"
|
||||
echo "fake" > .done-`basename $2 .tpkg`
|
||||
exit 0
|
||||
fi
|
||||
if test "$1" = "report" || test "$2" = "report"; then
|
||||
echo "Minitpkg Report"
|
||||
for result in result.*; do
|
||||
name=`echo $result | sed -e 's/result\.//'`
|
||||
if test -f ".done-$name"; then
|
||||
if test "$1" != "-q"; then
|
||||
echo "** PASSED ** : $name"
|
||||
fi
|
||||
else
|
||||
echo "!! FAILED !! : $name"
|
||||
fi
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if test "$1" != 'exe'; then
|
||||
# usage
|
||||
echo "mini tpkg. Reduced functionality for old shells."
|
||||
echo " tpkg exe <file>"
|
||||
echo " tpkg fake <file>"
|
||||
echo " tpkg clean"
|
||||
echo " tpkg [-q] report"
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
|
||||
# do not execute if the disk is too full
|
||||
#DISKLIMIT=100000
|
||||
# This check is not portable (to Solaris 10).
|
||||
#avail=`df . | tail -1 | awk '{print $4}'`
|
||||
#if test "$avail" -lt "$DISKLIMIT"; then
|
||||
#echo "minitpkg: The disk is too full! Only $avail."
|
||||
#exit 1
|
||||
#fi
|
||||
|
||||
name=`basename $1 .tpkg`
|
||||
dir=$name.$$
|
||||
result=result.$name
|
||||
done=.done-$name
|
||||
success="no"
|
||||
shell="bash"
|
||||
|
||||
# check already done
|
||||
if test -f .done-$name; then
|
||||
echo "minitpkg .done-$name exists. skip test."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Extract
|
||||
echo "minitpkg extract $1 to $dir"
|
||||
mkdir $dir
|
||||
gzip -cd $name.tpkg | (cd $dir; tar xf -)
|
||||
cd $dir
|
||||
mv $name.dir/* .
|
||||
|
||||
# EXE
|
||||
echo "minitpkg exe $name"
|
||||
echo "minitpkg exe $name" > $result
|
||||
if test -f $name.pre; then
|
||||
echo "minitpkg exe $name.pre"
|
||||
echo "minitpkg exe $name.pre" >> $result
|
||||
$shell $name.pre $args >> $result
|
||||
if test $? -ne 0; then
|
||||
echo "Warning: $name.pre did not exit successfully"
|
||||
fi
|
||||
fi
|
||||
if test -f $name.test; then
|
||||
echo "minitpkg exe $name.test"
|
||||
echo "minitpkg exe $name.test" >> $result
|
||||
$shell $name.test $args >>$result 2>&1
|
||||
if test $? -ne 0; then
|
||||
echo "$name: FAILED" >> $result
|
||||
echo "$name: FAILED"
|
||||
success="no"
|
||||
else
|
||||
echo "$name: PASSED" >> $result
|
||||
echo "$name: PASSED" > ../.done-$name
|
||||
echo "$name: PASSED"
|
||||
success="yes"
|
||||
fi
|
||||
fi
|
||||
if test -f $name.post; then
|
||||
echo "minitpkg exe $name.post"
|
||||
echo "minitpkg exe $name.post" >> $result
|
||||
$shell $name.post $args >> $result
|
||||
if test $? -ne 0; then
|
||||
echo "Warning: $name.post did not exit successfully"
|
||||
fi
|
||||
fi
|
||||
|
||||
mv $result ..
|
||||
cd ..
|
||||
rm -rf $dir
|
||||
+21
-13
@@ -111,8 +111,13 @@ void analyze_rdata(ldns_buffer*pkt, const ldns_rr_descriptor* desc,
|
||||
}
|
||||
rdf++;
|
||||
}
|
||||
if(rdlen)
|
||||
if(rdlen) {
|
||||
size_t i;
|
||||
printf(" remain[%d]\n", (int)rdlen);
|
||||
for(i=0; i<rdlen; i++)
|
||||
printf(" %2.2X", (unsigned)ldns_buffer_current(pkt)[i]);
|
||||
printf("\n");
|
||||
}
|
||||
else printf("\n");
|
||||
ldns_buffer_skip(pkt, (ssize_t)rdlen);
|
||||
}
|
||||
@@ -134,9 +139,9 @@ void analyze_rr(ldns_buffer* pkt, int q)
|
||||
printf("\n");
|
||||
} else {
|
||||
ttl = ldns_buffer_read_u32(pkt);
|
||||
printf(" ttl %d (0x%x)", ttl, ttl);
|
||||
printf(" ttl %d (0x%x)", (int)ttl, (unsigned)ttl);
|
||||
len = ldns_buffer_read_u16(pkt);
|
||||
printf(" rdata len %d:\n", len);
|
||||
printf(" rdata len %d:\n", (int)len);
|
||||
if(ldns_rr_descript(type))
|
||||
analyze_rdata(pkt, ldns_rr_descript(type), len);
|
||||
else ldns_buffer_skip(pkt, (ssize_t)len);
|
||||
@@ -152,25 +157,28 @@ void analyze(ldns_buffer* pkt)
|
||||
if(ldns_buffer_limit(pkt) < 12) return;
|
||||
|
||||
i = ldns_buffer_read_u16(pkt);
|
||||
printf("id (hostorder): %d (0x%x)\n", i, i);
|
||||
printf("id (hostorder): %d (0x%x)\n", (int)i, (unsigned)i);
|
||||
f = ldns_buffer_read_u16(pkt);
|
||||
printf("flags: 0x%x\n", f);
|
||||
printf("flags: 0x%x\n", (unsigned)f);
|
||||
qd = ldns_buffer_read_u16(pkt);
|
||||
printf("qdcount: %d\n", qd);
|
||||
printf("qdcount: %d\n", (int)qd);
|
||||
an = ldns_buffer_read_u16(pkt);
|
||||
printf("ancount: %d\n", an);
|
||||
printf("ancount: %d\n", (int)an);
|
||||
ns = ldns_buffer_read_u16(pkt);
|
||||
printf("nscount: %d\n", ns);
|
||||
printf("nscount: %d\n", (int)ns);
|
||||
ar = ldns_buffer_read_u16(pkt);
|
||||
printf("arcount: %d\n", ar);
|
||||
printf("arcount: %d\n", (int)ar);
|
||||
|
||||
printf(";-- query section\n");
|
||||
while(ldns_buffer_remaining(pkt) > 0) {
|
||||
if(rrnum == qd) printf(";-- answer section\n");
|
||||
if(rrnum == qd+an) printf(";-- authority section\n");
|
||||
if(rrnum == qd+an+ns) printf(";-- additional section\n");
|
||||
if(rrnum == (int)qd)
|
||||
printf(";-- answer section\n");
|
||||
if(rrnum == (int)qd+(int)an)
|
||||
printf(";-- authority section\n");
|
||||
if(rrnum == (int)qd+(int)an+(int)ns)
|
||||
printf(";-- additional section\n");
|
||||
printf("rr %d ", rrnum);
|
||||
analyze_rr(pkt, rrnum < qd);
|
||||
analyze_rr(pkt, rrnum < (int)qd);
|
||||
rrnum++;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -46,7 +46,7 @@ static void
|
||||
skip_whites(const char** p)
|
||||
{
|
||||
while(1) {
|
||||
while(isspace(**p))
|
||||
while(isspace((int)**p))
|
||||
(*p)++;
|
||||
if(**p == ';') {
|
||||
/* comment, skip until newline */
|
||||
@@ -68,11 +68,11 @@ void hex_to_buf(ldns_buffer* pkt, const char* hex)
|
||||
skip_whites(&p);
|
||||
if(ldns_buffer_position(pkt) == ldns_buffer_limit(pkt))
|
||||
fatal_exit("hex_to_buf: buffer too small");
|
||||
if(!isalnum(*p))
|
||||
if(!isalnum((int)*p))
|
||||
break;
|
||||
val = ldns_hexdigit_to_int(*p++) << 4;
|
||||
skip_whites(&p);
|
||||
log_assert(*p && isalnum(*p));
|
||||
log_assert(*p && isalnum((int)*p));
|
||||
val |= ldns_hexdigit_to_int(*p++);
|
||||
ldns_buffer_write_u8(pkt, (uint8_t)val);
|
||||
skip_whites(&p);
|
||||
|
||||
+10
-8
@@ -92,7 +92,7 @@ strip_end_white(char* p)
|
||||
{
|
||||
size_t i;
|
||||
for(i = strlen(p); i > 0; i--) {
|
||||
if(isspace(p[i-1]))
|
||||
if(isspace((int)p[i-1]))
|
||||
p[i-1] = 0;
|
||||
else return;
|
||||
}
|
||||
@@ -133,12 +133,14 @@ replay_range_read(char* remain, FILE* in, const char* name, int* lineno,
|
||||
while(fgets(line, MAX_LINE_LEN-1, in)) {
|
||||
(*lineno)++;
|
||||
parse = line;
|
||||
while(isspace(*parse))
|
||||
while(isspace((int)*parse))
|
||||
parse++;
|
||||
if(!*parse || *parse == ';')
|
||||
if(!*parse || *parse == ';') {
|
||||
pos = ftello(in);
|
||||
continue;
|
||||
}
|
||||
if(parse_keyword(&parse, "ADDRESS")) {
|
||||
while(isspace(*parse))
|
||||
while(isspace((int)*parse))
|
||||
parse++;
|
||||
strip_end_white(parse);
|
||||
if(!extstrtoaddr(parse, &rng->addr, &rng->addrlen)) {
|
||||
@@ -199,7 +201,7 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
|
||||
return NULL;
|
||||
}
|
||||
remain += skip;
|
||||
while(isspace(*remain))
|
||||
while(isspace((int)*remain))
|
||||
remain++;
|
||||
if(parse_keyword(&remain, "NOTHING")) {
|
||||
mom->evt_type = repevt_nothing;
|
||||
@@ -224,7 +226,7 @@ replay_moment_read(char* remain, FILE* in, const char* name, int* lineno,
|
||||
free(mom);
|
||||
return NULL;
|
||||
}
|
||||
while(isspace(*remain))
|
||||
while(isspace((int)*remain))
|
||||
remain++;
|
||||
if(parse_keyword(&remain, "ADDRESS")) {
|
||||
if(!extstrtoaddr(remain, &mom->addr, &mom->addrlen)) {
|
||||
@@ -251,7 +253,7 @@ static struct replay_scenario*
|
||||
make_scenario(char* line)
|
||||
{
|
||||
struct replay_scenario* scen;
|
||||
while(isspace(*line))
|
||||
while(isspace((int)*line))
|
||||
line++;
|
||||
if(!*line) {
|
||||
log_err("scenario: no title given");
|
||||
@@ -283,7 +285,7 @@ replay_scenario_read(FILE* in, const char* name, int* lineno)
|
||||
while(fgets(line, MAX_LINE_LEN-1, in)) {
|
||||
parse=line;
|
||||
(*lineno)++;
|
||||
while(isspace(*parse))
|
||||
while(isspace((int)*parse))
|
||||
parse++;
|
||||
if(!*parse)
|
||||
continue; /* empty line */
|
||||
|
||||
@@ -228,6 +228,8 @@ struct replay_runtime {
|
||||
void (*sig_cb)(int, void*);
|
||||
/** signal handler user arg */
|
||||
void *sig_cb_arg;
|
||||
/** time to exit cleanly */
|
||||
int exit_cleanly;
|
||||
|
||||
/** size of buffers */
|
||||
size_t bufsize;
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* testcode/signit.c - debug tool to sign rrsets with given keys.
|
||||
*
|
||||
* Copyright (c) 2007, 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 signs rrsets with the given keys. It can be used to
|
||||
* construct input to test the validator with.
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "util/log.h"
|
||||
#include "util/config_file.h"
|
||||
#include "util/net_help.h"
|
||||
|
||||
/**
|
||||
* Key settings
|
||||
*/
|
||||
struct keysets {
|
||||
/** signature inception */
|
||||
uint32_t incep;
|
||||
/** signature expiration */
|
||||
uint32_t expi;
|
||||
/** owner name */
|
||||
char* owner;
|
||||
/** keytag */
|
||||
uint16_t keytag;
|
||||
/** DNSKEY flags */
|
||||
uint16_t flags;
|
||||
};
|
||||
|
||||
/** print usage and exit */
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
printf("usage: signit expi ince keytag owner keyfile\n");
|
||||
printf("present rrset data on stdin.\n");
|
||||
printf("signed data is printed to stdout.\n");
|
||||
printf("\n");
|
||||
printf("Or use: signit NSEC3PARAM hash flags iter salt\n");
|
||||
printf("present names on stdin, hashed names are printed to stdout.\n");
|
||||
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->keytag = (uint16_t)atoi(argv[3]);
|
||||
s->owner = argv[4];
|
||||
s->flags = DNSKEY_BIT_ZSK; /* to enforce signing */
|
||||
}
|
||||
|
||||
/** read all key files, exit on error */
|
||||
static ldns_key_list*
|
||||
read_keys(int num, char* names[], struct keysets* set)
|
||||
{
|
||||
int i;
|
||||
ldns_key_list* keys = ldns_key_list_new();
|
||||
ldns_key* k;
|
||||
ldns_rdf* rdf;
|
||||
ldns_status s;
|
||||
int b;
|
||||
FILE* in;
|
||||
|
||||
if(!keys) fatal_exit("alloc failure");
|
||||
for(i=0; i<num; i++) {
|
||||
printf("read keyfile %s\n", names[i]);
|
||||
in = fopen(names[i], "r");
|
||||
if(!in) fatal_exit("could not open %s: %s", names[i],
|
||||
strerror(errno));
|
||||
s = ldns_key_new_frm_fp(&k, in);
|
||||
fclose(in);
|
||||
if(s != LDNS_STATUS_OK)
|
||||
fatal_exit("bad keyfile %s: %s", names[i],
|
||||
ldns_get_errorstr_by_id(s));
|
||||
ldns_key_set_expiration(k, set->expi);
|
||||
ldns_key_set_inception(k, set->incep);
|
||||
s = ldns_str2rdf_dname(&rdf, set->owner);
|
||||
if(s != LDNS_STATUS_OK)
|
||||
fatal_exit("bad owner name %s: %s", set->owner,
|
||||
ldns_get_errorstr_by_id(s));
|
||||
ldns_key_set_pubkey_owner(k, rdf);
|
||||
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);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/** read list of rrs from the file */
|
||||
static ldns_rr_list*
|
||||
read_rrs(FILE* in)
|
||||
{
|
||||
uint32_t my_ttl = 3600;
|
||||
ldns_rdf *my_origin = NULL;
|
||||
ldns_rdf *my_prev = NULL;
|
||||
ldns_status s;
|
||||
int line_nr = 1;
|
||||
int b;
|
||||
|
||||
ldns_rr_list* list;
|
||||
ldns_rr *rr;
|
||||
|
||||
list = ldns_rr_list_new();
|
||||
if(!list) fatal_exit("alloc error");
|
||||
|
||||
while(!feof(in)) {
|
||||
s = ldns_rr_new_frm_fp_l(&rr, in, &my_ttl, &my_origin,
|
||||
&my_prev, &line_nr);
|
||||
if(s == LDNS_STATUS_SYNTAX_TTL ||
|
||||
s == LDNS_STATUS_SYNTAX_ORIGIN ||
|
||||
s == LDNS_STATUS_SYNTAX_EMPTY)
|
||||
continue;
|
||||
else if(s != LDNS_STATUS_OK)
|
||||
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);
|
||||
}
|
||||
printf("read %d lines\n", line_nr);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/** sign the rrs with the keys */
|
||||
static void
|
||||
signit(ldns_rr_list* rrs, ldns_key_list* keys)
|
||||
{
|
||||
ldns_rr_list* rrset;
|
||||
ldns_rr_list* sigs;
|
||||
|
||||
while(ldns_rr_list_rr_count(rrs) > 0) {
|
||||
rrset = ldns_rr_list_pop_rrset(rrs);
|
||||
if(!rrset) fatal_exit("copy alloc failure");
|
||||
sigs = ldns_sign_public(rrset, keys);
|
||||
if(!sigs) fatal_exit("failed to sign");
|
||||
ldns_rr_list_print(stdout, rrset);
|
||||
ldns_rr_list_print(stdout, sigs);
|
||||
printf("\n");
|
||||
ldns_rr_list_free(rrset);
|
||||
ldns_rr_list_free(sigs);
|
||||
}
|
||||
}
|
||||
|
||||
/** process keys and signit */
|
||||
static void
|
||||
process_keys(int argc, char* argv[])
|
||||
{
|
||||
ldns_rr_list* rrs;
|
||||
ldns_key_list* keys;
|
||||
struct keysets settings;
|
||||
log_assert(argc == 6);
|
||||
|
||||
parse_cmdline(argv, &settings);
|
||||
keys = read_keys(1, argv+5, &settings);
|
||||
rrs = read_rrs(stdin);
|
||||
signit(rrs, keys);
|
||||
|
||||
ldns_rr_list_deep_free(rrs);
|
||||
ldns_key_list_free(keys);
|
||||
}
|
||||
|
||||
/** process nsec3 params and perform hashing */
|
||||
static void
|
||||
process_nsec3(int argc, char* argv[])
|
||||
{
|
||||
char line[10240];
|
||||
ldns_rdf* salt;
|
||||
ldns_rdf* in, *out;
|
||||
ldns_status status;
|
||||
status = ldns_str2rdf_nsec3_salt(&salt, argv[5]);
|
||||
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);
|
||||
while(fgets(line, (int)sizeof(line), stdin)) {
|
||||
if(strlen(line) > 0)
|
||||
line[strlen(line)-1] = 0; /* remove trailing newline */
|
||||
if(line[0]==0)
|
||||
continue;
|
||||
status = ldns_str2rdf_dname(&in, line);
|
||||
if(status != LDNS_STATUS_OK)
|
||||
fatal_exit("Could not parse name %s: %s", line,
|
||||
ldns_get_errorstr_by_id(status));
|
||||
ldns_rdf_print(stdout, in);
|
||||
printf(" -> ");
|
||||
/* arg 3 is flags, unused */
|
||||
out = ldns_nsec3_hash_name(in, (uint8_t)atoi(argv[2]),
|
||||
(uint16_t)atoi(argv[4]),
|
||||
ldns_rdf_data(salt)[0], ldns_rdf_data(salt)+1);
|
||||
if(!out)
|
||||
fatal_exit("Could not hash %s", line);
|
||||
ldns_rdf_print(stdout, out);
|
||||
printf("\n");
|
||||
ldns_rdf_deep_free(in);
|
||||
ldns_rdf_deep_free(out);
|
||||
}
|
||||
ldns_rdf_deep_free(salt);
|
||||
}
|
||||
|
||||
/** main program */
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
log_init(NULL, 0, NULL);
|
||||
if(argc != 6) {
|
||||
usage();
|
||||
}
|
||||
if(strcmp(argv[1], "NSEC3PARAM") == 0) {
|
||||
process_nsec3(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
process_keys(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
+6
-7
@@ -43,10 +43,10 @@ function dotest()
|
||||
fi
|
||||
|
||||
cat >makeconf.mak.$$ << EOF
|
||||
configure: configure.ac
|
||||
$AC_CMD
|
||||
touch configure
|
||||
Makefile: configure Makefile.in
|
||||
#configure: configure.ac
|
||||
# $AC_CMD
|
||||
# touch configure
|
||||
Makefile: Makefile.in #configure
|
||||
./configure $CONFIGURE_FLAGS $DISABLE
|
||||
touch Makefile
|
||||
EOF
|
||||
@@ -77,12 +77,11 @@ EOF
|
||||
# echossh $1 "gtar xzf unbound_ttt.tar.gz && rm unbound_ttt.tar.gz"
|
||||
fi
|
||||
echossh $1 "cd $2; $MAKE_CMD -f makeconf.mak.$$ Makefile"
|
||||
echossh $1 "cd $2; $MAKE_CMD"
|
||||
echossh $1 "cd $2; $MAKE_CMD all tests"
|
||||
echossh $1 "cd $2; $MAKE_CMD doc"
|
||||
if test $RUN_TEST = yes; then
|
||||
echossh $1 "cd $2/testdata; tpkg clean"
|
||||
echossh $1 "cd $2; bash testcode/do-tests.sh"
|
||||
echossh $1 "cd $2/testdata; tpkg -q report" | tee -a $REPORT_FILE
|
||||
echossh $1 "cd $2/testdata; sh ../testcode/mini_tpkg.sh -q report" | tee -a $REPORT_FILE
|
||||
fi
|
||||
echossh $1 "cd $2; rm -f makeconf.mak.$$"
|
||||
rm -f makeconf.mak.$$
|
||||
|
||||
+23
-6
@@ -53,6 +53,8 @@
|
||||
|
||||
/** maximum line length for lines in the replay file. */
|
||||
#define MAX_LINE_LEN 1024
|
||||
/** the config file (removed at exit) */
|
||||
static char cfgfile[MAX_LINE_LEN];
|
||||
|
||||
/** give commandline usage for testbound. */
|
||||
static void
|
||||
@@ -82,7 +84,7 @@ add_opts(char* optarg, int* pass_argc, char* pass_argv[])
|
||||
{
|
||||
char *p = optarg, *np;
|
||||
size_t len;
|
||||
while(p && isspace(*p))
|
||||
while(p && isspace((int)*p))
|
||||
p++;
|
||||
while(p && *p) {
|
||||
/* find location of next string and length of this one */
|
||||
@@ -100,7 +102,7 @@ add_opts(char* optarg, int* pass_argc, char* pass_argv[])
|
||||
(*pass_argc)++;
|
||||
/* go to next option */
|
||||
p = np;
|
||||
while(p && isspace(*p))
|
||||
while(p && isspace((int)*p))
|
||||
p++;
|
||||
}
|
||||
}
|
||||
@@ -133,10 +135,16 @@ setup_config(FILE* in, char* configfile, int* lineno,
|
||||
if(!cfg) fatal_exit("could not open %s: %s",
|
||||
configfile, strerror(errno));
|
||||
line[MAX_LINE_LEN-1] = 0;
|
||||
/* some basic settings to not pollute the host system */
|
||||
fprintf(cfg, "server: use-syslog: no\n");
|
||||
fprintf(cfg, " directory: \"\"\n");
|
||||
fprintf(cfg, " chroot: \"\"\n");
|
||||
fprintf(cfg, " username: \"\"\n");
|
||||
fprintf(cfg, " pidfile: \"\"\n");
|
||||
while(fgets(line, MAX_LINE_LEN-1, in)) {
|
||||
parse = line;
|
||||
(*lineno)++;
|
||||
while(isspace(*parse))
|
||||
while(isspace((int)*parse))
|
||||
parse++;
|
||||
if(!*parse || parse[0] == ';')
|
||||
continue;
|
||||
@@ -179,6 +187,12 @@ setup_playback(const char* filename, char* configfile,
|
||||
log_info("Scenario: %s", scen->title);
|
||||
return scen;
|
||||
}
|
||||
|
||||
/** remove config file at exit */
|
||||
void remove_configfile(void)
|
||||
{
|
||||
unlink(cfgfile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main fake event test program. Setup, teardown and report errors.
|
||||
@@ -195,11 +209,11 @@ main(int argc, char* argv[])
|
||||
int init_optind = optind;
|
||||
char* init_optarg = optarg;
|
||||
struct replay_scenario* scen = NULL;
|
||||
char cfgfile[MAX_LINE_LEN];
|
||||
|
||||
log_init(NULL);
|
||||
log_init(NULL, 0, NULL);
|
||||
log_info("Start of %s testbound program.", PACKAGE_STRING);
|
||||
/* determine commandline options for the daemon */
|
||||
cfgfile[0] = 0;
|
||||
pass_argc = 1;
|
||||
pass_argv[0] = "unbound";
|
||||
add_opts("-d", &pass_argc, pass_argv);
|
||||
@@ -224,6 +238,8 @@ main(int argc, char* argv[])
|
||||
testbound_usage();
|
||||
return 1;
|
||||
}
|
||||
if(atexit(&remove_configfile) != 0)
|
||||
fatal_exit("atexit() failed: %s", strerror(errno));
|
||||
|
||||
/* setup test environment */
|
||||
scen = setup_playback(playback_file, cfgfile, &pass_argc, pass_argv);
|
||||
@@ -240,9 +256,10 @@ main(int argc, char* argv[])
|
||||
/* run the normal daemon */
|
||||
res = daemon_main(pass_argc, pass_argv);
|
||||
|
||||
unlink(cfgfile);
|
||||
fake_event_cleanup();
|
||||
for(c=1; c<pass_argc; c++)
|
||||
free(pass_argv[c]);
|
||||
if(res == 0)
|
||||
log_info("Testbound Exit Success");
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* testcode/unitanchor.c - unit test for trust anchor storage.
|
||||
*
|
||||
* Copyright (c) 2007, 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
|
||||
* Calls trust anchor unit tests. Exits with code 1 on a failure.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "util/log.h"
|
||||
#include "util/data/dname.h"
|
||||
#include "testcode/unitmain.h"
|
||||
#include "validator/val_anchor.h"
|
||||
|
||||
/** test empty set */
|
||||
static void
|
||||
test_anchor_empty(struct val_anchors* a)
|
||||
{
|
||||
uint16_t c = LDNS_RR_CLASS_IN;
|
||||
unit_assert(anchors_lookup(a, (uint8_t*)"\000", 1, c) == NULL);
|
||||
unit_assert(anchors_lookup(a, (uint8_t*)"\003com\000", 5, c) == NULL);
|
||||
unit_assert(anchors_lookup(a,
|
||||
(uint8_t*)"\007example\003com\000", 11, c) == NULL);
|
||||
unit_assert(anchors_lookup(a, (uint8_t*)"\002nl\000", 4, c) == NULL);
|
||||
unit_assert(anchors_lookup(a,
|
||||
(uint8_t*)"\004labs\002nl\000", 9, c) == NULL);
|
||||
unit_assert(anchors_lookup(a,
|
||||
(uint8_t*)"\004fabs\002nl\000", 9, c) == NULL);
|
||||
}
|
||||
|
||||
/** test set of one anchor */
|
||||
static void
|
||||
test_anchor_one(ldns_buffer* buff, struct val_anchors* a)
|
||||
{
|
||||
uint16_t c = LDNS_RR_CLASS_IN;
|
||||
unit_assert(anchor_store_str(a, buff,
|
||||
"nl. DS 42860 5 1 14D739EB566D2B1A5E216A0BA4D17FA9B038BE4A"));
|
||||
unit_assert(anchors_lookup(a, (uint8_t*)"\000", 1, c) == NULL);
|
||||
unit_assert(anchors_lookup(a, (uint8_t*)"\003com\000", 5, c) == NULL);
|
||||
unit_assert(anchors_lookup(a,
|
||||
(uint8_t*)"\007example\003com\000", 11, c) == NULL);
|
||||
unit_assert(anchors_lookup(a, (uint8_t*)"\002nl\000", 4, c) != NULL);
|
||||
unit_assert(anchors_lookup(a,
|
||||
(uint8_t*)"\004labs\002nl\000", 9, c) != NULL);
|
||||
unit_assert(anchors_lookup(a,
|
||||
(uint8_t*)"\004fabs\002nl\000", 9, c) != NULL);
|
||||
unit_assert(anchors_lookup(a, (uint8_t*)"\002oo\000", 4, c) == NULL);
|
||||
}
|
||||
|
||||
/** test with several anchors */
|
||||
static void
|
||||
test_anchors(ldns_buffer* buff, struct val_anchors* a)
|
||||
{
|
||||
struct trust_anchor* ta;
|
||||
uint16_t c = LDNS_RR_CLASS_IN;
|
||||
unit_assert(anchor_store_str(a, buff,
|
||||
"labs.nl. DS 42860 5 1 14D739EB566D2B1A5E216A0BA4D17FA9B038BE4A"));
|
||||
unit_assert(anchors_lookup(a, (uint8_t*)"\000", 1, c) == NULL);
|
||||
unit_assert(anchors_lookup(a, (uint8_t*)"\003com\000", 5, c) == NULL);
|
||||
unit_assert(anchors_lookup(a,
|
||||
(uint8_t*)"\007example\003com\000", 11, c) == NULL);
|
||||
unit_assert(ta = anchors_lookup(a, (uint8_t*)"\002nl\000", 4, c));
|
||||
unit_assert(query_dname_compare(ta->name, (uint8_t*)"\002nl\000")==0);
|
||||
unit_assert(ta = anchors_lookup(a,
|
||||
(uint8_t*)"\004labs\002nl\000", 9, c));
|
||||
unit_assert(query_dname_compare(ta->name,
|
||||
(uint8_t*)"\004labs\002nl\000") == 0);
|
||||
unit_assert(ta = anchors_lookup(a,
|
||||
(uint8_t*)"\004fabs\002nl\000", 9, c));
|
||||
unit_assert(query_dname_compare(ta->name,
|
||||
(uint8_t*)"\002nl\000") == 0);
|
||||
unit_assert(anchors_lookup(a, (uint8_t*)"\002oo\000", 4, c) == NULL);
|
||||
}
|
||||
|
||||
void anchors_test()
|
||||
{
|
||||
ldns_buffer* buff = ldns_buffer_new(65800);
|
||||
struct val_anchors* a;
|
||||
unit_assert(a = anchors_create());
|
||||
ldns_buffer_flip(buff);
|
||||
test_anchor_empty(a);
|
||||
test_anchor_one(buff, a);
|
||||
test_anchors(buff, a);
|
||||
anchors_delete(a);
|
||||
ldns_buffer_free(buff);
|
||||
}
|
||||
+309
-4
@@ -76,21 +76,21 @@ static void
|
||||
dname_test_qdtl(ldns_buffer* buff)
|
||||
{
|
||||
ldns_buffer_write_at(buff, 0, "\012abCDeaBCde\003cOm\000", 16);
|
||||
query_dname_tolower(ldns_buffer_begin(buff), 16);
|
||||
query_dname_tolower(ldns_buffer_begin(buff));
|
||||
unit_assert( memcmp(ldns_buffer_begin(buff),
|
||||
"\012abcdeabcde\003com\000", 16) == 0);
|
||||
|
||||
ldns_buffer_write_at(buff, 0, "\001+\012abC{e-ZYXe\003NET\000", 18);
|
||||
query_dname_tolower(ldns_buffer_begin(buff), 18);
|
||||
query_dname_tolower(ldns_buffer_begin(buff));
|
||||
unit_assert( memcmp(ldns_buffer_begin(buff),
|
||||
"\001+\012abc{e-zyxe\003net\000", 18) == 0);
|
||||
|
||||
ldns_buffer_write_at(buff, 0, "\000", 1);
|
||||
query_dname_tolower(ldns_buffer_begin(buff), 1);
|
||||
query_dname_tolower(ldns_buffer_begin(buff));
|
||||
unit_assert( memcmp(ldns_buffer_begin(buff), "\000", 1) == 0);
|
||||
|
||||
ldns_buffer_write_at(buff, 0, "\002NL\000", 4);
|
||||
query_dname_tolower(ldns_buffer_begin(buff), 4);
|
||||
query_dname_tolower(ldns_buffer_begin(buff));
|
||||
unit_assert( memcmp(ldns_buffer_begin(buff), "\002nl\000", 4) == 0);
|
||||
}
|
||||
|
||||
@@ -433,6 +433,305 @@ dname_test_strict_subdomain()
|
||||
(uint8_t*)"\007example\003org", 3));
|
||||
}
|
||||
|
||||
/** test dname_is_root */
|
||||
static void
|
||||
dname_test_isroot()
|
||||
{
|
||||
unit_assert(dname_is_root((uint8_t*)"\000"));
|
||||
unit_assert(!dname_is_root((uint8_t*)"\001a\000"));
|
||||
unit_assert(!dname_is_root((uint8_t*)"\005abvcd\003com\000"));
|
||||
/* malformed dname in this test, but should work */
|
||||
unit_assert(!dname_is_root((uint8_t*)"\077a\000"));
|
||||
unit_assert(dname_is_root((uint8_t*)"\000"));
|
||||
}
|
||||
|
||||
/** test dname_remove_label */
|
||||
static void
|
||||
dname_test_removelabel()
|
||||
{
|
||||
uint8_t* orig = (uint8_t*)"\007example\003com\000";
|
||||
uint8_t* n = orig;
|
||||
size_t l = 13;
|
||||
dname_remove_label(&n, &l);
|
||||
unit_assert( n == orig+8 );
|
||||
unit_assert( l == 5 );
|
||||
dname_remove_label(&n, &l);
|
||||
unit_assert( n == orig+12 );
|
||||
unit_assert( l == 1 );
|
||||
dname_remove_label(&n, &l);
|
||||
unit_assert( n == orig+12 );
|
||||
unit_assert( l == 1 );
|
||||
}
|
||||
|
||||
/** test dname_signame_label_count */
|
||||
static void
|
||||
dname_test_sigcount()
|
||||
{
|
||||
unit_assert(dname_signame_label_count((uint8_t*)"\000") == 0);
|
||||
unit_assert(dname_signame_label_count((uint8_t*)"\001*\000") == 0);
|
||||
unit_assert(dname_signame_label_count((uint8_t*)"\003xom\000") == 1);
|
||||
unit_assert(dname_signame_label_count(
|
||||
(uint8_t*)"\001*\003xom\000") == 1);
|
||||
unit_assert(dname_signame_label_count(
|
||||
(uint8_t*)"\007example\003xom\000") == 2);
|
||||
unit_assert(dname_signame_label_count(
|
||||
(uint8_t*)"\001*\007example\003xom\000") == 2);
|
||||
unit_assert(dname_signame_label_count(
|
||||
(uint8_t*)"\003www\007example\003xom\000") == 3);
|
||||
unit_assert(dname_signame_label_count(
|
||||
(uint8_t*)"\001*\003www\007example\003xom\000") == 3);
|
||||
}
|
||||
|
||||
/** test dname_is_wild routine */
|
||||
static void
|
||||
dname_test_iswild()
|
||||
{
|
||||
unit_assert( !dname_is_wild((uint8_t*)"\000") );
|
||||
unit_assert( dname_is_wild((uint8_t*)"\001*\000") );
|
||||
unit_assert( !dname_is_wild((uint8_t*)"\003net\000") );
|
||||
unit_assert( dname_is_wild((uint8_t*)"\001*\003net\000") );
|
||||
}
|
||||
|
||||
/** test dname_canonical_compare */
|
||||
static void
|
||||
dname_test_canoncmp()
|
||||
{
|
||||
/* equality */
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\000",
|
||||
(uint8_t*)"\000"
|
||||
) == 0);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\003net\000",
|
||||
(uint8_t*)"\003net\000"
|
||||
) == 0);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\007example\003net\000",
|
||||
(uint8_t*)"\007example\003net\000"
|
||||
) == 0);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\004test\007example\003net\000",
|
||||
(uint8_t*)"\004test\007example\003net\000"
|
||||
) == 0);
|
||||
|
||||
/* subdomains */
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\003com",
|
||||
(uint8_t*)"\000"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\000",
|
||||
(uint8_t*)"\003com"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\007example\003com",
|
||||
(uint8_t*)"\003com"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\003com",
|
||||
(uint8_t*)"\007example\003com"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\007example\003com",
|
||||
(uint8_t*)"\000"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\000",
|
||||
(uint8_t*)"\007example\003com"
|
||||
) == -1);
|
||||
|
||||
/* compare rightmost label */
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\003com",
|
||||
(uint8_t*)"\003net"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\003net",
|
||||
(uint8_t*)"\003com"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\003net",
|
||||
(uint8_t*)"\003org"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\007example\003net",
|
||||
(uint8_t*)"\003org"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\003org",
|
||||
(uint8_t*)"\007example\003net"
|
||||
) == 1);
|
||||
|
||||
/* label length makes a difference; but only if rest is equal */
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\004neta",
|
||||
(uint8_t*)"\003net"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\002ne",
|
||||
(uint8_t*)"\004neta"
|
||||
) == -1);
|
||||
|
||||
/* label content */
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\003aag\007example\003net",
|
||||
(uint8_t*)"\003bla\007example\003net"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\003bla\007example\003net",
|
||||
(uint8_t*)"\003aag\007example\003net"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\003bla\003aag\007example\003net",
|
||||
(uint8_t*)"\003aag\003bla\007example\003net"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\02sn\003opt\003aag\007example\003net",
|
||||
(uint8_t*)"\02sn\003opt\003bla\007example\003net"
|
||||
) == -1);
|
||||
|
||||
/* lowercase during compare */
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\003bLa\007examPLe\003net",
|
||||
(uint8_t*)"\003bla\007eXAmple\003nET"
|
||||
) == 0);
|
||||
|
||||
/* example from 4034 */
|
||||
/* example a.example yljkjljk.a.example Z.a.example zABC.a.EXAMPLE
|
||||
z.example \001.z.example *.z.example \200.z.example */
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"",
|
||||
(uint8_t*)"\007example"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\007example",
|
||||
(uint8_t*)"\001a\007example"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001a\007example",
|
||||
(uint8_t*)"\010yljkjljk\001a\007example"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\010yljkjljk\001a\007example",
|
||||
(uint8_t*)"\001Z\001a\007example"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001Z\001a\007example",
|
||||
(uint8_t*)"\004zABC\001a\007EXAMPLE"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\004zABC\001a\007EXAMPLE",
|
||||
(uint8_t*)"\001z\007example"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001z\007example",
|
||||
(uint8_t*)"\001\001\001z\007example"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001\001\001z\007example",
|
||||
(uint8_t*)"\001*\001z\007example"
|
||||
) == -1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001*\001z\007example",
|
||||
(uint8_t*)"\001\200\001z\007example"
|
||||
) == -1);
|
||||
/* same example in reverse */
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\007example",
|
||||
(uint8_t*)""
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001a\007example",
|
||||
(uint8_t*)"\007example"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\010yljkjljk\001a\007example",
|
||||
(uint8_t*)"\001a\007example"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001Z\001a\007example",
|
||||
(uint8_t*)"\010yljkjljk\001a\007example"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\004zABC\001a\007EXAMPLE",
|
||||
(uint8_t*)"\001Z\001a\007example"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001z\007example",
|
||||
(uint8_t*)"\004zABC\001a\007EXAMPLE"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001\001\001z\007example",
|
||||
(uint8_t*)"\001z\007example"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001*\001z\007example",
|
||||
(uint8_t*)"\001\001\001z\007example"
|
||||
) == 1);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001\200\001z\007example",
|
||||
(uint8_t*)"\001*\001z\007example"
|
||||
) == 1);
|
||||
/* same example for equality */
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\007example",
|
||||
(uint8_t*)"\007example"
|
||||
) == 0);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001a\007example",
|
||||
(uint8_t*)"\001a\007example"
|
||||
) == 0);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\010yljkjljk\001a\007example",
|
||||
(uint8_t*)"\010yljkjljk\001a\007example"
|
||||
) == 0);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001Z\001a\007example",
|
||||
(uint8_t*)"\001Z\001a\007example"
|
||||
) == 0);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\004zABC\001a\007EXAMPLE",
|
||||
(uint8_t*)"\004zABC\001a\007EXAMPLE"
|
||||
) == 0);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001z\007example",
|
||||
(uint8_t*)"\001z\007example"
|
||||
) == 0);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001\001\001z\007example",
|
||||
(uint8_t*)"\001\001\001z\007example"
|
||||
) == 0);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001*\001z\007example",
|
||||
(uint8_t*)"\001*\001z\007example"
|
||||
) == 0);
|
||||
unit_assert( dname_canonical_compare(
|
||||
(uint8_t*)"\001\200\001z\007example",
|
||||
(uint8_t*)"\001\200\001z\007example"
|
||||
) == 0);
|
||||
}
|
||||
|
||||
/** Test dname_get_shared_topdomain */
|
||||
static void
|
||||
dname_test_topdomain()
|
||||
{
|
||||
unit_assert( query_dname_compare(
|
||||
dname_get_shared_topdomain(
|
||||
(uint8_t*)"",
|
||||
(uint8_t*)""),
|
||||
(uint8_t*)"") == 0);
|
||||
unit_assert( query_dname_compare(
|
||||
dname_get_shared_topdomain(
|
||||
(uint8_t*)"\003www\007example\003com",
|
||||
(uint8_t*)"\003www\007example\003com"),
|
||||
(uint8_t*)"\003www\007example\003com") == 0);
|
||||
unit_assert( query_dname_compare(
|
||||
dname_get_shared_topdomain(
|
||||
(uint8_t*)"\003www\007example\003com",
|
||||
(uint8_t*)"\003bla\007example\003com"),
|
||||
(uint8_t*)"\007example\003com") == 0);
|
||||
}
|
||||
|
||||
void dname_test()
|
||||
{
|
||||
ldns_buffer* buff = ldns_buffer_new(65800);
|
||||
@@ -446,5 +745,11 @@ void dname_test()
|
||||
dname_test_pkt_dname_len(buff);
|
||||
dname_test_strict_subdomain();
|
||||
dname_test_subdomain();
|
||||
dname_test_isroot();
|
||||
dname_test_removelabel();
|
||||
dname_test_sigcount();
|
||||
dname_test_iswild();
|
||||
dname_test_canoncmp();
|
||||
dname_test_topdomain();
|
||||
ldns_buffer_free(buff);
|
||||
}
|
||||
|
||||
+55
-92
@@ -42,36 +42,24 @@
|
||||
#include "testcode/unitmain.h"
|
||||
#include "util/log.h"
|
||||
#include "util/storage/lruhash.h"
|
||||
#include "util/storage/slabhash.h" /* for the test structures */
|
||||
|
||||
/* --- test representation --- */
|
||||
/** structure contains test key */
|
||||
struct testkey {
|
||||
/** the key id */
|
||||
int id;
|
||||
/** the entry */
|
||||
struct lruhash_entry entry;
|
||||
};
|
||||
/** structure contains test data */
|
||||
struct testdata {
|
||||
/** data value */
|
||||
int data;
|
||||
};
|
||||
/** use this type for the lruhash test key */
|
||||
typedef struct slabhash_testkey testkey_t;
|
||||
/** use this type for the lruhash test data */
|
||||
typedef struct slabhash_testdata testdata_t;
|
||||
|
||||
/** sizefunc for lruhash */
|
||||
static size_t test_sizefunc(void*, void*);
|
||||
/** comparefunc for lruhash */
|
||||
static int test_compfunc(void*, void*);
|
||||
/** delkey for lruhash */
|
||||
static void test_delkey(void*, void*, int);
|
||||
/** deldata for lruhash */
|
||||
static void test_deldata(void*, void*);
|
||||
/* --- end test representation --- */
|
||||
/** delete key */
|
||||
static void delkey(struct slabhash_testkey* k) {
|
||||
lock_rw_destroy(&k->entry.lock); free(k);}
|
||||
/** delete data */
|
||||
static void deldata(struct slabhash_testdata* d) {free(d);}
|
||||
|
||||
/** hash func, very bad to improve collisions */
|
||||
static hashvalue_t myhash(int id) {return (hashvalue_t)id & 0x0f;}
|
||||
/** allocate new key, fill in hash */
|
||||
static struct testkey* newkey(int id) {
|
||||
struct testkey* k = (struct testkey*)calloc(1, sizeof(struct testkey));
|
||||
static testkey_t* newkey(int id) {
|
||||
testkey_t* k = (testkey_t*)calloc(1, sizeof(testkey_t));
|
||||
if(!k) fatal_exit("out of memory");
|
||||
k->id = id;
|
||||
k->entry.hash = myhash(id);
|
||||
@@ -80,28 +68,23 @@ static struct testkey* newkey(int id) {
|
||||
return k;
|
||||
}
|
||||
/** new data el */
|
||||
static struct testdata* newdata(int val) {
|
||||
struct testdata* d = (struct testdata*)calloc(1,
|
||||
sizeof(struct testdata));
|
||||
static testdata_t* newdata(int val) {
|
||||
testdata_t* d = (testdata_t*)calloc(1,
|
||||
sizeof(testdata_t));
|
||||
if(!d) fatal_exit("out of memory");
|
||||
d->data = val;
|
||||
return d;
|
||||
}
|
||||
/** delete key */
|
||||
static void delkey(struct testkey* k) {
|
||||
lock_rw_destroy(&k->entry.lock); free(k);}
|
||||
/** delete data */
|
||||
static void deldata(struct testdata* d) {free(d);}
|
||||
|
||||
/** test bin_find_entry function and bin_overflow_remove */
|
||||
static void
|
||||
test_bin_find_entry(struct lruhash* table)
|
||||
{
|
||||
struct testkey* k = newkey(12);
|
||||
struct testdata* d = newdata(128);
|
||||
struct testkey* k2 = newkey(12 + 1024);
|
||||
struct testkey* k3 = newkey(14);
|
||||
struct testkey* k4 = newkey(12 + 1024*2);
|
||||
testkey_t* k = newkey(12);
|
||||
testdata_t* d = newdata(128);
|
||||
testkey_t* k2 = newkey(12 + 1024);
|
||||
testkey_t* k3 = newkey(14);
|
||||
testkey_t* k4 = newkey(12 + 1024*2);
|
||||
hashvalue_t h = myhash(12);
|
||||
struct lruhash_bin bin;
|
||||
memset(&bin, 0, sizeof(bin));
|
||||
@@ -178,8 +161,8 @@ test_bin_find_entry(struct lruhash* table)
|
||||
/** test lru_front lru_remove */
|
||||
static void test_lru(struct lruhash* table)
|
||||
{
|
||||
struct testkey* k = newkey(12);
|
||||
struct testkey* k2 = newkey(14);
|
||||
testkey_t* k = newkey(12);
|
||||
testkey_t* k2 = newkey(14);
|
||||
lock_quick_lock(&table->lock);
|
||||
|
||||
unit_assert( table->lru_start == NULL && table->lru_end == NULL);
|
||||
@@ -225,10 +208,10 @@ static void test_lru(struct lruhash* table)
|
||||
static void
|
||||
test_short_table(struct lruhash* table)
|
||||
{
|
||||
struct testkey* k = newkey(12);
|
||||
struct testkey* k2 = newkey(14);
|
||||
struct testdata* d = newdata(128);
|
||||
struct testdata* d2 = newdata(129);
|
||||
testkey_t* k = newkey(12);
|
||||
testkey_t* k2 = newkey(14);
|
||||
testdata_t* d = newdata(128);
|
||||
testdata_t* d2 = newdata(129);
|
||||
|
||||
k->entry.data = d;
|
||||
k2->entry.data = d2;
|
||||
@@ -249,11 +232,11 @@ test_short_table(struct lruhash* table)
|
||||
|
||||
/** test adding a random element */
|
||||
static void
|
||||
testadd(struct lruhash* table, struct testdata* ref[])
|
||||
testadd(struct lruhash* table, testdata_t* ref[])
|
||||
{
|
||||
int numtoadd = random() % HASHTESTMAX;
|
||||
struct testdata* data = newdata(numtoadd);
|
||||
struct testkey* key = newkey(numtoadd);
|
||||
testdata_t* data = newdata(numtoadd);
|
||||
testkey_t* key = newkey(numtoadd);
|
||||
key->entry.data = data;
|
||||
lruhash_insert(table, myhash(numtoadd), &key->entry, data, NULL);
|
||||
ref[numtoadd] = data;
|
||||
@@ -261,10 +244,10 @@ testadd(struct lruhash* table, struct testdata* ref[])
|
||||
|
||||
/** test adding a random element */
|
||||
static void
|
||||
testremove(struct lruhash* table, struct testdata* ref[])
|
||||
testremove(struct lruhash* table, testdata_t* ref[])
|
||||
{
|
||||
int num = random() % HASHTESTMAX;
|
||||
struct testkey* key = newkey(num);
|
||||
testkey_t* key = newkey(num);
|
||||
lruhash_remove(table, myhash(num), key);
|
||||
ref[num] = NULL;
|
||||
delkey(key);
|
||||
@@ -272,12 +255,12 @@ testremove(struct lruhash* table, struct testdata* ref[])
|
||||
|
||||
/** test adding a random element */
|
||||
static void
|
||||
testlookup(struct lruhash* table, struct testdata* ref[])
|
||||
testlookup(struct lruhash* table, testdata_t* ref[])
|
||||
{
|
||||
int num = random() % HASHTESTMAX;
|
||||
struct testkey* key = newkey(num);
|
||||
testkey_t* key = newkey(num);
|
||||
struct lruhash_entry* en = lruhash_lookup(table, myhash(num), key, 0);
|
||||
struct testdata* data = en? (struct testdata*)en->data : NULL;
|
||||
testdata_t* data = en? (testdata_t*)en->data : NULL;
|
||||
if(en) {
|
||||
unit_assert(en->key);
|
||||
unit_assert(en->data);
|
||||
@@ -321,17 +304,17 @@ check_table(struct lruhash* table)
|
||||
|
||||
/* this assertion is specific to the unit test */
|
||||
unit_assert( table->space_used ==
|
||||
table->num * test_sizefunc(NULL, NULL) );
|
||||
table->num * test_slabhash_sizefunc(NULL, NULL) );
|
||||
lock_quick_unlock(&table->lock);
|
||||
}
|
||||
|
||||
/** test adding a random element (unlimited range) */
|
||||
static void
|
||||
testadd_unlim(struct lruhash* table, struct testdata** ref)
|
||||
testadd_unlim(struct lruhash* table, testdata_t** ref)
|
||||
{
|
||||
int numtoadd = random() % (HASHTESTMAX * 10);
|
||||
struct testdata* data = newdata(numtoadd);
|
||||
struct testkey* key = newkey(numtoadd);
|
||||
testdata_t* data = newdata(numtoadd);
|
||||
testkey_t* key = newkey(numtoadd);
|
||||
key->entry.data = data;
|
||||
lruhash_insert(table, myhash(numtoadd), &key->entry, data, NULL);
|
||||
if(ref)
|
||||
@@ -340,10 +323,10 @@ testadd_unlim(struct lruhash* table, struct testdata** ref)
|
||||
|
||||
/** test adding a random element (unlimited range) */
|
||||
static void
|
||||
testremove_unlim(struct lruhash* table, struct testdata** ref)
|
||||
testremove_unlim(struct lruhash* table, testdata_t** ref)
|
||||
{
|
||||
int num = random() % (HASHTESTMAX*10);
|
||||
struct testkey* key = newkey(num);
|
||||
testkey_t* key = newkey(num);
|
||||
lruhash_remove(table, myhash(num), key);
|
||||
if(ref)
|
||||
ref[num] = NULL;
|
||||
@@ -352,12 +335,12 @@ testremove_unlim(struct lruhash* table, struct testdata** ref)
|
||||
|
||||
/** test adding a random element (unlimited range) */
|
||||
static void
|
||||
testlookup_unlim(struct lruhash* table, struct testdata** ref)
|
||||
testlookup_unlim(struct lruhash* table, testdata_t** ref)
|
||||
{
|
||||
int num = random() % (HASHTESTMAX*10);
|
||||
struct testkey* key = newkey(num);
|
||||
testkey_t* key = newkey(num);
|
||||
struct lruhash_entry* en = lruhash_lookup(table, myhash(num), key, 0);
|
||||
struct testdata* data = en? (struct testdata*)en->data : NULL;
|
||||
testdata_t* data = en? (testdata_t*)en->data : NULL;
|
||||
if(en) {
|
||||
unit_assert(en->key);
|
||||
unit_assert(en->data);
|
||||
@@ -377,17 +360,22 @@ static void
|
||||
test_long_table(struct lruhash* table)
|
||||
{
|
||||
/* assuming it all fits in the hastable, this check will work */
|
||||
struct testdata* ref[HASHTESTMAX * 100];
|
||||
testdata_t* ref[HASHTESTMAX * 100];
|
||||
size_t i;
|
||||
memset(ref, 0, sizeof(ref));
|
||||
/* test assumption */
|
||||
if(0) log_info(" size %d x %d < %d", (int)test_sizefunc(NULL, NULL),
|
||||
if(0) log_info(" size %d x %d < %d", (int)test_slabhash_sizefunc(NULL, NULL),
|
||||
(int)HASHTESTMAX, (int)table->space_max);
|
||||
unit_assert( test_sizefunc(NULL, NULL)*HASHTESTMAX < table->space_max);
|
||||
unit_assert( test_slabhash_sizefunc(NULL, NULL)*HASHTESTMAX < table->space_max);
|
||||
if(0) lruhash_status(table, "unit test", 1);
|
||||
srandom(48);
|
||||
for(i=0; i<1000; i++) {
|
||||
/* what to do? */
|
||||
if(i == 500) {
|
||||
lruhash_clear(table);
|
||||
memset(ref, 0, sizeof(ref));
|
||||
continue;
|
||||
}
|
||||
switch(random() % 4) {
|
||||
case 0:
|
||||
case 3:
|
||||
@@ -496,41 +484,16 @@ void lruhash_test()
|
||||
struct lruhash* table ;
|
||||
printf("lruhash test\n");
|
||||
table = lruhash_create(2, 4096,
|
||||
test_sizefunc, test_compfunc, test_delkey, test_deldata, NULL);
|
||||
test_slabhash_sizefunc, test_slabhash_compfunc,
|
||||
test_slabhash_delkey, test_slabhash_deldata, NULL);
|
||||
test_bin_find_entry(table);
|
||||
test_lru(table);
|
||||
test_short_table(table);
|
||||
test_long_table(table);
|
||||
lruhash_delete(table);
|
||||
table = lruhash_create(2, 4096,
|
||||
test_sizefunc, test_compfunc, test_delkey, test_deldata, NULL);
|
||||
test_slabhash_sizefunc, test_slabhash_compfunc,
|
||||
test_slabhash_delkey, test_slabhash_deldata, NULL);
|
||||
test_threaded_table(table);
|
||||
lruhash_delete(table);
|
||||
}
|
||||
|
||||
static size_t test_sizefunc(void* ATTR_UNUSED(key), void* ATTR_UNUSED(data))
|
||||
{
|
||||
return sizeof(struct testkey) + sizeof(struct testdata);
|
||||
}
|
||||
|
||||
static int test_compfunc(void* key1, void* key2)
|
||||
{
|
||||
struct testkey* k1 = (struct testkey*)key1;
|
||||
struct testkey* k2 = (struct testkey*)key2;
|
||||
if(k1->id == k2->id)
|
||||
return 0;
|
||||
if(k1->id > k2->id)
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void test_delkey(void* key, void* ATTR_UNUSED(arg), int l)
|
||||
{
|
||||
if(l) { lock_rw_unlock(&((struct testkey*)key)->entry.lock); }
|
||||
delkey((struct testkey*)key);
|
||||
}
|
||||
|
||||
static void test_deldata(void* data, void* ATTR_UNUSED(arg))
|
||||
{
|
||||
deldata((struct testdata*)data);
|
||||
}
|
||||
|
||||
+37
-11
@@ -124,17 +124,18 @@ net_test()
|
||||
static void
|
||||
rtt_test()
|
||||
{
|
||||
int init = 376;
|
||||
int i;
|
||||
struct rtt_info r;
|
||||
rtt_init(&r);
|
||||
/* initial value sensible */
|
||||
unit_assert( rtt_timeout(&r) == 3000 );
|
||||
unit_assert( rtt_timeout(&r) == init );
|
||||
rtt_lost(&r);
|
||||
unit_assert( rtt_timeout(&r) == 6000 );
|
||||
unit_assert( rtt_timeout(&r) == init*2 );
|
||||
rtt_lost(&r);
|
||||
unit_assert( rtt_timeout(&r) == 12000 );
|
||||
unit_assert( rtt_timeout(&r) == init*4 );
|
||||
rtt_update(&r, 4000);
|
||||
unit_assert( rtt_timeout(&r) >= 5000 );
|
||||
unit_assert( rtt_timeout(&r) >= 2000 );
|
||||
rtt_lost(&r);
|
||||
for(i=0; i<100; i++) {
|
||||
rtt_lost(&r);
|
||||
@@ -158,36 +159,37 @@ infra_test()
|
||||
int vs, to;
|
||||
struct infra_host_key* k;
|
||||
struct infra_host_data* d;
|
||||
int init = 376;
|
||||
|
||||
slab = infra_create(cfg);
|
||||
unit_assert( infra_host(slab, (struct sockaddr_storage*)&one,
|
||||
(socklen_t)sizeof(int), now, &vs, &to) );
|
||||
unit_assert( vs == 0 && to == 3000 );
|
||||
unit_assert( vs == 0 && to == init );
|
||||
|
||||
unit_assert( infra_rtt_update(slab, (struct sockaddr_storage*)&one,
|
||||
(socklen_t)sizeof(int), -1, now) );
|
||||
unit_assert( infra_host(slab, (struct sockaddr_storage*)&one,
|
||||
(socklen_t)sizeof(int), now, &vs, &to) );
|
||||
unit_assert( vs == 0 && to == 6000 );
|
||||
unit_assert( vs == 0 && to == init*2 );
|
||||
|
||||
unit_assert( infra_edns_update(slab, (struct sockaddr_storage*)&one,
|
||||
(socklen_t)sizeof(int), -1, now) );
|
||||
unit_assert( infra_host(slab, (struct sockaddr_storage*)&one,
|
||||
(socklen_t)sizeof(int), now, &vs, &to) );
|
||||
unit_assert( vs == -1 && to == 6000 );
|
||||
unit_assert( vs == -1 && to == init*2 );
|
||||
|
||||
now += cfg->host_ttl + 10;
|
||||
unit_assert( infra_host(slab, (struct sockaddr_storage*)&one,
|
||||
(socklen_t)sizeof(int), now, &vs, &to) );
|
||||
unit_assert( vs == 0 && to == 3000 );
|
||||
unit_assert( vs == 0 && to == init );
|
||||
|
||||
unit_assert( infra_set_lame(slab, (struct sockaddr_storage*)&one,
|
||||
(socklen_t)sizeof(int), zone, zonelen, now) );
|
||||
(socklen_t)sizeof(int), zone, zonelen, now, 0) );
|
||||
unit_assert( (d=infra_lookup_host(slab, (struct sockaddr_storage*)&one,
|
||||
(socklen_t)sizeof(int), 0, now, &k)) );
|
||||
unit_assert( d->ttl == now+cfg->host_ttl );
|
||||
unit_assert( d->edns_version == 0 );
|
||||
unit_assert( infra_lookup_lame(d, zone, zonelen, now) );
|
||||
unit_assert( infra_lookup_lame(d, zone, zonelen, now)==1 );
|
||||
unit_assert( !infra_lookup_lame(d, zone, zonelen,
|
||||
now+cfg->lame_ttl+10) );
|
||||
unit_assert( !infra_lookup_lame(d, (uint8_t*)"\000", 1, now) );
|
||||
@@ -197,6 +199,27 @@ infra_test()
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
#include "util/random.h"
|
||||
/** test randomness */
|
||||
static void
|
||||
rnd_test()
|
||||
{
|
||||
struct ub_randstate r;
|
||||
int num = 100, i;
|
||||
long int a[100];
|
||||
unit_assert( ub_initstate((unsigned)time(NULL), &r, 256) );
|
||||
for(i=0; i<num; i++) {
|
||||
a[i] = ub_random(&r);
|
||||
unit_assert(a[i] >= 0);
|
||||
unit_assert((size_t)a[i] <= (size_t)RAND_MAX);
|
||||
if(i > 5)
|
||||
unit_assert(a[i] != a[i-1] || a[i] != a[i-2] ||
|
||||
a[i] != a[i-3] || a[i] != a[i-4] ||
|
||||
a[i] != a[i-5] || a[i] != a[i-6]);
|
||||
}
|
||||
ub_randfree(&r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main unit test program. Setup, teardown and report errors.
|
||||
* @param argc: arg count.
|
||||
@@ -205,7 +228,7 @@ infra_test()
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
log_init(NULL);
|
||||
log_init(NULL, 0, NULL);
|
||||
if(argc != 1) {
|
||||
printf("usage: %s\n", argv[0]);
|
||||
printf("\tperforms unit tests.\n");
|
||||
@@ -213,8 +236,11 @@ main(int argc, char* argv[])
|
||||
}
|
||||
printf("Start of %s unit test.\n", PACKAGE_STRING);
|
||||
checklock_start();
|
||||
rnd_test();
|
||||
verify_test();
|
||||
net_test();
|
||||
dname_test();
|
||||
anchors_test();
|
||||
rtt_test();
|
||||
alloc_test();
|
||||
lruhash_test();
|
||||
|
||||
@@ -55,5 +55,9 @@ void slabhash_test();
|
||||
void msgparse_test();
|
||||
/** unit test dname handling functions */
|
||||
void dname_test();
|
||||
/** unit test trust anchor storage functions */
|
||||
void anchors_test();
|
||||
/** unit test for verification functions */
|
||||
void verify_test();
|
||||
|
||||
#endif /* TESTCODE_UNITMAIN_H */
|
||||
|
||||
+29
-18
@@ -45,12 +45,14 @@
|
||||
#include "util/data/msgreply.h"
|
||||
#include "util/data/msgencode.h"
|
||||
#include "util/alloc.h"
|
||||
#include "util/region-allocator.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/net_help.h"
|
||||
#include "testcode/readhex.h"
|
||||
|
||||
/** verbose message parse unit test */
|
||||
static int vbmp = 0;
|
||||
/** if matching within a section should disregard the order of RRs. */
|
||||
static int matches_nolocation = 0;
|
||||
|
||||
/** match two rr lists */
|
||||
static int
|
||||
@@ -65,18 +67,25 @@ match_list(ldns_rr_list* q, ldns_rr_list *p)
|
||||
}
|
||||
for(i=0; i<ldns_rr_list_rr_count(q); i++)
|
||||
{
|
||||
if(ldns_rr_compare(ldns_rr_list_rr(q, i),
|
||||
ldns_rr_list_rr(p, i)) != 0) {
|
||||
verbose(3, "rr %u different", (unsigned)i);
|
||||
return 0;
|
||||
if(matches_nolocation) {
|
||||
if(!ldns_rr_list_contains_rr(p, ldns_rr_list_rr(q, i)))
|
||||
{
|
||||
verbose(3, "rr %u not found", (unsigned)i);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if(ldns_rr_compare(ldns_rr_list_rr(q, i),
|
||||
ldns_rr_list_rr(p, i)) != 0) {
|
||||
verbose(3, "rr %u different", (unsigned)i);
|
||||
return 0;
|
||||
}
|
||||
/* and check the ttl */
|
||||
if(ldns_rr_ttl(ldns_rr_list_rr(q, i)) !=
|
||||
ldns_rr_ttl(ldns_rr_list_rr(p, i))) {
|
||||
verbose(3, "rr %u ttl different", (unsigned)i);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* and check the ttl */
|
||||
if(ldns_rr_ttl(ldns_rr_list_rr(q, i)) !=
|
||||
ldns_rr_ttl(ldns_rr_list_rr(p, i))) {
|
||||
verbose(3, "rr %u ttl different", (unsigned)i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -197,10 +206,8 @@ test_buffers(ldns_buffer* pkt, ldns_buffer* out)
|
||||
s1 = ldns_buffer2pkt_wire(&p1, pkt);
|
||||
s2 = ldns_buffer2pkt_wire(&p2, out);
|
||||
if(vbmp) {
|
||||
log_hex("orig in hex", ldns_buffer_begin(pkt),
|
||||
ldns_buffer_limit(pkt));
|
||||
log_hex("unbound out in hex", ldns_buffer_begin(out),
|
||||
ldns_buffer_limit(out));
|
||||
log_buf(0, "orig in hex", pkt);
|
||||
log_buf(0, "unbound out in hex", out);
|
||||
printf("\npacket from unbound (%d):\n",
|
||||
(int)ldns_buffer_limit(out));
|
||||
ldns_pkt_print(stdout, p2);
|
||||
@@ -251,7 +258,7 @@ testpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
|
||||
uint16_t id;
|
||||
uint16_t flags;
|
||||
uint32_t timenow = 0;
|
||||
region_type *region = region_create(malloc, free);
|
||||
struct regional* region = regional_create();
|
||||
struct edns_data edns;
|
||||
|
||||
hex_to_buf(pkt, hex);
|
||||
@@ -300,7 +307,7 @@ testpkt(ldns_buffer* pkt, struct alloc_cache* alloc, ldns_buffer* out,
|
||||
|
||||
query_info_clear(&qi);
|
||||
reply_info_parsedelete(rep, alloc);
|
||||
region_destroy(region);
|
||||
regional_destroy(region);
|
||||
}
|
||||
|
||||
/** simple test of parsing */
|
||||
@@ -433,6 +440,10 @@ void msgparse_test()
|
||||
testfromdrillfile(pkt, &alloc, out, "testdata/test_packets.4");
|
||||
testfromdrillfile(pkt, &alloc, out, "testdata/test_packets.5");
|
||||
|
||||
matches_nolocation = 1; /* RR order not important for the next test */
|
||||
testfromdrillfile(pkt, &alloc, out, "testdata/test_packets.6");
|
||||
matches_nolocation = 0;
|
||||
|
||||
/* cleanup */
|
||||
alloc_clear(&alloc);
|
||||
alloc_clear(&super_a);
|
||||
|
||||
+43
-83
@@ -43,29 +43,14 @@
|
||||
#include "util/log.h"
|
||||
#include "util/storage/slabhash.h"
|
||||
|
||||
/* --- test representation --- */
|
||||
/** structure contains test key */
|
||||
struct slabtestkey {
|
||||
/** the key id */
|
||||
int id;
|
||||
/** the entry */
|
||||
struct lruhash_entry entry;
|
||||
};
|
||||
/** structure contains test data */
|
||||
struct slabtestdata {
|
||||
/** data value */
|
||||
int data;
|
||||
};
|
||||
/** use this type for the slabhash test key */
|
||||
typedef struct slabhash_testkey testkey_t;
|
||||
/** use this type for the slabhash test data */
|
||||
typedef struct slabhash_testdata testdata_t;
|
||||
|
||||
/** sizefunc for lruhash */
|
||||
static size_t test_sizefunc(void*, void*);
|
||||
/** comparefunc for lruhash */
|
||||
static int test_compfunc(void*, void*);
|
||||
/** delkey for lruhash */
|
||||
static void test_delkey(void*, void*, int);
|
||||
/** deldata for lruhash */
|
||||
static void test_deldata(void*, void*);
|
||||
/* --- end test representation --- */
|
||||
/** delete key */
|
||||
static void delkey(struct slabhash_testkey* k) {
|
||||
lock_rw_destroy(&k->entry.lock); free(k);}
|
||||
|
||||
/** hash func, very bad to improve collisions, both high and low bits */
|
||||
static hashvalue_t myhash(int id) {
|
||||
@@ -75,8 +60,8 @@ static hashvalue_t myhash(int id) {
|
||||
}
|
||||
|
||||
/** allocate new key, fill in hash */
|
||||
static struct slabtestkey* newkey(int id) {
|
||||
struct slabtestkey* k = (struct slabtestkey*)calloc(1, sizeof(struct slabtestkey));
|
||||
static testkey_t* newkey(int id) {
|
||||
testkey_t* k = (testkey_t*)calloc(1, sizeof(testkey_t));
|
||||
if(!k) fatal_exit("out of memory");
|
||||
k->id = id;
|
||||
k->entry.hash = myhash(id);
|
||||
@@ -85,27 +70,22 @@ static struct slabtestkey* newkey(int id) {
|
||||
return k;
|
||||
}
|
||||
/** new data el */
|
||||
static struct slabtestdata* newdata(int val) {
|
||||
struct slabtestdata* d = (struct slabtestdata*)calloc(1,
|
||||
sizeof(struct slabtestdata));
|
||||
static testdata_t* newdata(int val) {
|
||||
testdata_t* d = (testdata_t*)calloc(1,
|
||||
sizeof(testdata_t));
|
||||
if(!d) fatal_exit("out of memory");
|
||||
d->data = val;
|
||||
return d;
|
||||
}
|
||||
/** delete key */
|
||||
static void delkey(struct slabtestkey* k) {
|
||||
lock_rw_destroy(&k->entry.lock); free(k);}
|
||||
/** delete data */
|
||||
static void deldata(struct slabtestdata* d) {free(d);}
|
||||
|
||||
/** test hashtable using short sequence */
|
||||
static void
|
||||
test_short_table(struct slabhash* table)
|
||||
{
|
||||
struct slabtestkey* k = newkey(12);
|
||||
struct slabtestkey* k2 = newkey(14);
|
||||
struct slabtestdata* d = newdata(128);
|
||||
struct slabtestdata* d2 = newdata(129);
|
||||
testkey_t* k = newkey(12);
|
||||
testkey_t* k2 = newkey(14);
|
||||
testdata_t* d = newdata(128);
|
||||
testdata_t* d2 = newdata(129);
|
||||
|
||||
k->entry.data = d;
|
||||
k2->entry.data = d2;
|
||||
@@ -126,11 +106,11 @@ test_short_table(struct slabhash* table)
|
||||
|
||||
/** test adding a random element */
|
||||
static void
|
||||
testadd(struct slabhash* table, struct slabtestdata* ref[])
|
||||
testadd(struct slabhash* table, testdata_t* ref[])
|
||||
{
|
||||
int numtoadd = random() % HASHTESTMAX;
|
||||
struct slabtestdata* data = newdata(numtoadd);
|
||||
struct slabtestkey* key = newkey(numtoadd);
|
||||
testdata_t* data = newdata(numtoadd);
|
||||
testkey_t* key = newkey(numtoadd);
|
||||
key->entry.data = data;
|
||||
slabhash_insert(table, myhash(numtoadd), &key->entry, data, NULL);
|
||||
ref[numtoadd] = data;
|
||||
@@ -138,10 +118,10 @@ testadd(struct slabhash* table, struct slabtestdata* ref[])
|
||||
|
||||
/** test adding a random element */
|
||||
static void
|
||||
testremove(struct slabhash* table, struct slabtestdata* ref[])
|
||||
testremove(struct slabhash* table, testdata_t* ref[])
|
||||
{
|
||||
int num = random() % HASHTESTMAX;
|
||||
struct slabtestkey* key = newkey(num);
|
||||
testkey_t* key = newkey(num);
|
||||
slabhash_remove(table, myhash(num), key);
|
||||
ref[num] = NULL;
|
||||
delkey(key);
|
||||
@@ -149,12 +129,12 @@ testremove(struct slabhash* table, struct slabtestdata* ref[])
|
||||
|
||||
/** test adding a random element */
|
||||
static void
|
||||
testlookup(struct slabhash* table, struct slabtestdata* ref[])
|
||||
testlookup(struct slabhash* table, testdata_t* ref[])
|
||||
{
|
||||
int num = random() % HASHTESTMAX;
|
||||
struct slabtestkey* key = newkey(num);
|
||||
testkey_t* key = newkey(num);
|
||||
struct lruhash_entry* en = slabhash_lookup(table, myhash(num), key, 0);
|
||||
struct slabtestdata* data = en? (struct slabtestdata*)en->data : NULL;
|
||||
testdata_t* data = en? (testdata_t*)en->data : NULL;
|
||||
if(en) {
|
||||
unit_assert(en->key);
|
||||
unit_assert(en->data);
|
||||
@@ -198,7 +178,7 @@ check_lru_table(struct lruhash* table)
|
||||
|
||||
/* this assertion is specific to the unit test */
|
||||
unit_assert( table->space_used ==
|
||||
table->num * test_sizefunc(NULL, NULL) );
|
||||
table->num * test_slabhash_sizefunc(NULL, NULL) );
|
||||
lock_quick_unlock(&table->lock);
|
||||
}
|
||||
|
||||
@@ -213,11 +193,11 @@ check_table(struct slabhash* table)
|
||||
|
||||
/** test adding a random element (unlimited range) */
|
||||
static void
|
||||
testadd_unlim(struct slabhash* table, struct slabtestdata** ref)
|
||||
testadd_unlim(struct slabhash* table, testdata_t** ref)
|
||||
{
|
||||
int numtoadd = random() % (HASHTESTMAX * 10);
|
||||
struct slabtestdata* data = newdata(numtoadd);
|
||||
struct slabtestkey* key = newkey(numtoadd);
|
||||
testdata_t* data = newdata(numtoadd);
|
||||
testkey_t* key = newkey(numtoadd);
|
||||
key->entry.data = data;
|
||||
slabhash_insert(table, myhash(numtoadd), &key->entry, data, NULL);
|
||||
if(ref)
|
||||
@@ -226,10 +206,10 @@ testadd_unlim(struct slabhash* table, struct slabtestdata** ref)
|
||||
|
||||
/** test adding a random element (unlimited range) */
|
||||
static void
|
||||
testremove_unlim(struct slabhash* table, struct slabtestdata** ref)
|
||||
testremove_unlim(struct slabhash* table, testdata_t** ref)
|
||||
{
|
||||
int num = random() % (HASHTESTMAX*10);
|
||||
struct slabtestkey* key = newkey(num);
|
||||
testkey_t* key = newkey(num);
|
||||
slabhash_remove(table, myhash(num), key);
|
||||
if(ref)
|
||||
ref[num] = NULL;
|
||||
@@ -238,12 +218,12 @@ testremove_unlim(struct slabhash* table, struct slabtestdata** ref)
|
||||
|
||||
/** test adding a random element (unlimited range) */
|
||||
static void
|
||||
testlookup_unlim(struct slabhash* table, struct slabtestdata** ref)
|
||||
testlookup_unlim(struct slabhash* table, testdata_t** ref)
|
||||
{
|
||||
int num = random() % (HASHTESTMAX*10);
|
||||
struct slabtestkey* key = newkey(num);
|
||||
testkey_t* key = newkey(num);
|
||||
struct lruhash_entry* en = slabhash_lookup(table, myhash(num), key, 0);
|
||||
struct slabtestdata* data = en? (struct slabtestdata*)en->data : NULL;
|
||||
testdata_t* data = en? (testdata_t*)en->data : NULL;
|
||||
if(en) {
|
||||
unit_assert(en->key);
|
||||
unit_assert(en->data);
|
||||
@@ -263,7 +243,7 @@ static void
|
||||
test_long_table(struct slabhash* table)
|
||||
{
|
||||
/* assuming it all fits in the hastable, this check will work */
|
||||
struct slabtestdata* ref[HASHTESTMAX * 100];
|
||||
testdata_t* ref[HASHTESTMAX * 100];
|
||||
size_t i;
|
||||
memset(ref, 0, sizeof(ref));
|
||||
/* test assumption */
|
||||
@@ -271,6 +251,11 @@ test_long_table(struct slabhash* table)
|
||||
srandom(48);
|
||||
for(i=0; i<1000; i++) {
|
||||
/* what to do? */
|
||||
if(i == 500) {
|
||||
slabhash_clear(table);
|
||||
memset(ref, 0, sizeof(ref));
|
||||
continue;
|
||||
}
|
||||
switch(random() % 4) {
|
||||
case 0:
|
||||
case 3:
|
||||
@@ -378,39 +363,14 @@ void slabhash_test()
|
||||
struct slabhash* table;
|
||||
printf("slabhash test\n");
|
||||
table = slabhash_create(4, 2, 5200,
|
||||
test_sizefunc, test_compfunc, test_delkey, test_deldata, NULL);
|
||||
test_slabhash_sizefunc, test_slabhash_compfunc,
|
||||
test_slabhash_delkey, test_slabhash_deldata, NULL);
|
||||
test_short_table(table);
|
||||
test_long_table(table);
|
||||
slabhash_delete(table);
|
||||
table = slabhash_create(4, 2, 5200,
|
||||
test_sizefunc, test_compfunc, test_delkey, test_deldata, NULL);
|
||||
test_slabhash_sizefunc, test_slabhash_compfunc,
|
||||
test_slabhash_delkey, test_slabhash_deldata, NULL);
|
||||
test_threaded_table(table);
|
||||
slabhash_delete(table);
|
||||
}
|
||||
|
||||
static size_t test_sizefunc(void* ATTR_UNUSED(key), void* ATTR_UNUSED(data))
|
||||
{
|
||||
return sizeof(struct slabtestkey) + sizeof(struct slabtestdata);
|
||||
}
|
||||
|
||||
static int test_compfunc(void* key1, void* key2)
|
||||
{
|
||||
struct slabtestkey* k1 = (struct slabtestkey*)key1;
|
||||
struct slabtestkey* k2 = (struct slabtestkey*)key2;
|
||||
if(k1->id == k2->id)
|
||||
return 0;
|
||||
if(k1->id > k2->id)
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void test_delkey(void* key, void* ATTR_UNUSED(arg), int l)
|
||||
{
|
||||
if(l) { lock_rw_unlock(&((struct slabtestkey*)key)->entry.lock); }
|
||||
delkey((struct slabtestkey*)key);
|
||||
}
|
||||
|
||||
static void test_deldata(void* data, void* ATTR_UNUSED(arg))
|
||||
{
|
||||
deldata((struct slabtestdata*)data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,465 @@
|
||||
/*
|
||||
* testcode/unitverify.c - unit test for signature verification routines.
|
||||
*
|
||||
* Copyright (c) 2007, 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
|
||||
* Calls verification unit tests. Exits with code 1 on a failure.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "util/log.h"
|
||||
#include "testcode/unitmain.h"
|
||||
#include "validator/val_sigcrypt.h"
|
||||
#include "validator/val_nsec.h"
|
||||
#include "validator/val_nsec3.h"
|
||||
#include "validator/validator.h"
|
||||
#include "testcode/ldns-testpkts.h"
|
||||
#include "util/data/msgreply.h"
|
||||
#include "util/data/msgparse.h"
|
||||
#include "util/data/dname.h"
|
||||
#include "util/regional.h"
|
||||
#include "util/alloc.h"
|
||||
#include "util/rbtree.h"
|
||||
#include "util/net_help.h"
|
||||
#include "util/module.h"
|
||||
#include "util/config_file.h"
|
||||
|
||||
/** verbose signature test */
|
||||
static int vsig = 0;
|
||||
|
||||
/** entry to packet buffer with wireformat */
|
||||
static void
|
||||
entry_to_buf(struct entry* e, ldns_buffer* pkt)
|
||||
{
|
||||
unit_assert(e->reply_list);
|
||||
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_flip(pkt);
|
||||
free(ans);
|
||||
}
|
||||
}
|
||||
|
||||
/** entry to reply info conversion */
|
||||
static void
|
||||
entry_to_repinfo(struct entry* e, struct alloc_cache* alloc,
|
||||
struct regional* region, ldns_buffer* pkt, struct query_info* qi,
|
||||
struct reply_info** rep)
|
||||
{
|
||||
int ret;
|
||||
struct edns_data edns;
|
||||
entry_to_buf(e, pkt);
|
||||
/* lock alloc lock to please lock checking software.
|
||||
* alloc_special_obtain assumes it is talking to a ub-alloc,
|
||||
* and does not need to perform locking. Here the alloc is
|
||||
* the only one, so we lock it here */
|
||||
lock_quick_lock(&alloc->lock);
|
||||
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);
|
||||
unit_assert(ret != 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** extract DNSKEY rrset from answer and convert it */
|
||||
static struct ub_packed_rrset_key*
|
||||
extract_keys(struct entry* e, struct alloc_cache* alloc,
|
||||
struct regional* region, ldns_buffer* pkt)
|
||||
{
|
||||
struct ub_packed_rrset_key* dnskey = NULL;
|
||||
struct query_info qinfo;
|
||||
struct reply_info* rep = NULL;
|
||||
size_t i;
|
||||
|
||||
entry_to_repinfo(e, alloc, region, pkt, &qinfo, &rep);
|
||||
for(i=0; i<rep->an_numrrsets; i++) {
|
||||
if(ntohs(rep->rrsets[i]->rk.type) == LDNS_RR_TYPE_DNSKEY) {
|
||||
dnskey = rep->rrsets[i];
|
||||
rep->rrsets[i] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
unit_assert(dnskey);
|
||||
|
||||
reply_info_parsedelete(rep, alloc);
|
||||
query_info_clear(&qinfo);
|
||||
return dnskey;
|
||||
}
|
||||
|
||||
/** return true if answer should be bogus */
|
||||
static int
|
||||
should_be_bogus(struct ub_packed_rrset_key* rrset)
|
||||
{
|
||||
struct packed_rrset_data* d = (struct packed_rrset_data*)rrset->
|
||||
entry.data;
|
||||
if(d->rrsig_count == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** verify and test one rrset against the key rrset */
|
||||
static void
|
||||
verifytest_rrset(struct module_env* env, struct val_env* ve,
|
||||
struct ub_packed_rrset_key* rrset, struct ub_packed_rrset_key* dnskey)
|
||||
{
|
||||
enum sec_status sec;
|
||||
if(vsig) {
|
||||
log_nametypeclass(VERB_DETAIL, "verify of rrset",
|
||||
rrset->rk.dname, ntohs(rrset->rk.type),
|
||||
ntohs(rrset->rk.rrset_class));
|
||||
}
|
||||
sec = dnskeyset_verify_rrset(env, ve, rrset, dnskey);
|
||||
if(vsig) {
|
||||
printf("verify outcome is: %s\n", sec_status_to_string(sec));
|
||||
}
|
||||
if(should_be_bogus(rrset)) {
|
||||
unit_assert(sec == sec_status_bogus);
|
||||
} else {
|
||||
unit_assert(sec == sec_status_secure);
|
||||
}
|
||||
}
|
||||
|
||||
/** verify and test an entry - every rr in the message */
|
||||
static void
|
||||
verifytest_entry(struct entry* e, struct alloc_cache* alloc,
|
||||
struct regional* region, ldns_buffer* pkt,
|
||||
struct ub_packed_rrset_key* dnskey, struct module_env* env,
|
||||
struct val_env* ve)
|
||||
{
|
||||
struct query_info qinfo;
|
||||
struct reply_info* rep = NULL;
|
||||
size_t i;
|
||||
|
||||
regional_free_all(region);
|
||||
if(vsig) {
|
||||
printf("verifying pkt:\n");
|
||||
ldns_pkt_print(stdout, e->reply_list->reply);
|
||||
printf("\n");
|
||||
}
|
||||
entry_to_repinfo(e, alloc, region, pkt, &qinfo, &rep);
|
||||
|
||||
for(i=0; i<rep->rrset_count; i++) {
|
||||
verifytest_rrset(env, ve, rep->rrsets[i], dnskey);
|
||||
}
|
||||
|
||||
reply_info_parsedelete(rep, alloc);
|
||||
query_info_clear(&qinfo);
|
||||
}
|
||||
|
||||
/** find RRset in reply by type */
|
||||
static struct ub_packed_rrset_key*
|
||||
find_rrset_type(struct reply_info* rep, uint16_t type)
|
||||
{
|
||||
size_t i;
|
||||
for(i=0; i<rep->rrset_count; i++) {
|
||||
if(ntohs(rep->rrsets[i]->rk.type) == type)
|
||||
return rep->rrsets[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** DS sig test an entry - get DNSKEY and DS in entry and verify */
|
||||
static void
|
||||
dstest_entry(struct entry* e, struct alloc_cache* alloc,
|
||||
struct regional* region, ldns_buffer* pkt, struct module_env* env)
|
||||
{
|
||||
struct query_info qinfo;
|
||||
struct reply_info* rep = NULL;
|
||||
struct ub_packed_rrset_key* ds, *dnskey;
|
||||
int ret;
|
||||
|
||||
regional_free_all(region);
|
||||
if(vsig) {
|
||||
printf("verifying DS-DNSKEY match:\n");
|
||||
ldns_pkt_print(stdout, e->reply_list->reply);
|
||||
printf("\n");
|
||||
}
|
||||
entry_to_repinfo(e, alloc, region, pkt, &qinfo, &rep);
|
||||
ds = find_rrset_type(rep, LDNS_RR_TYPE_DS);
|
||||
dnskey = find_rrset_type(rep, LDNS_RR_TYPE_DNSKEY);
|
||||
/* check test is OK */
|
||||
unit_assert(ds && dnskey);
|
||||
|
||||
ret = ds_digest_match_dnskey(env, dnskey, 0, ds, 0);
|
||||
if(strncmp((char*)qinfo.qname, "\003yes", 4) == 0) {
|
||||
if(vsig) {
|
||||
printf("result(yes)= %s\n", ret?"yes":"no");
|
||||
}
|
||||
unit_assert(ret);
|
||||
} else if (strncmp((char*)qinfo.qname, "\002no", 3) == 0) {
|
||||
if(vsig) {
|
||||
printf("result(no)= %s\n", ret?"yes":"no");
|
||||
}
|
||||
unit_assert(!ret);
|
||||
verbose(VERB_DETAIL, "DS fail: OK; matched unit test");
|
||||
} else {
|
||||
fatal_exit("Bad qname in DS unit test, yes or no");
|
||||
}
|
||||
|
||||
reply_info_parsedelete(rep, alloc);
|
||||
query_info_clear(&qinfo);
|
||||
}
|
||||
|
||||
/** verify from a file */
|
||||
static void
|
||||
verifytest_file(const char* fname, const char* at_date)
|
||||
{
|
||||
/*
|
||||
* The file contains a list of ldns-testpkts entries.
|
||||
* The first entry must be a query for DNSKEY.
|
||||
* The answer rrset is the keyset that will be used for verification
|
||||
*/
|
||||
struct ub_packed_rrset_key* dnskey;
|
||||
struct regional* region = regional_create();
|
||||
struct alloc_cache alloc;
|
||||
ldns_buffer* buf = ldns_buffer_new(65535);
|
||||
struct entry* e;
|
||||
struct entry* list = read_datafile(fname);
|
||||
struct module_env env;
|
||||
struct val_env ve;
|
||||
|
||||
if(!list)
|
||||
fatal_exit("could not read %s: %s", fname, strerror(errno));
|
||||
alloc_init(&alloc, NULL, 1);
|
||||
memset(&env, 0, sizeof(env));
|
||||
memset(&ve, 0, sizeof(ve));
|
||||
env.scratch = region;
|
||||
env.scratch_buffer = buf;
|
||||
ve.date_override = cfg_convert_timeval(at_date);
|
||||
unit_assert(region && buf);
|
||||
dnskey = extract_keys(list, &alloc, region, buf);
|
||||
if(vsig) log_nametypeclass(VERB_DETAIL, "test dnskey",
|
||||
dnskey->rk.dname, ntohs(dnskey->rk.type),
|
||||
ntohs(dnskey->rk.rrset_class));
|
||||
/* ready to go! */
|
||||
for(e = list->next; e; e = e->next) {
|
||||
verifytest_entry(e, &alloc, region, buf, dnskey, &env, &ve);
|
||||
}
|
||||
|
||||
ub_packed_rrset_parsedelete(dnskey, &alloc);
|
||||
delete_entry(list);
|
||||
regional_destroy(region);
|
||||
alloc_clear(&alloc);
|
||||
ldns_buffer_free(buf);
|
||||
}
|
||||
|
||||
/** verify DS matches DNSKEY from a file */
|
||||
static void
|
||||
dstest_file(const char* fname)
|
||||
{
|
||||
/*
|
||||
* The file contains a list of ldns-testpkts entries.
|
||||
* The first entry must be a query for DNSKEY.
|
||||
* The answer rrset is the keyset that will be used for verification
|
||||
*/
|
||||
struct regional* region = regional_create();
|
||||
struct alloc_cache alloc;
|
||||
ldns_buffer* buf = ldns_buffer_new(65535);
|
||||
struct entry* e;
|
||||
struct entry* list = read_datafile(fname);
|
||||
struct module_env env;
|
||||
|
||||
if(!list)
|
||||
fatal_exit("could not read %s: %s", fname, strerror(errno));
|
||||
alloc_init(&alloc, NULL, 1);
|
||||
memset(&env, 0, sizeof(env));
|
||||
env.scratch = region;
|
||||
env.scratch_buffer = buf;
|
||||
unit_assert(region && buf);
|
||||
|
||||
/* ready to go! */
|
||||
for(e = list; e; e = e->next) {
|
||||
dstest_entry(e, &alloc, region, buf, &env);
|
||||
}
|
||||
|
||||
delete_entry(list);
|
||||
regional_destroy(region);
|
||||
alloc_clear(&alloc);
|
||||
ldns_buffer_free(buf);
|
||||
}
|
||||
|
||||
/** helper for unittest of NSEC routines */
|
||||
static int
|
||||
unitest_nsec_has_type_rdata(char* bitmap, size_t len, uint16_t type)
|
||||
{
|
||||
return nsecbitmap_has_type_rdata((uint8_t*)bitmap, len, type);
|
||||
}
|
||||
|
||||
/** Test NSEC type bitmap routine */
|
||||
static void
|
||||
nsectest()
|
||||
{
|
||||
/* bitmap starts at type bitmap rdata field */
|
||||
/* from rfc 4034 example */
|
||||
char* bitmap = "\000\006\100\001\000\000\000\003"
|
||||
"\004\033\000\000\000\000\000\000"
|
||||
"\000\000\000\000\000\000\000\000"
|
||||
"\000\000\000\000\000\000\000\000"
|
||||
"\000\000\000\000\040";
|
||||
size_t len = 37;
|
||||
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 0));
|
||||
unit_assert(unitest_nsec_has_type_rdata(bitmap, len, LDNS_RR_TYPE_A));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 2));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 3));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 4));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 5));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 6));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 7));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 8));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 9));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 10));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 11));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 12));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 13));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 14));
|
||||
unit_assert(unitest_nsec_has_type_rdata(bitmap, len, LDNS_RR_TYPE_MX));
|
||||
unit_assert(unitest_nsec_has_type_rdata(bitmap, len, LDNS_RR_TYPE_RRSIG));
|
||||
unit_assert(unitest_nsec_has_type_rdata(bitmap, len, LDNS_RR_TYPE_NSEC));
|
||||
unit_assert(unitest_nsec_has_type_rdata(bitmap, len, 1234));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 1233));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 1235));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 1236));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 1237));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 1238));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 1239));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 1240));
|
||||
unit_assert(!unitest_nsec_has_type_rdata(bitmap, len, 2230));
|
||||
}
|
||||
|
||||
/** Test hash algo - NSEC3 hash it and compare result */
|
||||
static void
|
||||
nsec3_hash_test_entry(struct entry* e, rbtree_t* ct,
|
||||
struct alloc_cache* alloc, struct regional* region,
|
||||
ldns_buffer* buf)
|
||||
{
|
||||
struct query_info qinfo;
|
||||
struct reply_info* rep = NULL;
|
||||
struct ub_packed_rrset_key* answer, *nsec3;
|
||||
struct nsec3_cached_hash* hash;
|
||||
int ret;
|
||||
uint8_t* qname;
|
||||
|
||||
if(vsig) {
|
||||
printf("verifying NSEC3 hash:\n");
|
||||
ldns_pkt_print(stdout, e->reply_list->reply);
|
||||
printf("\n");
|
||||
}
|
||||
entry_to_repinfo(e, alloc, region, buf, &qinfo, &rep);
|
||||
nsec3 = find_rrset_type(rep, LDNS_RR_TYPE_NSEC3);
|
||||
answer = find_rrset_type(rep, LDNS_RR_TYPE_AAAA);
|
||||
qname = regional_alloc_init(region, qinfo.qname, qinfo.qname_len);
|
||||
/* check test is OK */
|
||||
unit_assert(nsec3 && answer && qname);
|
||||
|
||||
ret = nsec3_hash_name(ct, region, buf, nsec3, 0, qname,
|
||||
qinfo.qname_len, &hash);
|
||||
if(ret != 1) {
|
||||
printf("Bad nsec3_hash_name retcode %d\n", ret);
|
||||
unit_assert(ret == 1);
|
||||
}
|
||||
unit_assert(hash->dname && hash->hash && hash->hash_len &&
|
||||
hash->b32 && hash->b32_len);
|
||||
unit_assert(hash->b32_len == (size_t)answer->rk.dname[0]);
|
||||
/* does not do lowercasing. */
|
||||
unit_assert(memcmp(hash->b32, answer->rk.dname+1, hash->b32_len)
|
||||
== 0);
|
||||
|
||||
reply_info_parsedelete(rep, alloc);
|
||||
query_info_clear(&qinfo);
|
||||
}
|
||||
|
||||
|
||||
/** Read file to test NSEC3 hash algo */
|
||||
static void
|
||||
nsec3_hash_test(const char* fname)
|
||||
{
|
||||
/*
|
||||
* The list contains a list of ldns-testpkts entries.
|
||||
* Every entry is a test.
|
||||
* The qname is hashed.
|
||||
* The answer section AAAA RR name is the required result.
|
||||
* The auth section NSEC3 is used to get hash parameters.
|
||||
* The hash cache is maintained per file.
|
||||
*
|
||||
* The test does not perform canonicalization during the compare.
|
||||
*/
|
||||
rbtree_t ct;
|
||||
struct regional* region = regional_create();
|
||||
struct alloc_cache alloc;
|
||||
ldns_buffer* buf = ldns_buffer_new(65535);
|
||||
struct entry* e;
|
||||
struct entry* list = read_datafile(fname);
|
||||
|
||||
if(!list)
|
||||
fatal_exit("could not read %s: %s", fname, strerror(errno));
|
||||
rbtree_init(&ct, &nsec3_hash_cmp);
|
||||
alloc_init(&alloc, NULL, 1);
|
||||
unit_assert(region && buf);
|
||||
|
||||
/* ready to go! */
|
||||
for(e = list; e; e = e->next) {
|
||||
nsec3_hash_test_entry(e, &ct, &alloc, region, buf);
|
||||
}
|
||||
|
||||
delete_entry(list);
|
||||
regional_destroy(region);
|
||||
alloc_clear(&alloc);
|
||||
ldns_buffer_free(buf);
|
||||
}
|
||||
|
||||
void
|
||||
verify_test()
|
||||
{
|
||||
printf("verify test\n");
|
||||
verifytest_file("testdata/test_signatures.1", "20070818005004");
|
||||
dstest_file("testdata/test_ds_sig.1");
|
||||
nsectest();
|
||||
nsec3_hash_test("testdata/test_nsec3_hash.1");
|
||||
}
|
||||
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
+1
@@ -0,0 +1 @@
|
||||
example.com. 3600 IN DS 2854 3 1 46e4ffc6e9a4793b488954bd3f0cc6af0dfb201b
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
example.com. 3600 IN DNSKEY 256 3 3 ALXLUsWqUrY3JYER3T4TBJIIs70j+sDS/UT2QRp61SE7S3EEXopNXoFE73JLRmvpi/UrOO/Vz4Se6wXv/CYCKjGw06U4WRgRYXcpEhJROyNapmdIKSxhOzfLVE1gqA0PweZR8dtY3aNQSRn3sPpwJr6Mi/PqQKAMMrZ9ckJpf1+bQMOOvxgzz2U1GS18b3yZKcgTMEaJzd/GZYzi/BN2DzQ0MsrSwYXfsNLFOBbs8PJMW4LYIxeeOe6rUgkWOF7CC9Dh/dduQ1QrsJhmZAEFfd6ByYV+ ;{id = 2854 (zsk), size = 1688b}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
Private-key-format: v1.2
|
||||
Algorithm: 3 (DSA)
|
||||
Prime(p): +sDS/UT2QRp61SE7S3EEXopNXoFE73JLRmvpi/UrOO/Vz4Se6wXv/CYCKjGw06U4WRgRYXcpEhJROyNapmdIKQ==
|
||||
Subprime(q): tctSxapStjclgRHdPhMEkgizvSM=
|
||||
Base(g): LGE7N8tUTWCoDQ/B5lHx21jdo1BJGfew+nAmvoyL8+pAoAwytn1yQml/X5tAw46/GDPPZTUZLXxvfJkpyBMwRg==
|
||||
Private_value(x): XMs4XYi1oNckzTPvGMkgG5IiuzY=
|
||||
Public_value(y): ic3fxmWM4vwTdg80NDLK0sGF37DSxTgW7PDyTFuC2CMXnjnuq1IJFjhewgvQ4f3XbkNUK7CYZmQBBX3egcmFfg==
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
example.com. 3600 IN DS 30899 5 1 d4bf9d2e10f6d76840d42ef5913022abcd0bf512
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
example.com. 3600 IN DNSKEY 256 3 5 AQPQ41chR9DEHt/aIzIFAqanbDlRflJoRs5yz1jFsoRIT7dWf0r+PeDuewdxkszNH6wnU4QL8pfKFRh5PIYVBLK3 ;{id = 30899 (zsk), size = 512b}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
Private-key-format: v1.2
|
||||
Algorithm: 5 (RSASHA1)
|
||||
Modulus: 0ONXIUfQxB7f2iMyBQKmp2w5UX5SaEbOcs9YxbKESE+3Vn9K/j3g7nsHcZLMzR+sJ1OEC/KXyhUYeTyGFQSytw==
|
||||
PublicExponent: Aw==
|
||||
PrivateExponent: i0I6Fi/ggr8/5sIhWKxvGkgmNlQ28C80TIo7LncC2t6ar2Q5rpyiDxEHvFLfphRh108ZOqf2tQdHx7tXTx5Gqw==
|
||||
Prime1: 9WS85Q92ilTAuGiVi+KesKzrFqF98l2Gpu4003hfmbc=
|
||||
Prime2: 2eqsD2jcY4Mgw26A8XFiaLdxx5J4s10Dhd9ur6X3rwE=
|
||||
Exponent1: o5h97gpPBuMrJZsOXUG/IHNHZGupTD5ZxJ7N4lA/u88=
|
||||
Exponent2: kUcdX5s9l6zAgkmrS6DsRc+hL7b7Ij4CWT+fH8P6dKs=
|
||||
Coefficient: PVZrElFmz9tWa4kwu9jArjcocycYu0eBycgguQ03J7w=
|
||||
Vendored
+161
@@ -0,0 +1,161 @@
|
||||
; config options
|
||||
stub-zone:
|
||||
name: "."
|
||||
stub-addr: 193.0.14.129 # K.ROOT-SERVERS.NET.
|
||||
CONFIG_END
|
||||
|
||||
SCENARIO_BEGIN Fetch cnamed glue when missing or timed out.
|
||||
|
||||
; 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 qtype qname
|
||||
ADJUST copy_id
|
||||
REPLY QR NOERROR
|
||||
SECTION QUESTION
|
||||
www.example.com. IN A
|
||||
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
|
||||
www.example.com. IN A
|
||||
SECTION AUTHORITY
|
||||
example.com. IN NS ns.example.com.
|
||||
; is missing the glue!
|
||||
ENTRY_END
|
||||
|
||||
ENTRY_BEGIN
|
||||
MATCH opcode qtype qname
|
||||
ADJUST copy_id
|
||||
REPLY AA QR NOERROR
|
||||
SECTION QUESTION
|
||||
ns.example.com. IN A
|
||||
SECTION ANSWER
|
||||
ns.example.com. IN CNAME ns2.example.com.
|
||||
SECTION AUTHORITY
|
||||
example.com. IN NS ns.example.com.
|
||||
ENTRY_END
|
||||
|
||||
ENTRY_BEGIN
|
||||
MATCH opcode qtype qname
|
||||
ADJUST copy_id
|
||||
REPLY AA QR NOERROR
|
||||
SECTION QUESTION
|
||||
ns2.example.com. IN A
|
||||
SECTION ANSWER
|
||||
ns2.example.com. IN A 1.2.3.4
|
||||
SECTION AUTHORITY
|
||||
example.com. IN NS ns.example.com.
|
||||
ENTRY_END
|
||||
|
||||
ENTRY_BEGIN
|
||||
MATCH opcode qtype qname
|
||||
ADJUST copy_id
|
||||
REPLY QR NOERROR
|
||||
SECTION QUESTION
|
||||
ns.example.com. IN AAAA
|
||||
SECTION AUTHORITY
|
||||
example.com. IN NS ns.example.com.
|
||||
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
|
||||
www.example.com. IN A
|
||||
SECTION ANSWER
|
||||
www.example.com. IN A 10.20.30.40
|
||||
SECTION AUTHORITY
|
||||
example.com. IN NS ns.example.com.
|
||||
SECTION ADDITIONAL
|
||||
ns.example.com. IN A 1.2.3.4
|
||||
ENTRY_END
|
||||
|
||||
ENTRY_BEGIN
|
||||
MATCH opcode qtype qname
|
||||
ADJUST copy_id
|
||||
REPLY QR NOERROR
|
||||
SECTION QUESTION
|
||||
ns.example.com. IN A
|
||||
SECTION ANSWER
|
||||
ns.example.com. IN A 1.2.3.4
|
||||
SECTION AUTHORITY
|
||||
example.com. IN NS ns.example.com.
|
||||
ENTRY_END
|
||||
|
||||
ENTRY_BEGIN
|
||||
MATCH opcode qtype qname
|
||||
ADJUST copy_id
|
||||
REPLY QR NOERROR
|
||||
SECTION QUESTION
|
||||
ns.example.com. IN AAAA
|
||||
SECTION AUTHORITY
|
||||
example.com. IN NS ns.example.com.
|
||||
SECTION ADDITIONAL
|
||||
ns.example.com. IN A 1.2.3.4
|
||||
ENTRY_END
|
||||
|
||||
RANGE_END
|
||||
|
||||
STEP 1 QUERY
|
||||
ENTRY_BEGIN
|
||||
REPLY RD
|
||||
SECTION QUESTION
|
||||
www.example.com. IN A
|
||||
ENTRY_END
|
||||
|
||||
; recursion happens here.
|
||||
STEP 10 CHECK_ANSWER
|
||||
ENTRY_BEGIN
|
||||
MATCH all
|
||||
REPLY QR RD RA NOERROR
|
||||
SECTION QUESTION
|
||||
www.example.com. IN A
|
||||
SECTION ANSWER
|
||||
www.example.com. IN A 10.20.30.40
|
||||
SECTION AUTHORITY
|
||||
example.com. IN NS ns.example.com.
|
||||
SECTION ADDITIONAL
|
||||
ns.example.com. IN A 1.2.3.4
|
||||
ENTRY_END
|
||||
|
||||
; due to ordering of answer packets, this is still outstanding, remove it
|
||||
STEP 21 CHECK_OUT_QUERY
|
||||
ENTRY_BEGIN
|
||||
ADJUST copy_id
|
||||
MATCH qname qtype
|
||||
REPLY QR
|
||||
SECTION QUESTION
|
||||
ns.example.com IN AAAA
|
||||
ENTRY_END
|
||||
|
||||
SCENARIO_END
|
||||
Vendored
BIN
Binary file not shown.
Vendored
+5
-1
@@ -8,9 +8,13 @@ SECTION QUESTION
|
||||
www.example.com. IN A
|
||||
ENTRY_END
|
||||
; But the pending query fails due to error (say TCP failure or malloc or ...)
|
||||
; This is iterator/iterator.h OUTBOUND_MSG_RETRY number of errors.
|
||||
STEP 2 ERROR
|
||||
STEP 3 ERROR
|
||||
STEP 4 ERROR
|
||||
STEP 5 ERROR
|
||||
; returns servfail
|
||||
STEP 4 CHECK_ANSWER
|
||||
STEP 14 CHECK_ANSWER
|
||||
ENTRY_BEGIN
|
||||
MATCH opcode qname qtype
|
||||
SECTION QUESTION
|
||||
|
||||
Vendored
+3
@@ -11,6 +11,7 @@ SCENARIO_BEGIN Old answer is dropped from the cache
|
||||
|
||||
STEP 1 QUERY
|
||||
ENTRY_BEGIN
|
||||
REPLY RD
|
||||
SECTION QUESTION
|
||||
www.example.com. IN A
|
||||
ENTRY_END
|
||||
@@ -47,6 +48,7 @@ ENTRY_END
|
||||
; another query to force the cache to drop the example.com entry.
|
||||
STEP 11 QUERY
|
||||
ENTRY_BEGIN
|
||||
REPLY RD
|
||||
SECTION QUESTION
|
||||
www.example.net. IN A
|
||||
ENTRY_END
|
||||
@@ -84,6 +86,7 @@ ENTRY_END
|
||||
; query, same as first, but it fell out of the cache.
|
||||
STEP 21 QUERY
|
||||
ENTRY_BEGIN
|
||||
REPLY RD
|
||||
SECTION QUESTION
|
||||
www.example.com. IN A
|
||||
ENTRY_END
|
||||
|
||||
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user