1dnl
2dnl Some global settings
3dnl
4
5sinclude(acx_nlnetlabs.m4)
6sinclude(dnstap/dnstap.m4)
7
8AC_INIT([NSD],[4.8.0],[https://github.com/NLnetLabs/nsd/issues or nsd-bugs@nlnetlabs.nl])
9AC_CONFIG_HEADERS([config.h])
10
11#
12# Setup the standard programs
13# https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Setting-Output-Variables.html
14
15AC_ARG_VAR(SED, [location of the sed program])
16AC_ARG_VAR(AWK, [location of the awk program])
17AC_ARG_VAR(GREP, [location of the grep program])
18AC_ARG_VAR(EGREP, [location of the egrep program])
19AC_ARG_VAR(LEX, [location of the lex program with GNU extensions (flex)])
20AC_ARG_VAR(YACC, [location of the yacc program with GNU extensions (bison)])
21
22cmdln="`echo $@ | sed -e 's/\\\\/\\\\\\\\/g' | sed -e 's/"/\\\\"/'g`"
23AC_DEFINE_UNQUOTED(CONFCMDLINE, ["$cmdln"], [Command line arguments used with configure])
24
25CFLAGS="$CFLAGS"
26AC_USE_SYSTEM_EXTENSIONS
27if test "$ac_cv_header_minix_config_h" = "yes"; then
28	AC_DEFINE(_NETBSD_SOURCE,1, [Enable for compile on Minix])
29fi
30
31dnl
32dnl By default set $sysconfdir to /etc and $localstatedir to /var
33dnl
34case "$prefix" in
35	NONE)
36		case "$sysconfdir" in
37			'${prefix}/etc')
38				sysconfdir=/etc
39			;;
40                esac
41		case "$localstatedir" in
42			'${prefix}/var')
43				localstatedir=/var
44			;;
45		esac
46	;;
47esac
48
49#
50# Determine configuration directory
51#
52configdir=$sysconfdir/nsd
53AC_ARG_WITH([configdir],
54	AS_HELP_STRING([--with-configdir=dir],[NSD configuration directory]),
55	[configdir=$withval])
56AC_DEFINE_UNQUOTED(CONFIGDIR, ["`eval echo $configdir`"], [NSD config dir])
57AC_SUBST(configdir)
58
59#
60# Determine configuration file
61nsd_conf_file=${configdir}/nsd.conf
62AC_ARG_WITH([nsd_conf_file],
63	AS_HELP_STRING([--with-nsd_conf_file=path],[Pathname to the NSD configuration file]),
64	[nsd_conf_file=$withval])
65AC_SUBST(nsd_conf_file)
66# the eval is to evaluate shell expansion twice, once
67# for $nsd_conf_file and once for the ${prefix} within it.
68AC_DEFINE_UNQUOTED(CONFIGFILE, ["`eval echo $nsd_conf_file`"], [Pathname to the NSD configuration file])
69
70#
71# Default logfile
72#
73logfile=${localstatedir}/log/nsd.log
74AC_ARG_WITH([logfile],
75	AS_HELP_STRING([--with-logfile=path],[Pathname to the default log file]),
76	[logfile=$withval])
77AC_SUBST(logfile)
78
79#
80# Database directory
81#
82dbdir=${localstatedir}/db/nsd
83
84#
85# Determine the pidfile location. Check if /var/run exists, if so set pidfile
86# to /var/run/nsd.pid by default
87#
88if test -d ${localstatedir}/run; then
89	pidfile=${localstatedir}/run/nsd.pid
90else
91	pidfile=${dbdir}/nsd.pid
92fi
93AC_ARG_WITH([pidfile],
94	AS_HELP_STRING([--with-pidfile=path],[Pathname to the NSD pidfile]),
95	[pidfile=$withval])
96AC_SUBST(pidfile)
97AC_DEFINE_UNQUOTED(PIDFILE, ["`eval echo $pidfile`"], [Pathname to the NSD pidfile])
98
99AC_ARG_WITH([dbfile],
100	AS_HELP_STRING([--with-dbfile=path],[Pathname to the NSD database (obsolete)]),[])
101
102piddir=`dirname $pidfile`
103AC_SUBST(piddir)
104
105#
106# Determine the default directory for the zone files
107#
108zonesdir=$configdir
109AC_ARG_WITH([zonesdir],
110	AS_HELP_STRING([--with-zonesdir=dir],[NSD default location for zone files]),
111	[zonesdir=$withval])
112AC_SUBST(zonesdir)
113AC_DEFINE_UNQUOTED(ZONESDIR, ["`eval echo $zonesdir`"], [NSD default location for zone files. Empty string or NULL to disable.])
114
115# default xfrd file location.
116xfrdfile=${dbdir}/xfrd.state
117AC_ARG_WITH([xfrdfile], AS_HELP_STRING([--with-xfrdfile=path],[Pathname to the NSD xfrd zone timer state file]), [xfrdfile=$withval])
118AC_DEFINE_UNQUOTED(XFRDFILE, ["`eval echo $xfrdfile`"], [Pathname to the NSD xfrd zone timer state file.])
119AC_SUBST(xfrdfile)
120
121# default zonelist file location.
122zonelistfile=${dbdir}/zone.list
123AC_ARG_WITH([zonelistfile], AS_HELP_STRING([--with-zonelistfile=path],[Pathname to the NSD zone list file]), [zonelistfile=$withval])
124AC_DEFINE_UNQUOTED(ZONELISTFILE, ["`eval echo $zonelistfile`"], [Pathname to the NSD zone list file.])
125AC_SUBST(zonelistfile)
126
127# default xfr dir location.
128xfrdir="/tmp"
129AC_ARG_WITH([xfrdir], AS_HELP_STRING([--with-xfrdir=path],[Pathname to where the NSD transfer dir is created]), [xfrdir=$withval])
130AC_DEFINE_UNQUOTED(XFRDIR, ["`eval echo $xfrdir`"], [Pathname to where the NSD transfer dir is created.])
131AC_SUBST(xfrdir)
132
133# nsd sbin location. tmpinstantiate execprefix with defaults if not yet done.
134if test "x${exec_prefix}" = "xNONE"; then
135	if test "x${prefix}" = "xNONE"; then exec_prefix="$ac_default_prefix"
136	else exec_prefix="${prefix}"; fi
137	nsd_start_path="`eval echo $sbindir`/nsd"
138	exec_prefix="NONE"
139else
140	nsd_start_path="`eval echo $sbindir`/nsd"
141fi
142AC_DEFINE_UNQUOTED(NSD_START_PATH, ["$nsd_start_path"], [Pathname to start nsd from nsd-control])
143
144#
145# Determine default chroot directory
146#
147AC_ARG_WITH([chroot],
148	AS_HELP_STRING([--with-chroot=dir],[NSD default chroot directory]),
149	[
150		chrootdir=$withval
151		AC_DEFINE_UNQUOTED(CHROOTDIR, ["`eval echo $chrootdir`"], [NSD default chroot directory])
152	])
153AC_SUBST(chrootdir)
154
155#
156# Determine the user name to drop privileges to
157#
158user=nsd
159AC_ARG_WITH([user],
160	AS_HELP_STRING([--with-user=username],[User name or ID to answer the queries with]),
161	[user=$withval])
162AC_SUBST(user)
163AC_DEFINE_UNQUOTED(USER, ["$user"], [the user name to drop privileges to])
164
165m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_STDC])
166AC_PROG_SED
167AC_PROG_AWK
168AC_PROG_GREP
169AC_PROG_EGREP
170AC_PROG_LEX([noyywrap])
171AC_PROG_YACC
172AC_PROG_LN_S
173AC_PROG_INSTALL
174
175if test "$LEX" != ":" -a "$LEX" != ""; then
176# Solaris provides anemic tools, and they don't offer GNU extensions like
177# 'flex -i'. Solaris also does not offer GNU replacements in /usr/gnu/bin.
178AC_MSG_CHECKING([whether lex accepts -i])
179AS_IF([echo "%%" | $LEX -i -t >/dev/null 2>&1],
180  [
181    AC_MSG_RESULT([yes])
182  ],
183  [
184    AC_MSG_RESULT([no])
185    AC_MSG_ERROR([unable to find a lexer that supports -i. If one is available then set the LEX variable])
186  ]
187)
188
189  # Check if lex defines yy_current_buffer, because 2.4.6 and older use it,
190  # but later could define it as a macro and then we should not redefine it.
191  AC_MSG_CHECKING(if lex defines yy_current_buffer)
192  cat <<EOF >conftest.lex
193%%
194EOF
195  $LEX -i -t conftest.lex >> conftest.c 2>/dev/null
196  if $GREP "^#define yy_current_buffer" conftest.c >/dev/null; then
197	  AC_DEFINE_UNQUOTED(LEX_DEFINES_YY_CURRENT_BUFFER, 1, [If flex defines yy_current_buffer as a macro])
198	AC_MSG_RESULT(yes)
199  else
200	AC_MSG_RESULT(no)
201  fi
202  rm -f conftest.lex conftest.c
203fi
204
205AC_DEFUN([AC_CHECK_FORMAT_ATTRIBUTE],
206[AC_REQUIRE([AC_PROG_CC])
207AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "format" attribute)
208AC_CACHE_VAL(ac_cv_c_format_attribute,
209[ac_cv_c_format_attribute=no
210AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
211void f (char *format, ...) __attribute__ ((format (printf, 1, 2)));
212void (*pf) (char *format, ...) __attribute__ ((format (printf, 1, 2)));
213]], [[
214   f ("%s", "str");
215]])],[ac_cv_c_format_attribute="yes"],[ac_cv_c_format_attribute="no"])
216])
217
218AC_MSG_RESULT($ac_cv_c_format_attribute)
219if test $ac_cv_c_format_attribute = yes; then
220  AC_DEFINE(HAVE_ATTR_FORMAT, 1, [Whether the C compiler accepts the "format" attribute])
221fi
222])dnl
223
224AC_DEFUN([AC_CHECK_UNUSED_ATTRIBUTE],
225[AC_REQUIRE([AC_PROG_CC])
226AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "unused" attribute)
227AC_CACHE_VAL(ac_cv_c_unused_attribute,
228[ac_cv_c_unused_attribute=no
229AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
230void f (char *u __attribute__((unused)));
231]], [[
232   f ("x");
233]])],[ac_cv_c_unused_attribute="yes"],[ac_cv_c_unused_attribute="no"])
234])
235
236AC_MSG_RESULT($ac_cv_c_unused_attribute)
237if test $ac_cv_c_unused_attribute = yes; then
238  AC_DEFINE(HAVE_ATTR_UNUSED, 1, [Whether the C compiler accepts the "unused" attribute])
239fi
240])dnl
241
242AC_DEFUN([CHECK_WEAK_ATTRIBUTE],
243[AC_REQUIRE([AC_PROG_CC])
244AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "weak" attribute)
245AC_CACHE_VAL(ac_cv_c_weak_attribute,
246[ac_cv_c_weak_attribute=no
247AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <stdio.h>
248__attribute__((weak)) void f(int x) { printf("%d", x); }
249]], [[
250   f(1);
251]])],[ac_cv_c_weak_attribute="yes"],[ac_cv_c_weak_attribute="no"])
252])
253
254AC_MSG_RESULT($ac_cv_c_weak_attribute)
255if test $ac_cv_c_weak_attribute = yes; then
256  AC_DEFINE(HAVE_ATTR_WEAK, 1, [Whether the C compiler accepts the "weak" attribute])
257  AC_DEFINE(ATTR_WEAK, [__attribute__((weak))], [apply the weak attribute to a symbol])
258fi
259])dnl End of CHECK_WEAK_ATTRIBUTE
260
261AC_DEFUN([CHECK_NORETURN_ATTRIBUTE],
262[AC_REQUIRE([AC_PROG_CC])
263AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "noreturn" attribute)
264AC_CACHE_VAL(ac_cv_c_noreturn_attribute,
265[ac_cv_c_noreturn_attribute=no
266AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <stdio.h>
267__attribute__((noreturn)) void f(int x) { printf("%d", x); }
268]], [[
269   f(1);
270]])],[ac_cv_c_noreturn_attribute="yes"],[ac_cv_c_noreturn_attribute="no"])
271])
272
273AC_MSG_RESULT($ac_cv_c_noreturn_attribute)
274if test $ac_cv_c_noreturn_attribute = yes; then
275  AC_DEFINE(HAVE_ATTR_NORETURN, 1, [Whether the C compiler accepts the "noreturn" attribute])
276  AC_DEFINE(ATTR_NORETURN, [__attribute__((__noreturn__))], [apply the noreturn attribute to a function that exits the program])
277fi
278])dnl End of CHECK_NORETURN_ATTRIBUTE
279
280AC_DEFUN([CHECK_COMPILER_FLAG],
281[
282AC_REQUIRE([AC_PROG_CC])
283AC_MSG_CHECKING(whether $CC supports -$1)
284cache=`echo $1 | $SED 'y%.=/+-%___p_%'`
285AC_CACHE_VAL(cv_prog_cc_flag_$cache,
286[
287echo 'void f(void){}' >conftest.c
288if test -z "`$CC -$1 -c conftest.c 2>&1`"; then
289eval "cv_prog_cc_flag_$cache=yes"
290else
291eval "cv_prog_cc_flag_$cache=no"
292fi
293rm -f conftest*
294])
295if eval "test \"`echo '$cv_prog_cc_flag_'$cache`\" = yes"; then
296AC_MSG_RESULT(yes)
297:
298$2
299else
300AC_MSG_RESULT(no)
301:
302$3
303fi
304])
305
306AC_DEFUN([AC_CHECK_CTIME_R],
307[AC_REQUIRE([AC_PROG_CC])
308AC_MSG_CHECKING(whether ctime_r works with two arguments)
309AC_CACHE_VAL(ac_cv_c_ctime_c,
310[ac_cv_c_ctime_c=no
311AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <time.h>
312void testing (void) { time_t clock; char current_time[40]; ctime_r(&clock, current_time); }]], [[
313        testing();
314]])],[ac_cv_c_ctime_c="yes"],[ac_cv_c_ctime_c="no"])
315])
316
317AC_MSG_RESULT($ac_cv_c_ctime_c)
318if test $ac_cv_c_ctime_c = no; then
319        CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
320fi
321])dnl
322
323# Checks for typedefs, structures, and compiler characteristics.
324# allow user to override the -g -O2 flags.
325if test "x$CFLAGS" = "x" ; then
326	ACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"])
327	# we do not use O3 because it causes miscompilations.
328	ACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
329	ACX_CHECK_FLTO
330	ACX_CHECK_PIE
331	ACX_CHECK_RELRO_NOW
332fi
333AC_C_CONST
334AC_C_INLINE
335AC_TYPE_UID_T
336AC_TYPE_PID_T
337AC_TYPE_SIZE_T
338AC_TYPE_OFF_T
339
340AC_CHECK_FORMAT_ATTRIBUTE
341AC_CHECK_UNUSED_ATTRIBUTE
342CHECK_WEAK_ATTRIBUTE
343CHECK_NORETURN_ATTRIBUTE
344ACX_CHECK_MEMCMP_SIGNED
345AC_CHECK_CTIME_R
346
347# Checks for libraries.
348
349# Check for SSL, original taken from
350# http://www.gnu.org/software/ac-archive/htmldoc/check_ssl.html and
351# modified for NSD.
352AC_DEFUN([CHECK_SSL], [
353    AC_ARG_WITH(ssl, AS_HELP_STRING([--with-ssl=pathname],[enable SSL (will check /usr/local/ssl
354                /usr/lib/ssl /usr/ssl /usr/sfw /usr/local /usr /usr/local/opt/openssl)]),[
355        ],[
356            withval="yes"
357        ])
358    if test x_$withval != x_no; then
359        AC_MSG_CHECKING(for SSL)
360	if test -n "$withval"; then
361        	dnl look for openssl install with different version, eg.
362                dnl in /usr/include/openssl11/openssl/ssl.h
363                dnl and /usr/lib64/openssl11/libssl.so
364                dnl with the --with-ssl=/usr/include/openssl11
365                if test ! -f "$withval/include/openssl/ssl.h" -a -f "$withval/openssl/ssl.h"; then
366                        ssldir="$withval"
367                        found_ssl="yes"
368                        withval=""
369                        ssldir_include="$ssldir"
370                        CPPFLAGS="$CPPFLAGS -I$ssldir_include";
371                        dnl find the libdir
372                        ssldir_lib=`echo $ssldir | sed -e 's/include/lib/'`
373                        if test -f "$ssldir_lib/libssl.a" -o -f "$ssldir_lib/libssl.so"; then
374                                : # found here
375                        else
376                                ssldir_lib=`echo $ssldir | sed -e 's/include/lib64/'`
377                                if test -f "$ssldir_lib/libssl.a" -o -f "$ssldir_lib/libssl.so"; then
378                                        : # found here
379                                else
380                                        AC_MSG_ERROR([Could not find openssl lib file, $ssldir_lib/libssl.[so,a], pass like "/usr/local" or "/usr/include/openssl11"])
381                                fi
382                        fi
383                fi
384	fi
385        if test x_$withval = x_ -o x_$withval = x_yes; then
386            withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/sfw /usr/local /usr /usr/local/opt/openssl"
387        fi
388        for dir in $withval; do
389            ssldir="$dir"
390            if test -f "$dir/include/openssl/ssl.h"; then
391                found_ssl="yes";
392                if test x_$ssldir != x_/usr; then
393                    CPPFLAGS="$CPPFLAGS -I$ssldir/include";
394                fi
395		ssldir_include="$ssldir/include"
396		if test ! -d "$ssldir/lib" -a -d "$ssldir/lib64"; then
397			ssldir_lib="$ssldir/lib64"
398		else
399			ssldir_lib="$ssldir/lib"
400		fi
401                break;
402            fi
403        done
404        if test x_$found_ssl != x_yes; then
405            AC_MSG_ERROR([Cannot find the SSL libraries in $withval])
406        else
407            AC_MSG_RESULT([found in $ssldir])
408            HAVE_SSL=yes
409            AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.])
410            if test x_$ssldir != x_/usr; then
411                LDFLAGS="$LDFLAGS -L$ssldir_lib";
412            fi
413	    if test x_$ssldir = x_/usr/sfw; then
414		LDFLAGS="$LDFLAGS -R$ssldir_lib";
415	    fi
416        fi
417        AC_SUBST(HAVE_SSL)
418    fi
419])dnl
420
421# check for libevent
422AC_ARG_WITH(libevent, AS_HELP_STRING([--with-libevent=pathname],[use libevent (will check /usr/local /opt/local /usr/lib  /usr/sfw /usr /usr/local/opt/libevent or you can specify an explicit path), useful when the zone count is high.]),
423    [ ],[ withval="yes" ])
424if test x_$withval = x_yes -o x_$withval != x_no; then
425        AC_MSG_CHECKING(for libevent)
426        if test x_$withval = x_ -o x_$withval = x_yes; then
427            withval="/usr/local /opt/local /usr/lib  /usr/sfw /usr /usr/local/opt/libevent"
428        fi
429        for dir in $withval; do
430            thedir="$dir"
431            if test -f "$dir/include/event.h" -o -f "$dir/include/event2/event.h"; then
432                found_libevent="yes"
433		dnl assume /usr is in default path.
434		if test "$thedir" != "/usr"; then
435                    CPPFLAGS="$CPPFLAGS -I$thedir/include"
436		fi
437                break;
438            fi
439        done
440        if test x_$found_libevent != x_yes; then
441		if test -f "$dir/event.h" -a \( -f "$dir/libevent.la" -o -f "$dir/libev.la" \) ; then
442			# libevent source directory
443            		AC_MSG_RESULT(found in $thedir)
444                	CPPFLAGS="$CPPFLAGS -I$thedir -I$thedir/include"
445			# remove evdns from linking
446			ev_files_o=`ls $thedir/*.o | $GREP -v evdns\.o | $GREP -v bufferevent_openssl\.o`
447			cp $ev_files_o .
448			LDFLAGS="$ev_files_o $LDFLAGS -lm"
449		else
450            		AC_MSG_ERROR([Cannot find the libevent library.
451You can restart ./configure --with-libevent=no to use a builtin alternative.])
452		fi
453        else
454            AC_MSG_RESULT(found in $thedir)
455	    dnl if event2 exists and no event lib in dir itself, use subdir
456	    if test ! -f $thedir/lib/libevent.a -a ! -f $thedir/lib/libevent.so -a -d "$thedir/lib/event2"; then
457		LDFLAGS="$LDFLAGS -L$thedir/lib/event2"
458		ACX_RUNTIME_PATH_ADD([$thedir/lib/event2])
459	    else
460		    dnl assume /usr is in default path, do not add "".
461		    if test "$thedir" != "/usr" -a "$thedir" != ""; then
462			LDFLAGS="$LDFLAGS -L$thedir/lib"
463			ACX_RUNTIME_PATH_ADD([$thedir/lib])
464		    fi
465	    fi
466        fi
467	# check for library used by libevent after 1.3c
468	AC_SEARCH_LIBS([clock_gettime], [rt])
469
470	# is the event.h header libev or libevent?
471	AC_CHECK_HEADERS([event.h],,, [AC_INCLUDES_DEFAULT])
472	AC_CHECK_DECL(EV_VERSION_MAJOR, [
473		AC_SEARCH_LIBS(event_set, [ev])
474	],[
475		AC_SEARCH_LIBS(event_set, [event])
476	],[AC_INCLUDES_DEFAULT
477#include <event.h>
478	])
479	AC_CHECK_FUNCS([event_base_free]) # only in libevent 1.2 and later
480	AC_CHECK_FUNCS([event_base_once]) # only in libevent 1.4.1 and later
481	AC_CHECK_FUNCS([event_base_new]) # only in libevent 1.4.1 and later
482	AC_CHECK_FUNCS([event_base_get_method]) # only in libevent 1.4.3 and later
483	AC_CHECK_FUNCS([ev_loop]) # only in libev. (tested on 3.51)
484	AC_CHECK_FUNCS([ev_default_loop]) # only in libev. (tested on 4.00)
485else
486	AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
487fi
488
489# Checks for header files.
490AC_HEADER_SYS_WAIT
491AC_CHECK_HEADERS([time.h arpa/inet.h signal.h string.h strings.h fcntl.h limits.h netinet/in.h netinet/tcp.h stddef.h sys/param.h sys/socket.h sys/un.h syslog.h unistd.h sys/select.h stdarg.h stdint.h netdb.h sys/bitypes.h tcpd.h glob.h grp.h endian.h sys/random.h ifaddrs.h],,, [AC_INCLUDES_DEFAULT])
492
493AC_DEFUN([CHECK_VALIST_DEF],
494[
495AC_REQUIRE([AC_PROG_CC])
496AC_MSG_CHECKING(for double definition of struct va_list)
497AC_CACHE_VAL(ac_cv_c_va_list_def,
498[
499cat >conftest.c <<EOF
500#include <stdio.h>
501#include <stdarg.h>
502int foo(void);
503EOF
504if test -z "`$CC -Werror -D_XOPEN_SOURCE=600 -c conftest.c 2>&1`"; then
505eval "ac_cv_c_va_list_def=no"
506else
507eval "ac_cv_c_va_list_def=yes"
508fi
509rm -f conftest*
510])
511if test $ac_cv_c_va_list_def = yes; then
512AC_MSG_RESULT(yes)
513:
514AC_DEFINE_UNQUOTED([HAVE_VA_LIST_DOUBLE_DEF], [], [Define this if you have double va_list definitions.])
515else
516AC_MSG_RESULT(no)
517:
518
519fi
520])
521
522CHECK_VALIST_DEF
523
524AC_DEFUN([AC_CHECK_STRPTIME],
525[AC_REQUIRE([AC_PROG_CC])
526AC_MSG_CHECKING(whether strptime needs defines)
527AC_CACHE_VAL(ac_cv_c_strptime_needs_defs,
528[
529cat >conftest.c <<EOF
530#include <time.h>
531int testing (void) { struct tm t; const char *timestr="201201"; return strptime(timestr, "%Y%m", &t) != 0; }
532EOF
533if test -z "`$CC -Wall -Werror -c conftest.c 2>&1`"; then
534eval "ac_cv_c_strptime_needs_defs=no"
535else
536eval "ac_cv_c_strptime_needs_defs=yes"
537fi
538rm -f conftest*
539])
540
541AC_MSG_RESULT($ac_cv_c_strptime_needs_defs)
542if test $ac_cv_c_strptime_needs_defs = yes; then
543AC_DEFINE_UNQUOTED([STRPTIME_NEEDS_DEFINES], 1, [strptime is available from time.h with some defines.])
544fi
545])dnl
546
547AC_CHECK_STRPTIME
548
549# check wether strptime also works
550AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
551[AC_REQUIRE([AC_PROG_CC])
552AC_MSG_CHECKING(whether strptime works)
553if test c${cross_compiling} = cno; then
554AC_RUN_IFELSE([AC_LANG_SOURCE([[
555#define _XOPEN_SOURCE 600
556#include <time.h>
557int main(void) { struct tm tm; char *res;
558res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
559if (!res) return 1; return 0; }
560]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"],
561[eval "ac_cv_c_strptime_works=maybe"])
562else
563eval "ac_cv_c_strptime_works=maybe"
564fi
565AC_MSG_RESULT($ac_cv_c_strptime_works)
566if test $ac_cv_c_strptime_works = no; then
567AC_LIBOBJ(strptime)
568else
569AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
570fi
571])dnl
572
573AC_SEARCH_LIBS(inet_pton, [nsl])
574AC_SEARCH_LIBS(socket, [socket])
575
576AC_CHECK_STRPTIME_WORKS
577ACX_CHECK_NONBLOCKING_BROKEN
578ACX_MKDIR_ONE_ARG
579
580# set -I. and -Isrcdir
581if test -n "$CPPFLAGS"; then
582	CPPFLAGS="$CPPFLAGS -I."
583else
584	CPPFLAGS="-I."
585fi
586if test "$srcdir" != "."; then
587	CPPFLAGS="$CPPFLAGS -I$srcdir"
588	if test -f $srcdir/config.h; then
589		AC_MSG_ERROR([$srcdir/config.h is in the way, please remove it])
590	fi
591fi
592
593dnl LIBGTOP_CHECK_TYPE
594dnl Stolen from Gnome's anjuta
595dnl Improved version of AC_CHECK_TYPE which takes into account
596dnl that we need to #include some other header files on some
597dnl systems to get some types.
598
599dnl AC_LIBGTOP_CHECK_TYPE(TYPE, DEFAULT)
600AC_DEFUN([AC_LIBGTOP_CHECK_TYPE],
601[AC_MSG_CHECKING(for $1)
602AC_CACHE_VAL(ac_cv_type_$1,
603[AC_EGREP_CPP(dnl
604changequote(<<,>>)dnl
605<<(^|[^a-zA-Z_0-9])$1[^a-zA-Z_0-9]>>dnl
606changequote([,]), [
607#include <sys/types.h>
608#include <stdlib.h>
609#include <stddef.h>
610
611#ifdef HAVE_STDINT_H
612#include <stdint.h>
613#endif
614
615#ifdef HAVE_SYS_SOCKET_H
616#include <sys/socket.h>
617#endif
618
619#ifdef HAVE_ARPA_INET_H
620#include <arpa/inet.h>
621#endif
622
623#ifdef HAVE_SIGNAL_H
624#include <signal.h>
625#endif
626
627/* For Tru64 */
628#ifdef HAVE_SYS_BITYPES_H
629#include <sys/bitypes.h>
630#endif
631], ac_cv_type_$1=yes, ac_cv_type_$1=no)])dnl
632AC_MSG_RESULT($ac_cv_type_$1)
633if test $ac_cv_type_$1 = no; then
634  AC_DEFINE($1, $2, Define "$1" to "$2" if "$1" is missing)
635fi
636])
637
638AC_LIBGTOP_CHECK_TYPE(int8_t, char)
639AC_LIBGTOP_CHECK_TYPE(int16_t, short)
640AC_LIBGTOP_CHECK_TYPE(int32_t, int)
641AC_LIBGTOP_CHECK_TYPE(int64_t, long long)
642AC_LIBGTOP_CHECK_TYPE(uint8_t, unsigned char)
643AC_LIBGTOP_CHECK_TYPE(uint16_t, unsigned short)
644AC_LIBGTOP_CHECK_TYPE(uint32_t, unsigned int)
645AC_LIBGTOP_CHECK_TYPE(uint64_t, unsigned long long)
646AC_LIBGTOP_CHECK_TYPE(socklen_t, int)
647AC_LIBGTOP_CHECK_TYPE(sig_atomic_t, int)
648AC_LIBGTOP_CHECK_TYPE(ssize_t, int)
649AC_LIBGTOP_CHECK_TYPE(suseconds_t, time_t)
650
651AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [
652#if HAVE_SYS_TYPES_H
653# include <sys/types.h>
654#endif
655#if HAVE_NETINET_IN_H
656# include <netinet/in.h>
657#endif])
658ACX_CHECK_SS_FAMILY
659AC_CHECK_MEMBERS([struct stat.st_mtimensec, struct stat.st_mtim.tv_nsec])
660AC_CHECK_MEMBERS([struct sockaddr_un.sun_len],,,[
661AC_INCLUDES_DEFAULT
662#ifdef HAVE_SYS_UN_H
663#include <sys/un.h>
664#endif
665])
666
667# Checks for library functions.
668AC_FUNC_CHOWN
669AC_FUNC_FORK
670AC_FUNC_MALLOC
671AC_DEFINE(RETSIGTYPE,void,[Return type of signal handlers, but autoconf 2.70 says 'your code may safely assume C89 semantics that RETSIGTYPE is void.'])
672AC_FUNC_FSEEKO
673AC_SYS_LARGEFILE
674AC_CHECK_SIZEOF(void*)
675AC_CHECK_SIZEOF(off_t)
676AC_CHECK_FUNCS([getrandom arc4random arc4random_uniform])
677AC_SEARCH_LIBS([setusercontext],[util],[AC_CHECK_HEADERS([login_cap.h],,, [AC_INCLUDES_DEFAULT])])
678AC_CHECK_FUNCS([tzset alarm chroot dup2 endpwent gethostname memset memcpy pwrite socket strcasecmp strchr strdup strerror strncasecmp strtol writev getaddrinfo getnameinfo freeaddrinfo gai_strerror sigaction sigprocmask strptime strftime localtime_r setusercontext glob initgroups setresuid setreuid setresgid setregid getpwnam mmap ppoll clock_gettime accept4 getifaddrs])
679
680AC_CHECK_TYPE([struct mmsghdr], AC_DEFINE(HAVE_MMSGHDR, 1, [If sys/socket.h has a struct mmsghdr.]), [], [
681AC_INCLUDES_DEFAULT
682#include <sys/socket.h>
683])
684
685AC_ARG_ENABLE(recvmmsg, AS_HELP_STRING([--enable-recvmmsg],[Enable recvmmsg and sendmmsg compilation, faster but some kernel versions may have implementation problems for IPv6]))
686case "$enable_recvmmsg" in
687        yes)
688		AC_CHECK_FUNC([recvmmsg], [
689AC_RUN_IFELSE([AC_LANG_SOURCE([[
690#ifdef HAVE_UNISTD_H
691#include <unistd.h>
692#endif
693#include <sys/socket.h>
694#include <errno.h>
695int main(void)
696{
697	int s = socket(AF_INET, SOCK_DGRAM, 0);
698	int r = recvmmsg(s, 0, 0, 0, 0) == -1 && errno == ENOSYS;
699	close(s);
700	return r;
701}
702]])], [
703AC_DEFINE([HAVE_RECVMMSG], [1], [Define if recvmmsg is implemented])], [
704], [
705AC_DEFINE([HAVE_RECVMMSG], [1], [Define if recvmmsg exists])]
706)])
707		AC_CHECK_FUNC([sendmmsg], [
708AC_RUN_IFELSE([AC_LANG_SOURCE([[
709#ifdef HAVE_UNISTD_H
710#include <unistd.h>
711#endif
712#include <sys/socket.h>
713#include <errno.h>
714int main(void)
715{
716	int s = socket(AF_INET, SOCK_DGRAM, 0);
717	int r = sendmmsg(s, 0, 0, 0) == -1 && errno == ENOSYS;
718	close(s);
719	return r;
720}
721]])], [
722AC_DEFINE([HAVE_SENDMMSG], [1], [Define if sendmmsg is implemented])], [
723], [
724AC_DEFINE([HAVE_SENDMMSG], [1], [Define if sendmmsg exists])]
725)])
726
727		;;
728        no|*)
729                ;;
730esac
731
732# check if setreuid en setregid fail, on MacOSX10.4(darwin8).
733if echo $target_os | $GREP -i darwin8 > /dev/null; then
734	AC_DEFINE(DARWIN_BROKEN_SETREUID, 1, [Define this if on macOSX10.4-darwin8 and setreuid and setregid do not work])
735fi
736
737# GNU HURD needs _GNU_SOURCE defined for cpu affinity gear
738if echo $target_os | $EGREP -i 'linux|hurd' > /dev/null; then
739  AC_DEFINE([_GNU_SOURCE, 1, [Define this if on Linux or GNU Hurd for cpu affinity interface]])
740fi
741
742# see comment on _GNU_SOURCE above
743AC_CHECK_HEADERS([sched.h sys/cpuset.h],,, [AC_INCLUDES_DEFAULT])
744
745# Check for cpu_set_t (Linux) and cpuset_t (FreeBSD and NetBSD)
746AC_CHECK_TYPES([cpu_set_t, cpuset_t, cpuid_t],,,[
747AC_INCLUDES_DEFAULT
748#if HAVE_SCHED_H
749# include <sched.h>
750#endif
751#if HAVE_SYS_CPUSET_H
752# include <sys/cpuset.h>
753#endif
754])
755
756AC_DEFUN([AC_CHECK_CPU_OR],
757[AC_REQUIRE([AC_PROG_CC])
758AC_MSG_CHECKING(whether CPU_OR works with three arguments)
759AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifdef HAVE_SCHED_H
760# include <sched.h>
761#endif
762#ifdef HAVE_SYS_CPUSET_H
763# include <sys/cpuset.h>
764#endif
765#include <string.h>
766#ifdef HAVE_CPUSET_T
767#define MY_CPUSET_TYPE cpuset_t
768#endif
769#ifdef HAVE_CPU_SET_T
770#define MY_CPUSET_TYPE cpu_set_t
771#endif
772void testing (void) {
773	MY_CPUSET_TYPE a, b;
774	memset(&a, 0, sizeof(a));
775	memset(&b, 0, sizeof(b));
776	CPU_OR(&a, &a, &b);
777}]], [[
778        testing();
779]])],[
780	AC_MSG_RESULT(yes)
781	AC_DEFINE([CPU_OR_THREE_ARGS], 1, [number of arguments for CPU_OR is three])
782],[
783	AC_MSG_RESULT(no)
784])])
785
786AS_IF([test x"$ac_cv_type_cpuset_t" = xyes -o x"$ac_cv_type_cpu_set_t" = xyes ],[
787	AC_CHECK_FUNC(cpuset_create)
788	AC_CHECK_FUNC(cpuset_destroy)
789	AC_CHECK_FUNC(cpuset_zero)
790	AC_CHECK_FUNC(cpuset_set)
791	AC_CHECK_FUNC(cpuset_clr)
792	AC_CHECK_FUNC(cpuset_isset)
793	AC_CHECK_FUNC(cpuset_size)
794	AC_LIBOBJ(cpuset)
795	AC_CHECK_FUNCS([sysconf])
796	AC_CHECK_CPU_OR
797])
798
799#
800# sched_setaffinity must be checked using proper includes.
801# also needs _GNU_SOURCE on Linux and Hurd; see above.
802# also see https://github.com/NLnetLabs/nsd/issues/82.
803#
804AC_MSG_CHECKING(for sched_setaffinity)
805AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
806  [[
807    #ifdef HAVE_SCHED_H
808    # include <sched.h>
809    #endif
810    #ifdef HAVE_SYS_CPUSET_H
811    #include <sys/cpuset.h>
812    #endif
813    #ifdef HAVE_CPUSET_T
814    #define MY_CPUSET_TYPE cpuset_t
815    #endif
816    #ifdef HAVE_CPU_SET_T
817    #define MY_CPUSET_TYPE cpu_set_t
818    #endif
819    void testing (void) {
820      MY_CPUSET_TYPE set;
821      CPU_ZERO(&set);
822      (void)sched_setaffinity(-1, sizeof(set), &set);
823    }
824]])],
825[  AC_MSG_RESULT(yes)
826   AC_DEFINE(HAVE_SCHED_SETAFFINITY, 1, [Define this if sched_setaffinity is available])],
827[  AC_MSG_RESULT(no)])
828
829#
830# Checking for missing functions we can replace
831#
832AC_REPLACE_FUNCS(basename)
833AC_REPLACE_FUNCS(inet_aton)
834AC_REPLACE_FUNCS(inet_pton)
835AC_REPLACE_FUNCS(inet_ntop)
836AC_REPLACE_FUNCS(snprintf)
837AC_REPLACE_FUNCS(strlcat)
838AC_REPLACE_FUNCS(strlcpy)
839AC_REPLACE_FUNCS(strptime)
840AC_REPLACE_FUNCS(b64_pton)
841AC_REPLACE_FUNCS(b64_ntop)
842AC_REPLACE_FUNCS(pselect)
843AC_REPLACE_FUNCS(memmove)
844AC_REPLACE_FUNCS(setproctitle)
845AC_REPLACE_FUNCS(explicit_bzero)
846AC_MSG_CHECKING([for reallocarray])
847AC_LINK_IFELSE([AC_LANG_SOURCE(
848[[
849#ifndef _OPENBSD_SOURCE
850#define _OPENBSD_SOURCE 1
851#endif
852]]
853AC_INCLUDES_DEFAULT
854[[
855#include <stdlib.h>
856int main(void) {
857	void* p = reallocarray(NULL, 10, 100);
858	free(p);
859	return 0;
860}
861]])], [AC_MSG_RESULT(yes)
862	AC_DEFINE(HAVE_REALLOCARRAY, 1, [If we have reallocarray(3)])
863	AC_CHECK_DECLS([reallocarray], [], [
864		AC_DEFINE(REALLOCARRAY_NEEDS_DEFINES, 1, [If reallocarray needs defines to appear in the headers])
865	], [
866AC_INCLUDES_DEFAULT
867#include <stdlib.h>
868	])
869], [
870	AC_MSG_RESULT(no)
871	AC_LIBOBJ(reallocarray)
872])
873
874AC_MSG_CHECKING(for pselect prototype in sys/select.h)
875AC_EGREP_HEADER([[^a-zA-Z_]*pselect[^a-zA-Z_]], sys/select.h, AC_DEFINE(HAVE_PSELECT_PROTO, 1,
876	[if sys/select.h provides pselect prototype]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
877
878AC_MSG_CHECKING(for ctime_r prototype in time.h)
879AC_EGREP_HEADER([[^a-zA-Z_]*ctime_r[^a-zA-Z_]], time.h, AC_DEFINE(HAVE_CTIME_R_PROTO, 1,
880	[if time.h provides ctime_r prototype]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
881
882AC_CHECK_TYPE([struct timespec], AC_DEFINE(HAVE_STRUCT_TIMESPEC, 1, [If time.h has a struct timespec (for pselect).]), [], [
883AC_INCLUDES_DEFAULT
884#ifdef HAVE_SIGNAL_H
885#include <signal.h>
886#endif
887#ifdef HAVE_TIME_H
888#include <time.h>
889#endif
890])
891
892dnl
893dnl Some random defines's
894dnl
895AC_DEFINE_UNQUOTED([IDENTITY], ["unidentified server"], [Define to the default nsd identity.])
896AC_DEFINE_UNQUOTED([VERSION], [PACKAGE_STRING], [Define to the NSD version to answer version.server query.])
897AC_DEFINE_UNQUOTED([TCP_BACKLOG], [256], [Define to the backlog to be used with listen.])
898AC_DEFINE_UNQUOTED([TCP_PORT], ["53"], [Define to the default tcp port.])
899AC_DEFINE_UNQUOTED([TCP_MAX_MESSAGE_LEN], [65535], [Define to the default maximum message length.])
900AC_DEFINE_UNQUOTED([UDP_PORT], ["53"], [Define to the default udp port.])
901AC_DEFINE_UNQUOTED([UDP_MAX_MESSAGE_LEN], [512], [Define to the default maximum udp message length.])
902AC_DEFINE_UNQUOTED([EDNS_MAX_MESSAGE_LEN], [1232], [Define to the default maximum message length with EDNS.])
903AC_DEFINE_UNQUOTED([TLS_PORT], ["853"], [Define to the default DNS over TLS port.])
904AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [512], [Define to the maximum message length to pass to syslog.])
905AC_DEFINE_UNQUOTED([NSD_CONTROL_PORT], [8952], [Define to the default nsd-control port.])
906AC_DEFINE_UNQUOTED([NSD_CONTROL_VERSION], [1], [Define to nsd-control proto version.])
907AC_DEFINE_UNQUOTED([VERIFY_PORT], ["5347"], [Define to the default zone verification udp port.])
908
909dnl
910dnl Determine the syslog facility to use
911dnl
912facility=LOG_DAEMON
913AC_ARG_WITH([facility],
914        AS_HELP_STRING([--with-facility=name],[Syslog default facility (LOG_DAEMON)]),
915        [facility=$withval])
916AC_DEFINE_UNQUOTED([FACILITY], $facility, [Define to the default facility for syslog.])
917
918dnl
919dnl Determine the default tcp timeout
920dnl
921tcp_timeout=120
922AC_ARG_WITH([tcp_timeout],
923	AS_HELP_STRING([--with-tcp-timeout=number],[Limit the default tcp timeout]),
924	[tcp_timeout=$withval])
925AC_DEFINE_UNQUOTED([TCP_TIMEOUT], $tcp_timeout, [Define to the default tcp timeout.])
926
927dnl
928dnl Features
929dnl
930AC_ARG_ENABLE(root-server, AS_HELP_STRING([--enable-root-server],[Configure NSD as a root server (obsolete)]))
931
932AC_ARG_ENABLE(ipv6, AS_HELP_STRING([--disable-ipv6],[Disables IPv6 support]))
933case "$enable_ipv6" in
934        no)
935                ;;
936        yes|*)
937		AC_DEFINE_UNQUOTED([INET6], [], [Define this to enable IPv6 support.])
938		;;
939esac
940
941AC_ARG_ENABLE(bind8-stats, AS_HELP_STRING([--enable-bind8-stats],[Enables BIND8 like NSTATS & XSTATS and statistics in nsd-control]))
942
943case "$enable_bind8_stats" in
944	yes|'')
945		AC_DEFINE_UNQUOTED([BIND8_STATS], [], [Define this to enable BIND8 like NSTATS & XSTATS.])
946		;;
947	no|*)
948		;;
949esac
950
951AC_ARG_ENABLE(zone-stats, AS_HELP_STRING([--enable-zone-stats],[Enable per-zone statistics gathering (needs --enable-bind8-stats)]))
952case "$enable_zone_stats" in
953	yes)
954		AC_DEFINE_UNQUOTED([USE_ZONE_STATS], [], [Define this to enable per-zone statistics gathering.])
955		AC_DEFINE_UNQUOTED([BIND8_STATS], [], [Define this to enable BIND8 like NSTATS & XSTATS.])
956		;;
957	no|''|*)
958		;;
959esac
960
961AC_ARG_ENABLE(checking, AS_HELP_STRING([--enable-checking],[Enable internal runtime checks]))
962case "$enable_checking" in
963        yes)
964		CHECK_COMPILER_FLAG(W, [ CFLAGS="$CFLAGS -W" ])
965		CHECK_COMPILER_FLAG(Wall, [ CFLAGS="$CFLAGS -Wall" ])
966		CHECK_COMPILER_FLAG(Wextra, [ CFLAGS="$CFLAGS -Wextra" ])
967		CHECK_COMPILER_FLAG(Wdeclaration-after-statement, [ CFLAGS="$CFLAGS -Wdeclaration-after-statement" ])
968		;;
969        no|*)
970                AC_DEFINE([NDEBUG], [], [Undefine this to enable internal runtime checks.])
971                ;;
972esac
973
974AC_ARG_ENABLE(memclean, AS_HELP_STRING([--enable-memclean],[Cleanup memory (at exit) for eg. valgrind, memcheck]))
975if test "$enable_memclean" = "yes"; then AC_DEFINE_UNQUOTED([MEMCLEAN], [1], [Define this to cleanup memory at exit (eg. for valgrind, etc.)])
976fi
977
978AC_ARG_ENABLE(ratelimit, AS_HELP_STRING([--enable-ratelimit],[Enable rate limiting]))
979case "$enable_ratelimit" in
980	yes)
981		AC_DEFINE_UNQUOTED([RATELIMIT], [], [Define this to enable rate limiting.])
982		dnl causes awk to not match the exclusion start marker.
983		ratelimit="xx"
984		;;
985	no|*)
986		ratelimit=""
987		;;
988esac
989AC_SUBST(ratelimit)
990
991AC_ARG_ENABLE(ratelimit-default-is-off, AS_HELP_STRING([--enable-ratelimit-default-is-off],[Enable this to set default of ratelimit to off (enable in nsd.conf), otherwise ratelimit is enabled by default if --enable-ratelimit is enabled]))
992case "$enable_ratelimit_default_is_off" in
993	yes)
994		AC_DEFINE_UNQUOTED([RATELIMIT_DEFAULT_OFF], [], [Define this to set ratelimit to off by default.])
995		ratelimit_default="off"
996		;;
997	no|*)
998		ratelimit_default="on"
999		;;
1000esac
1001AC_SUBST(ratelimit_default)
1002
1003# we need SSL for TSIG (and maybe also for NSEC3).
1004CHECK_SSL
1005if test x$HAVE_SSL = x"yes"; then
1006	ACX_LIB_SSL
1007	# remove space after -ldl if there.
1008	LIBS=`echo "$LIBS" | sed -e 's/ $//'`
1009
1010	# Check for -pthread
1011	BAKLIBS="$LIBS"
1012	LIBS="-lcrypto $LIBS"
1013	AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
1014		int EVP_sha256(void);
1015		(void)EVP_sha256();
1016	]])],[],[
1017		dnl so link fails for EVP_sha256, try with -pthread.
1018		BAKCFLAGS="$CFLAGS"
1019		CFLAGS="$CFLAGS -pthread"
1020		AC_MSG_CHECKING([if libcrypto needs -pthread])
1021		AC_TRY_LINK_FUNC([EVP_sha256], [
1022			AC_MSG_RESULT([yes])
1023		] , [
1024			AC_MSG_RESULT([no])
1025			dnl restore the nonpthread value
1026			CFLAGS="$BAKCFLAGS"
1027		])
1028	])
1029	LIBS="$BAKLIBS"
1030
1031	if test -n "$ssldir"; then
1032            AC_CHECK_LIB(crypto, EVP_sha256,, [
1033                    AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required])
1034                ])
1035	fi
1036	SSL_LIBS="-lssl"
1037	AC_SUBST(SSL_LIBS)
1038	AC_CHECK_HEADERS([openssl/ssl.h openssl/err.h openssl/rand.h openssl/ocsp.h openssl/core_names.h],,, [AC_INCLUDES_DEFAULT])
1039	AC_CHECK_FUNCS([HMAC_CTX_reset HMAC_CTX_new EVP_cleanup ERR_load_crypto_strings OPENSSL_init_crypto CRYPTO_memcmp EC_KEY_new_by_curve_name EVP_MAC_CTX_new EVP_MAC_CTX_set_params EVP_MAC_CTX_get_mac_size SHA1_Init])
1040	if test "$ac_cv_func_SHA1_Init" = "yes"; then
1041		ACX_FUNC_DEPRECATED([SHA1_Init], [(void)SHA1_Init(NULL);], [
1042#include <openssl/sha.h>
1043])
1044	fi
1045	AC_CHECK_DECLS([SSL_CTX_set_ecdh_auto,SSL_CTX_set_tmp_ecdh], [], [], [
1046AC_INCLUDES_DEFAULT
1047#ifdef HAVE_OPENSSL_ERR_H
1048#include <openssl/err.h>
1049#endif
1050
1051#ifdef HAVE_OPENSSL_RAND_H
1052#include <openssl/rand.h>
1053#endif
1054
1055#ifdef HAVE_OPENSSL_CONF_H
1056#include <openssl/conf.h>
1057#endif
1058
1059#ifdef HAVE_OPENSSL_ENGINE_H
1060#include <openssl/engine.h>
1061#endif
1062#include <openssl/ssl.h>
1063#include <openssl/evp.h>
1064])
1065	AC_CHECK_DECL([TLS1_3_VERSION], 
1066		[AC_DEFINE([HAVE_TLS_1_3], [1], [Define if TLS 1.3 is supported by OpenSSL])],
1067		[AC_MSG_WARN([No TLS 1.3, therefore XFR-over-TLS is disabled])], [[#include <openssl/ssl.h>]])
1068
1069	BAKLIBS="$LIBS"
1070	LIBS="-lssl $LIBS"
1071	AC_CHECK_FUNCS([OPENSSL_init_ssl SSL_get1_peer_certificate SSL_CTX_set_security_level ERR_load_SSL_strings])
1072	if test "$ac_cv_func_ERR_load_SSL_strings" = "yes"; then
1073		ACX_FUNC_DEPRECATED([ERR_load_SSL_strings], [(void)ERR_load_SSL_strings();], [
1074#include <openssl/ssl.h>
1075])
1076	fi
1077	LIBS="$BAKLIBS"
1078
1079else
1080	AC_MSG_WARN([No SSL, therefore TLS is disabled])
1081fi
1082
1083AC_ARG_ENABLE(nsec3, AS_HELP_STRING([--disable-nsec3],[Disable NSEC3 support]))
1084case "$enable_nsec3" in
1085        no)
1086		;;
1087        yes)
1088		AC_DEFINE_UNQUOTED([NSEC3], [], [Define this to enable NSEC3 support.])
1089		;;
1090		*)
1091		if test x$HAVE_SSL = x"yes"; then
1092			AC_DEFINE_UNQUOTED([NSEC3], [], [Define this to enable NSEC3 support.])
1093		else
1094			AC_MSG_WARN([No SSL, therefore NSEC3 is disabled])
1095		fi
1096                ;;
1097esac
1098
1099AC_ARG_ENABLE(minimal-responses, AS_HELP_STRING([--disable-minimal-responses],[Disable response minimization. More truncation.]))
1100case "$enable_minimal_responses" in
1101        no)
1102		;;
1103        yes|*)
1104		AC_DEFINE_UNQUOTED([MINIMAL_RESPONSES], [], [Define this to enable response minimalization to reduce truncation.])
1105                ;;
1106esac
1107
1108AC_ARG_ENABLE(mmap, AS_HELP_STRING([--enable-mmap],[Use mmap instead of malloc. Experimental.]))
1109case "$enable_mmap" in
1110        yes)
1111		AC_CHECK_HEADERS([sys/mman.h],,, [AC_INCLUDES_DEFAULT])
1112		AC_LIBGTOP_CHECK_TYPE(uintptr_t, void*)
1113		AC_CHECK_FUNCS([mmap munmap])
1114		AC_DEFINE_UNQUOTED([USE_MMAP_ALLOC], [], [Define this to enable mmap instead of malloc. Experimental.])
1115		;;
1116        no|*)
1117                ;;
1118esac
1119
1120AC_ARG_ENABLE(radix-tree, AS_HELP_STRING([--disable-radix-tree],[You can disable the radix tree and use the red-black tree for the main lookups, the red-black tree uses less memory, but uses some more CPU.]))
1121case "$enable_radix_tree" in
1122        no)
1123	;;
1124	yes|*)
1125	AC_DEFINE_UNQUOTED([USE_RADIX_TREE], [], [Define this to configure to use the radix tree.])
1126	;;
1127esac
1128
1129AC_ARG_ENABLE(packed, AS_HELP_STRING([--enable-packed],[Enable packed structure alignment, uses less memory, but unaligned reads.]))
1130case "$enable_packed" in
1131	yes)
1132	AC_DEFINE_UNQUOTED([PACKED_STRUCTS], [], [Define this to use packed structure alignment.])
1133	ACX_CHECK_COMPILER_FLAG(Wno-address-of-packed-member, [CFLAGS="$CFLAGS -Wno-address-of-packed-member"])
1134	;;
1135	no|*)
1136	;;
1137esac
1138
1139# check for dnstap if requested
1140dt_DNSTAP([${localstatedir}/run/nsd-dnstap.sock],
1141    [
1142        AC_DEFINE([USE_DNSTAP], [1], [Define to 1 to enable dnstap support])
1143        AC_SUBST([ENABLE_DNSTAP], [1])
1144
1145        AC_SUBST([opt_dnstap_socket_path])
1146        ACX_ESCAPE_BACKSLASH($opt_dnstap_socket_path, hdr_dnstap_socket_path)
1147        AC_DEFINE_UNQUOTED(DNSTAP_SOCKET_PATH,
1148            ["$hdr_dnstap_socket_path"], [default dnstap socket path])
1149
1150        AC_SUBST([DNSTAP_SRC], ["dnstap/dnstap.c dnstap/dnstap.pb-c.c dnstap/dnstap_collector.c"])
1151        AC_SUBST([DNSTAP_OBJ], ["dnstap.o dnstap_collector.o dnstap.pb-c.o"])
1152	dnstap_config="dnstap/dnstap_config.h"
1153    ],
1154    [
1155        AC_SUBST([ENABLE_DNSTAP], [0])
1156    ]
1157)
1158
1159# Include systemd.m4 - begin
1160sinclude(systemd.m4)
1161# Include systemd.m4 - end
1162
1163AC_ARG_ENABLE(tcp-fastopen, AS_HELP_STRING([--enable-tcp-fastopen],[Enable TCP Fast Open]))
1164case "$enable_tcp_fastopen" in
1165       yes)
1166             AC_CHECK_DECL([TCP_FASTOPEN], [], [AC_MSG_ERROR([TCP Fast Open is not available: please rerun without --enable-tcp-fastopen])], [AC_INCLUDES_DEFAULT
1167#include <netinet/tcp.h>
1168             ])
1169               AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])
1170               ;;
1171       no|*)
1172               ;;
1173esac
1174
1175AH_BOTTOM([
1176/* define before includes as it specifies what standard to use. */
1177#if (defined(HAVE_PSELECT) && !defined (HAVE_PSELECT_PROTO)) \
1178	|| !defined (HAVE_CTIME_R_PROTO) \
1179	|| defined (STRPTIME_NEEDS_DEFINES) || defined(REALLOCARRAY_NEEDS_DEFINES)
1180#  ifndef _XOPEN_SOURCE
1181#    define _XOPEN_SOURCE 600
1182#  endif
1183#  ifndef _POSIX_C_SOURCE
1184#    define _POSIX_C_SOURCE 200112
1185#  endif
1186#  ifndef _BSD_SOURCE
1187#    define _BSD_SOURCE 1
1188#  endif
1189#  ifndef _OPENBSD_SOURCE
1190#    define _OPENBSD_SOURCE 1
1191#  endif
1192#  ifndef _DEFAULT_SOURCE
1193#    define _DEFAULT_SOURCE 1
1194#  endif
1195#  ifndef __EXTENSIONS__
1196#    define __EXTENSIONS__ 1
1197#  endif
1198#  ifndef _STDC_C99
1199#    define _STDC_C99 1
1200#  endif
1201#  ifndef _ALL_SOURCE
1202#    define _ALL_SOURCE 1
1203#  endif
1204#endif
1205])
1206
1207AH_BOTTOM([
1208#ifdef HAVE_VA_LIST_DOUBLE_DEF
1209/* workaround double va_list definition on some platforms */
1210#  ifndef _VA_LIST_DEFINED
1211#    define _VA_LIST_DEFINED
1212#  endif
1213#endif
1214])
1215
1216AH_BOTTOM([
1217#include <sys/types.h>
1218#include <stdlib.h>
1219#include <stddef.h>
1220#include <string.h>
1221
1222#ifdef HAVE_TIME_H
1223#include <time.h>
1224#endif
1225
1226#ifdef HAVE_STDINT_H
1227#include <stdint.h>
1228#endif
1229
1230#ifdef HAVE_SYS_SOCKET_H
1231#include <sys/socket.h>
1232#endif
1233
1234#ifdef HAVE_NETINET_IN_H
1235#include <netinet/in.h>
1236#endif
1237
1238#ifdef HAVE_NETINET_TCP_H
1239#include <netinet/tcp.h>
1240#endif
1241
1242#ifdef HAVE_ARPA_INET_H
1243#include <arpa/inet.h>
1244#endif
1245
1246/* For Tru64 */
1247#ifdef HAVE_SYS_BITYPES_H
1248#include <sys/bitypes.h>
1249#endif
1250])
1251
1252AH_BOTTOM([
1253#ifdef HAVE_ATTR_FORMAT
1254#define ATTR_FORMAT(archetype, string_index, first_to_check) \
1255    __attribute__ ((format (archetype, string_index, first_to_check)))
1256#else /* !HAVE_ATTR_FORMAT */
1257#define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */
1258#endif /* !HAVE_ATTR_FORMAT */
1259#if defined(__cplusplus)
1260#define ATTR_UNUSED(x)
1261#elif defined(HAVE_ATTR_UNUSED)
1262#define ATTR_UNUSED(x)  x __attribute__((unused))
1263#else /* !HAVE_ATTR_UNUSED */
1264#define ATTR_UNUSED(x)  x
1265#endif /* !HAVE_ATTR_UNUSED */
1266])
1267
1268AH_BOTTOM([
1269#ifndef IPV6_MIN_MTU
1270#define IPV6_MIN_MTU 1280
1271#endif /* IPV6_MIN_MTU */
1272
1273#ifndef AF_INET6
1274#define AF_INET6	28
1275#endif /* AF_INET6 */
1276])
1277
1278if test $ac_cv_func_getaddrinfo = no; then
1279AC_LIBOBJ([fake-rfc2553])
1280fi
1281
1282AH_BOTTOM([
1283/* maximum nesting of included files */
1284#define MAXINCLUDES 10
1285])
1286
1287AH_BOTTOM([
1288#ifndef HAVE_B64_NTOP
1289int b64_ntop(uint8_t const *src, size_t srclength,
1290	     char *target, size_t targsize);
1291#endif /* !HAVE_B64_NTOP */
1292#ifndef HAVE_B64_PTON
1293int b64_pton(char const *src, uint8_t *target, size_t targsize);
1294#endif /* !HAVE_B64_PTON */
1295#ifndef HAVE_FSEEKO
1296#define fseeko fseek
1297#define ftello ftell
1298#endif /* HAVE_FSEEKO */
1299#ifndef HAVE_SNPRINTF
1300#include <stdarg.h>
1301int snprintf (char *str, size_t count, const char *fmt, ...);
1302int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
1303#endif /* HAVE_SNPRINTF */
1304#ifndef HAVE_INET_PTON
1305int inet_pton(int af, const char* src, void* dst);
1306#endif /* HAVE_INET_PTON */
1307#ifndef HAVE_INET_NTOP
1308const char *inet_ntop(int af, const void *src, char *dst, size_t size);
1309#endif
1310#ifndef HAVE_INET_ATON
1311int inet_aton(const char *cp, struct in_addr *addr);
1312#endif
1313#ifndef HAVE_MEMMOVE
1314void *memmove(void *dest, const void *src, size_t n);
1315#endif
1316#ifndef HAVE_EXPLICIT_BZERO
1317#define explicit_bzero nsd_explicit_bzero
1318void explicit_bzero(void* buf, size_t len);
1319#endif
1320#ifndef HAVE_STRLCAT
1321size_t strlcat(char *dst, const char *src, size_t siz);
1322#endif
1323#ifndef HAVE_STRLCPY
1324size_t strlcpy(char *dst, const char *src, size_t siz);
1325#endif
1326#ifndef HAVE_REALLOCARRAY
1327void* reallocarray(void *ptr, size_t nmemb, size_t size);
1328#endif
1329#ifndef HAVE_GETADDRINFO
1330#include "compat/fake-rfc2553.h"
1331#endif
1332#ifndef HAVE_STRPTIME
1333#define HAVE_STRPTIME 1
1334char *strptime(const char *s, const char *format, struct tm *tm);
1335#endif
1336#ifndef STRPTIME_WORKS
1337#define STRPTIME_WORKS 1
1338char *nsd_strptime(const char *s, const char *format, struct tm *tm);
1339#define strptime(a,b,c) nsd_strptime((a),(b),(c))
1340#endif
1341#if (HAVE_CPU_SET_T || HAVE_CPUSET_T)
1342#include "compat/cpuset.h"
1343#endif
1344#ifndef HAVE_SETPROCTITLE
1345#ifdef __linux__
1346#define HAVE_SETPROCTITLE 1
1347#include <stdarg.h>
1348void setproctitle(const char *fmt, ...);
1349#endif
1350#endif
1351])
1352AH_BOTTOM(
1353AHX_MEMCMP_BROKEN(nsd)
1354AHX_CONFIG_MAXHOSTNAMELEN
1355)
1356AH_BOTTOM([
1357
1358/* provide timespec def if not available */
1359#ifndef CONFIG_DEFINES
1360#define CONFIG_DEFINES
1361#ifndef HAVE_STRUCT_TIMESPEC
1362#ifndef __timespec_defined
1363#define __timespec_defined 1
1364	struct timespec {
1365		long    tv_sec;         /* seconds */
1366		long    tv_nsec;        /* nanoseconds */
1367	};
1368#endif /* !__timespec_defined */
1369#endif /* !HAVE_STRUCT_TIMESPEC */
1370#endif /* !CONFIG_DEFINES */
1371
1372#ifdef PACKED_STRUCTS
1373#define ATTR_PACKED __attribute__((packed))
1374#else
1375#define ATTR_PACKED
1376#endif
1377])
1378
1379# big fat warning
1380if test "$enable_checking" = "yes"; then
1381        echo "************************************************"
1382        echo "* You have activated \"--enable-checking\"       *"
1383        echo "*                                              *"
1384        echo "* This will instruct NSD to be stricter        *"
1385        echo "* when validating its input. This could lead   *"
1386        echo "* to a reduced service level.                  *"
1387        echo "*                                              *"
1388        echo "************************************************"
1389fi
1390
1391AC_CONFIG_FILES([Makefile $dnstap_config])
1392AC_OUTPUT
1393