Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Flex+Bison based zone parser with simdzone #278

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ubuntu_2204_gcc11: &ubuntu_2204_gcc11
bootstrap_script:
- apt-get update
install_script:
- apt-get install -y autoconf automake libtool make gcc-11 clang libc-dev libevent-dev libssl-dev flex bison
- apt-get install -y autoconf automake libtool make gcc-11 clang libc-dev libevent-dev libssl-dev flex bison git

ubuntu_2204_clang14: &ubuntu_2204_clang14
container:
Expand All @@ -30,7 +30,7 @@ ubuntu_2204_clang14: &ubuntu_2204_clang14
bootstrap_script:
- apt-get update
install_script:
- apt-get install -y autoconf automake libtool make clang-${CLANG_VERSION} libc-dev libevent-dev libssl-dev flex bison
- apt-get install -y autoconf automake libtool make clang-${CLANG_VERSION} libc-dev libevent-dev libssl-dev flex bison git
- update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 10

freebsd_14_0: &freebsd_14_0
Expand All @@ -39,7 +39,7 @@ freebsd_14_0: &freebsd_14_0
env:
CC: clang
install_script:
- pkg install --yes --quiet bash gmake autoconf automake libtool libevent
- pkg install --yes --quiet bash gmake autoconf automake libtool libevent git

macos_13_1_xcode14_2: &macos_13_1_xcode14_2
macos_instance:
Expand All @@ -49,7 +49,7 @@ macos_13_1_xcode14_2: &macos_13_1_xcode14_2
COV_COMPTYPE: clang
COV_COMPTYPE: macOSX
install_script:
- brew install bash autoconf automake libtool openssl libevent flex bison
- brew install bash autoconf automake libtool openssl libevent flex bison git

install_coverity: &install_coverity
env:
Expand Down Expand Up @@ -114,7 +114,9 @@ task:
LIBEVENT: "/opt/homebrew/opt/libevent"

build_script:
- git submodule update --init
- autoconf && autoheader
- (cd simdzone && autoconf)
- libtoolize -c -i || glibtoolize -c -i
- ./configure --enable-checking --disable-flto --with-ssl=${OPENSSL:-yes} --with-libevent=${LIBEVENT:-yes}
- make -j 2
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "simdzone"]
path = simdzone
url = https://github.com/NLnetLabs/simdzone.git
74 changes: 30 additions & 44 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ user = @user@
DNSTAP_SRC=@DNSTAP_SRC@
DNSTAP_OBJ=@DNSTAP_OBJ@

# GNU Make provides MAKECMDGOALS, BSD Make provides .TARGETS
MAKECMDGOALS ?= $(.TARGETS)

# override $U variable which is used by autotools for deansification (for
# K&R C compilers), but causes problems if $U is defined in the env).
U=

CC = @CC@
CPPFLAGS = @CPPFLAGS@
CPPFLAGS = @CPPFLAGS@ -I@srcdir@/simdzone/include
CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
Expand Down Expand Up @@ -78,13 +81,13 @@ MANUALS=nsd.8 nsd-checkconf.8 nsd-checkzone.8 nsd-control.8 nsd.conf.5

