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