COMMON_OBJ=answer.o axfr.o ixfr.o ixfrcreate.o buffer.o configlexer.o configparser.o dname.o dns.o edns.o iterated_hash.o lookup3.o namedb.o nsec3.o options.o packet.o query.o rbtree.o radtree.o rdata.o region-allocator.o rrl.o siphash.o tsig.o tsig-openssl.o udb.o util.o bitset.o popen3.o proxy_protocol.o
XFRD_OBJ=xfrd-catalog-zones.o xfrd-disk.o xfrd-notify.o xfrd-tcp.o xfrd.o remote.o $(DNSTAP_OBJ)
NSD_OBJ=$(COMMON_OBJ) $(XFRD_OBJ) difffile.o ipc.o mini_event.o netio.o nsd.o server.o dbaccess.o dbcreate.o zlexer.o zonec.o zparser.o verify.o
NSD_OBJ=$(COMMON_OBJ) $(XFRD_OBJ) difffile.o ipc.o mini_event.o netio.o nsd.o server.o dbaccess.o dbcreate.o zonec.o verify.o
ALL_OBJ=$(NSD_OBJ) nsd-checkconf.o nsd-checkzone.o nsd-control.o nsd-mem.o xfr-inspect.o
NSD_CHECKCONF_OBJ=$(COMMON_OBJ) nsd-checkconf.o
NSD_CHECKZONE_OBJ=$(COMMON_OBJ) $(XFRD_OBJ) dbaccess.o dbcreate.o difffile.o ipc.o mini_event.o netio.o server.o zonec.o zparser.o zlexer.o nsd-checkzone.o verify.o
NSD_CHECKZONE_OBJ=$(COMMON_OBJ) $(XFRD_OBJ) dbaccess.o dbcreate.o difffile.o ipc.o mini_event.o netio.o server.o zonec.o nsd-checkzone.o verify.o
NSD_CONTROL_OBJ=$(COMMON_OBJ) nsd-control.o
CUTEST_OBJ=$(COMMON_OBJ) $(XFRD_OBJ) dbaccess.o dbcreate.o difffile.o ipc.o mini_event.o netio.o server.o verify.o zonec.o zparser.o zlexer.o cutest_dname.o cutest_dns.o cutest_iterated_hash.o cutest_run.o cutest_radtree.o cutest_rbtree.o cutest_namedb.o cutest_options.o cutest_region.o cutest_rrl.o cutest_udb.o cutest_util.o cutest_bitset.o cutest_popen3.o cutest_iter.o cutest_event.o cutest.o qtest.o
NSD_MEM_OBJ=$(COMMON_OBJ) $(XFRD_OBJ) dbaccess.o dbcreate.o difffile.o ipc.o mini_event.o netio.o verify.o server.o zonec.o zparser.o zlexer.o nsd-mem.o
CUTEST_OBJ=$(COMMON_OBJ) $(XFRD_OBJ) dbaccess.o dbcreate.o difffile.o ipc.o mini_event.o netio.o server.o verify.o zonec.o cutest_dname.o cutest_dns.o cutest_iterated_hash.o cutest_run.o cutest_radtree.o cutest_rbtree.o cutest_namedb.o cutest_options.o cutest_region.o cutest_rrl.o cutest_udb.o cutest_util.o cutest_bitset.o cutest_popen3.o cutest_iter.o cutest_event.o cutest.o qtest.o
NSD_MEM_OBJ=$(COMMON_OBJ) $(XFRD_OBJ) dbaccess.o dbcreate.o difffile.o ipc.o mini_event.o netio.o verify.o server.o zonec.o nsd-mem.o
all: $(TARGETS) $(MANUALS)

$(ALL_OBJ):
Expand Down Expand Up @@ -152,26 +155,29 @@ uninstall:

test:

nsd: $(NSD_OBJ) $(LIBOBJS)
$(LINK) -o $@ $(NSD_OBJ) $(LIBOBJS) $(SSL_LIBS) $(LIBS)
simdzone/libzone.a:
$(MAKE) -C simdzone

nsd: simdzone/libzone.a $(NSD_OBJ) $(LIBOBJS)
$(LINK) -o $@ $(NSD_OBJ) $(LIBOBJS) simdzone/libzone.a $(SSL_LIBS) $(LIBS)

nsd-checkconf: $(NSD_CHECKCONF_OBJ) $(LIBOBJS)
$(LINK) -o $@ $(NSD_CHECKCONF_OBJ) $(LIBOBJS) $(LIBS)
nsd-checkconf: simdzone/libzone.a $(NSD_CHECKCONF_OBJ) $(LIBOBJS)
$(LINK) -o $@ $(NSD_CHECKCONF_OBJ) simdzone/libzone.a $(LIBOBJS) $(LIBS)

nsd-checkzone: $(NSD_CHECKZONE_OBJ) $(LIBOBJS)
$(LINK) -o $@ $(NSD_CHECKZONE_OBJ) $(LIBOBJS) $(SSL_LIBS) $(LIBS)
nsd-checkzone: simdzone/libzone.a $(NSD_CHECKZONE_OBJ) $(LIBOBJS)
$(LINK) -o $@ $(NSD_CHECKZONE_OBJ) $(LIBOBJS) simdzone/libzone.a $(SSL_LIBS) $(LIBS)

nsd-control: $(NSD_CONTROL_OBJ) $(LIBOBJS)
$(LINK) -o $@ $(NSD_CONTROL_OBJ) $(LIBOBJS) $(SSL_LIBS) $(LIBS)
nsd-control: simdzone/libzone.a $(NSD_CONTROL_OBJ) $(LIBOBJS)
$(LINK) -o $@ $(NSD_CONTROL_OBJ) $(LIBOBJS) simdzone/libzone.a $(SSL_LIBS) $(LIBS)

nsd-mem: $(NSD_MEM_OBJ) $(LIBOBJS)
$(LINK) -o $@ $(NSD_MEM_OBJ) $(LIBOBJS) $(SSL_LIBS) $(LIBS)
nsd-mem: simdzone/libzone.a $(NSD_MEM_OBJ) $(LIBOBJS)
$(LINK) -o $@ $(NSD_MEM_OBJ) $(LIBOBJS) simdzone/libzone.a $(SSL_LIBS) $(LIBS)

cutest: $(CUTEST_OBJ) $(LIBOBJS) popen3_echo
$(LINK) -o $@ $(CUTEST_OBJ) $(LIBOBJS) $(SSL_LIBS) $(LIBS)
cutest: simdzone/libzone.a $(CUTEST_OBJ) $(LIBOBJS) popen3_echo
$(LINK) -o $@ $(CUTEST_OBJ) $(LIBOBJS) simdzone/libzone.a $(SSL_LIBS) $(LIBS)

xfr-inspect: xfr-inspect.o $(COMMON_OBJ) zonec.o zparser.o zlexer.o $(LIBOBJS)
$(LINK) -o $@ xfr-inspect.o $(COMMON_OBJ) zonec.o zparser.o zlexer.o $(LIBOBJS) $(LIBS)
xfr-inspect: simdzone/libzone.a xfr-inspect.o $(COMMON_OBJ) zonec.o $(LIBOBJS)
$(LINK) -o $@ xfr-inspect.o $(COMMON_OBJ) zonec.o $(LIBOBJS) simdzone/libzone.a $(LIBS)

popen3_echo: popen3.o popen3_echo.o
$(LINK) -o $@ popen3.o popen3_echo.o
Expand All @@ -189,13 +195,13 @@ audit: nsd nsd-checkconf nsd-checkzone nsd-control nsd-mem checksec

clean:
rm -f *.o $(TARGETS) $(MANUALS) cutest popen3_echo xfr-inspect nsd-mem
make -C simdzone $(MAKECMDGOALS)

distclean: clean
rm -f Makefile config.h config.log config.status dnstap/dnstap_config.h

realclean: distclean
rm -rf autom4te*
rm -f zlexer.c zparser.h zparser.c zparser.stamp
rm -f configlexer.c configparser.h configparser.c configparser.stamp

maintainer-clean: realclean
Expand Down Expand Up @@ -326,16 +332,6 @@ cutest.o: $(srcdir)/tpkg/cutest/cutest.c
qtest.o: $(srcdir)/tpkg/cutest/qtest.c
$(COMPILE) -c $(srcdir)/tpkg/cutest/qtest.c

zlexer.c: $(srcdir)/zlexer.lex
if test "$(LEX)" != ":"; then rm -f $@ ;\
echo '#include "config.h"' > $@ ;\
$(LEX) -i -t $(srcdir)/zlexer.lex >> $@ ;\
fi
@if test ! -f $@; then echo "No $@ : need flex and bison to compile from source repository"; exit 1; fi

zparser.c zparser.h: $(srcdir)/zparser.y
$(YACC) -d -o zparser.c $(srcdir)/zparser.y

configlexer.c: $(srcdir)/configlexer.lex
if test "$(LEX)" != ":"; then rm -f $@ ;\
echo '#include "config.h"' > $@ ;\
Expand All @@ -350,10 +346,8 @@ configparser.c configparser.h: $(srcdir)/configparser.y
configlexer.o: configlexer.c config.h configparser.h
configparser.o: configparser.c config.h configparser.h
options.o: $(srcdir)/options.c config.h configparser.h
zlexer.o: zlexer.c config.h zparser.h
zparser.o: zparser.c config.h zparser.h
dns.o: $(srcdir)/dns.c config.h zparser.h
zonec.o: $(srcdir)/zonec.c config.h zparser.h
dns.o: $(srcdir)/dns.c config.h
zonec.o: $(srcdir)/zonec.c config.h

# dnstap
dnstap.o: $(srcdir)/dnstap/dnstap.c config.h dnstap/dnstap_config.h \
Expand Down Expand Up @@ -396,9 +390,6 @@ depend:
-e 's?$$(srcdir)/dnstap/dnstap_config.h??g' \
-e 's?$$(srcdir)/dnstap/dnstap.pb-c.c?dnstap/dnstap.pb-c.c?g' \
-e 's?$$(srcdir)/dnstap/dnstap.pb-c.h?dnstap/dnstap.pb-c.h?g' \
-e 's?$$(srcdir)/zlexer.c?zlexer.c?g' \
-e 's?$$(srcdir)/zparser.c?zparser.c?g' \
-e 's?$$(srcdir)/zparser.h?zparser.h?g' \
> $(DEPEND_TMP)
cp $(DEPEND_TARGET) $(DEPEND_TMP2)
head -`$(EGREP) -n "# Dependencies" $(DEPEND_TARGET) | tail -1 | $(SED) -e 's/:.*$$//'` $(DEPEND_TMP2) > $(DEPEND_TARGET)
Expand Down Expand Up @@ -444,7 +435,7 @@ dname.o: $(srcdir)/dname.c config.h $(srcdir)/compat/cpuset.h $(srcdir)/dns.h $(
$(srcdir)/region-allocator.h $(srcdir)/util.h $(srcdir)/query.h $(srcdir)/namedb.h $(srcdir)/radtree.h $(srcdir)/rbtree.h $(srcdir)/nsd.h \
$(srcdir)/edns.h $(srcdir)/bitset.h $(srcdir)/packet.h $(srcdir)/tsig.h
dns.o: $(srcdir)/dns.c config.h $(srcdir)/compat/cpuset.h $(srcdir)/dns.h $(srcdir)/zonec.h $(srcdir)/namedb.h $(srcdir)/dname.h \
$(srcdir)/buffer.h $(srcdir)/region-allocator.h $(srcdir)/util.h $(srcdir)/radtree.h $(srcdir)/rbtree.h zparser.h
$(srcdir)/buffer.h $(srcdir)/region-allocator.h $(srcdir)/util.h $(srcdir)/radtree.h $(srcdir)/rbtree.h
edns.o: $(srcdir)/edns.c config.h $(srcdir)/compat/cpuset.h $(srcdir)/dns.h $(srcdir)/edns.h $(srcdir)/buffer.h \
$(srcdir)/region-allocator.h $(srcdir)/util.h $(srcdir)/nsd.h $(srcdir)/bitset.h $(srcdir)/query.h $(srcdir)/namedb.h $(srcdir)/dname.h \
$(srcdir)/radtree.h $(srcdir)/rbtree.h $(srcdir)/packet.h $(srcdir)/tsig.h
Expand Down Expand Up @@ -551,14 +542,9 @@ xfrd-tcp.o: $(srcdir)/xfrd-tcp.c config.h $(srcdir)/compat/cpuset.h $(srcdir)/ns
xfr-inspect.o: $(srcdir)/xfr-inspect.c config.h $(srcdir)/compat/cpuset.h $(srcdir)/util.h $(srcdir)/buffer.h \
$(srcdir)/region-allocator.h $(srcdir)/packet.h $(srcdir)/dns.h $(srcdir)/namedb.h $(srcdir)/dname.h $(srcdir)/radtree.h $(srcdir)/rbtree.h \
$(srcdir)/rdata.h $(srcdir)/difffile.h $(srcdir)/options.h $(srcdir)/udb.h
zlexer.o: zlexer.c config.h $(srcdir)/compat/cpuset.h $(srcdir)/zonec.h $(srcdir)/namedb.h $(srcdir)/dname.h \
$(srcdir)/buffer.h $(srcdir)/region-allocator.h $(srcdir)/util.h $(srcdir)/dns.h $(srcdir)/radtree.h $(srcdir)/rbtree.h zparser.h
zonec.o: $(srcdir)/zonec.c config.h $(srcdir)/compat/cpuset.h $(srcdir)/zonec.h $(srcdir)/namedb.h $(srcdir)/dname.h \
$(srcdir)/buffer.h $(srcdir)/region-allocator.h $(srcdir)/util.h $(srcdir)/dns.h $(srcdir)/radtree.h $(srcdir)/rbtree.h $(srcdir)/rdata.h \
zparser.h $(srcdir)/options.h $(srcdir)/nsec3.h
zparser.o: zparser.c config.h $(srcdir)/compat/cpuset.h $(srcdir)/dname.h $(srcdir)/buffer.h \
$(srcdir)/region-allocator.h $(srcdir)/util.h $(srcdir)/namedb.h $(srcdir)/dns.h $(srcdir)/radtree.h $(srcdir)/rbtree.h $(srcdir)/zonec.h \
zparser.h
$(srcdir)/options.h $(srcdir)/nsec3.h
b64_ntop.o: $(srcdir)/compat/b64_ntop.c config.h $(srcdir)/compat/cpuset.h
b64_pton.o: $(srcdir)/compat/b64_pton.c config.h $(srcdir)/compat/cpuset.h
basename.o: $(srcdir)/compat/basename.c
Expand Down
2 changes: 1 addition & 1 deletion buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ buffer_create(region_type *region, size_t capacity)
}

void
buffer_create_from(buffer_type *buffer, void *data, size_t size)
buffer_create_from(buffer_type *buffer, const void *data, size_t size)
{
assert(data);

Expand Down
2 changes: 1 addition & 1 deletion buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ buffer_type *buffer_create(region_type *region, size_t capacity);
* and no memory allocations are done. The buffer is fixed and cannot
* be resized using buffer_reserve().
*/
void buffer_create_from(buffer_type *buffer, void *data, size_t size);
void buffer_create_from(buffer_type *buffer, const void *data, size_t size);

/*
* Clear the buffer and make it ready for writing. The buffer's limit
Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1399,4 +1399,9 @@ if test "$enable_checking" = "yes"; then
fi

AC_CONFIG_FILES([Makefile $dnstap_config])

# Arguments introduced specifically for simdzone.
AC_ARG_ENABLE(westmere, AS_HELP_STRING([--disable-westmere], [Disable Westmere (SSE4.2) parser kernel]))
AC_ARG_ENABLE(haswell, AS_HELP_STRING([--disable-haswell], [Disable Haswell (AVX2) parser kernel]))
AC_CONFIG_SUBDIRS([simdzone])
AC_OUTPUT
5 changes: 1 addition & 4 deletions dbaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void
namedb_close(struct namedb* db)
{
if(db) {
zonec_desetup_parser();
region_destroy(db->region);
}
}
Expand Down Expand Up @@ -155,7 +154,6 @@ namedb_open (struct nsd_options* opt)
db->zonetree = radix_tree_create(db->region);
db->diff_skip = 0;
db->diff_pos = 0;
zonec_setup_parser(db);

if (gettimeofday(&(db->diff_timestamp), NULL) != 0) {
log_msg(LOG_ERR, "unable to load namedb: cannot initialize timestamp");
Expand Down Expand Up @@ -254,14 +252,13 @@ namedb_read_zonefile(struct nsd* nsd, struct zone* zone, udb_base* taskudb,
}
}

assert(parser);
/* wipe zone from memory */
#ifdef NSEC3
nsec3_clear_precompile(nsd->db, zone);
zone->nsec3_param = NULL;
#endif
delete_zone_rrs(nsd->db, zone);
errors = zonec_read(zone->opts->name, fname, zone);
errors = zonec_read(nsd->db, nsd->db->domains, zone->opts->name, fname, zone);
if(errors > 0) {
log_msg(LOG_ERR, "zone %s file %s read with %u errors",
zone->opts->name, fname, errors);
Expand Down
Loading