blob: 91eb70ff368bfe534a068b5fd820e76cd83cf126 [file] [log] [blame]
Simon Kelley59546082012-01-06 20:02:04 +00001/* dnsmasq is Copyright (c) 2000-2012 Simon Kelley
Simon Kelley9e4abcb2004-01-22 19:47:41 +00002
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
Simon Kelley824af852008-02-12 20:43:05 +00005 the Free Software Foundation; version 2 dated June, 1991, or
6 (at your option) version 3 dated 29 June, 2007.
7
Simon Kelley9e4abcb2004-01-22 19:47:41 +00008 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
Simon Kelley824af852008-02-12 20:43:05 +000012
Simon Kelley73a08a22009-02-05 20:28:08 +000013 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
Simon Kelley9e4abcb2004-01-22 19:47:41 +000015*/
16
Simon Kelley208b65c2006-08-05 21:41:37 +010017#define FTABSIZ 150 /* max number of outstanding requests (default) */
Simon Kelleyfeba5c12004-07-27 20:28:58 +010018#define MAX_PROCS 20 /* max no children for TCP requests */
19#define CHILD_LIFETIME 150 /* secs 'till terminated (RFC1035 suggests > 120s) */
Simon Kelley316e2732010-01-22 20:16:09 +000020#define EDNS_PKTSZ 4096 /* default max EDNS.0 UDP packet from RFC5625 */
Simon Kelley7b4ad2e2012-04-04 14:05:35 +010021#define KEYBLOCK_LEN 140 /* choose to mininise fragmentation when storing DNSSEC keys */
Simon Kelley16972692006-10-16 20:04:18 +010022#define TIMEOUT 10 /* drop UDP queries after TIMEOUT seconds */
Simon Kelley1f15b812009-10-13 17:49:32 +010023#define FORWARD_TEST 50 /* try all servers every 50 queries */
Simon Kelley28866e92011-02-14 20:19:14 +000024#define FORWARD_TIME 20 /* or 20 seconds */
Simon Kelley1a6bca82008-07-11 11:11:42 +010025#define RANDOM_SOCKS 64 /* max simultaneous random ports */
Simon Kelleycdeda282006-03-16 20:16:06 +000026#define LEASE_RETRY 60 /* on error, retry writing leasefile after LEASE_RETRY seconds */
Simon Kelley9e4abcb2004-01-22 19:47:41 +000027#define CACHESIZ 150 /* default cache size */
Simon Kelley316e2732010-01-22 20:16:09 +000028#define MAXLEASES 1000 /* maximum number of DHCP leases */
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010029#define PING_WAIT 3 /* wait for ping address-in-use test */
30#define PING_CACHE_TIME 30 /* Ping test assumed to be valid this long. */
Simon Kelley849a8352006-06-09 21:02:31 +010031#define DECLINE_BACKOFF 600 /* disable DECLINEd static addresses for this long */
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010032#define DHCP_PACKET_MAX 16384 /* hard limit on DHCP packet size */
Simon Kelley9e4abcb2004-01-22 19:47:41 +000033#define SMALLDNAME 40 /* most domain names are smaller than this */
Simon Kelley9e4abcb2004-01-22 19:47:41 +000034#define HOSTSFILE "/etc/hosts"
Simon Kelley44a2a312004-03-10 20:04:35 +000035#define ETHERSFILE "/etc/ethers"
Simon Kelleyc72daea2012-01-05 21:33:27 +000036#define DEFLEASE 3600 /* default lease time, 1 hour */
37#define CHUSER "nobody"
38#define CHGRP "dip"
39#define TFTP_MAX_CONNECTIONS 50 /* max simultaneous connections */
40#define LOG_MAX 5 /* log-queue length */
41#define RANDFILE "/dev/urandom"
42#define EDNS0_OPTION_MAC 5 /* dyndns.org temporary assignment */
Simon Kelleyad094272012-08-10 17:10:54 +010043#define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* Default - may be overridden by config */
Simon Kelleyc72daea2012-01-05 21:33:27 +000044#define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
Simon Kelley4f7b3042012-11-28 21:27:02 +000045#define AUTH_TTL 600 /* default TTL for auth DNS */
46#define SOA_REFRESH 1200 /* SOA refresh default */
47#define SOA_RETRY 180 /* SOA retry default */
48#define SOA_EXPIRY 1209600 /* SOA expiry default */
Simon Kelley55b548a2012-12-29 17:13:04 +000049#define RA_INTERVAL 600 /* Send unsolicited RA's this often when not provoked. */
Simon Kelley4f7b3042012-11-28 21:27:02 +000050
Simon Kelleyc72daea2012-01-05 21:33:27 +000051/* compile-time options: uncomment below to enable or do eg.
52 make COPTS=-DHAVE_BROKEN_RTC
53
54HAVE_BROKEN_RTC
55 define this on embedded systems which don't have an RTC
56 which keeps time over reboots. Causes dnsmasq to use uptime
57 for timing, and keep lease lengths rather than expiry times
58 in its leases file. This also make dnsmasq "flash disk friendly".
59 Normally, dnsmasq tries very hard to keep the on-disk leases file
60 up-to-date: rewriting it after every renewal. When HAVE_BROKEN_RTC
61 is in effect, the lease file is only written when a new lease is
62 created, or an old one destroyed. (Because those are the only times
63 it changes.) This vastly reduces the number of file writes, and makes
64 it viable to keep the lease file on a flash filesystem.
65 NOTE: when enabling or disabling this, be sure to delete any old
66 leases file, otherwise dnsmasq may get very confused.
67
68HAVE_TFTP
69 define this to get dnsmasq's built-in TFTP server.
70
71HAVE_DHCP
72 define this to get dnsmasq's DHCPv4 server.
73
74HAVE_DHCP6
75 define this to get dnsmasq's DHCPv6 server. (implies HAVE_DHCP).
76
77HAVE_SCRIPT
78 define this to get the ability to call scripts on lease-change.
79
80HAVE_LUASCRIPT
81 define this to get the ability to call Lua script on lease-change. (implies HAVE_SCRIPT)
82
83HAVE_DBUS
84 define this if you want to link against libdbus, and have dnsmasq
85 support some methods to allow (re)configuration of the upstream DNS
86 servers via DBus.
87
88HAVE_IDN
89 define this if you want international domain name support.
90 NOTE: for backwards compatibility, IDN support is automatically
91 included when internationalisation support is built, using the
92 *-i18n makefile targets, even if HAVE_IDN is not explicitly set.
93
94HAVE_CONNTRACK
95 define this to include code which propogates conntrack marks from
96 incoming DNS queries to the corresponding upstream queries. This adds
97 a build-dependency on libnetfilter_conntrack, but the resulting binary will
98 still run happily on a kernel without conntrack support.
99
Simon Kelley4820dce2012-12-18 18:30:30 +0000100HAVE_AUTH
101 define this to include the facility to act as an authoritative DNS
102 server for one or more zones.
103
104
Simon Kelleyc72daea2012-01-05 21:33:27 +0000105NO_IPV6
106NO_TFTP
107NO_DHCP
108NO_DHCP6
109NO_SCRIPT
110NO_LARGEFILE
Simon Kelley4820dce2012-12-18 18:30:30 +0000111NO_AUTH
Simon Kelleyc72daea2012-01-05 21:33:27 +0000112 these are avilable to explictly disable compile time options which would
113 otherwise be enabled automatically (HAVE_IPV6, >2Gb file sizes) or
114 which are enabled by default in the distributed source tree. Building dnsmasq
115 with something like "make COPTS=-DNO_SCRIPT" will do the trick.
116
117LEASEFILE
118CONFFILE
119RESOLVFILE
120 the default locations of these files are determined below, but may be overridden
121 in a build command line using COPTS.
122
123*/
124
125
126/* The default set of options to build. Built with these options, dnsmasq
127 has no library dependencies other than libc */
128
129#define HAVE_DHCP
Simon Kelley07933802012-02-14 20:55:25 +0000130#define HAVE_DHCP6
Simon Kelleyc72daea2012-01-05 21:33:27 +0000131#define HAVE_TFTP
132#define HAVE_SCRIPT
Simon Kelley4820dce2012-12-18 18:30:30 +0000133#define HAVE_AUTH
Simon Kelleyc72daea2012-01-05 21:33:27 +0000134/* #define HAVE_LUASCRIPT */
135/* #define HAVE_BROKEN_RTC */
136/* #define HAVE_DBUS */
137/* #define HAVE_IDN */
138/* #define HAVE_CONNTRACK */
139
140
141
142/* Default locations for important system files. */
Simon Kelley73a08a22009-02-05 20:28:08 +0000143
144#ifndef LEASEFILE
145# if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
146# define LEASEFILE "/var/db/dnsmasq.leases"
147# elif defined(__sun__) || defined (__sun)
148# define LEASEFILE "/var/cache/dnsmasq.leases"
Simon Kelley572b41e2011-02-18 18:11:18 +0000149# elif defined(__ANDROID__)
150# define LEASEFILE "/data/misc/dhcp/dnsmasq.leases"
Simon Kelley73a08a22009-02-05 20:28:08 +0000151# else
152# define LEASEFILE "/var/lib/misc/dnsmasq.leases"
153# endif
Simon Kelleyfeba5c12004-07-27 20:28:58 +0100154#endif
Simon Kelley73a08a22009-02-05 20:28:08 +0000155
156#ifndef CONFFILE
157# if defined(__FreeBSD__)
158# define CONFFILE "/usr/local/etc/dnsmasq.conf"
159# else
160# define CONFFILE "/etc/dnsmasq.conf"
161# endif
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000162#endif
Simon Kelley73a08a22009-02-05 20:28:08 +0000163
Simon Kelleyc72daea2012-01-05 21:33:27 +0000164#ifndef RESOLVFILE
165# if defined(__uClinux__)
166# define RESOLVFILE "/etc/config/resolv.conf"
167# else
168# define RESOLVFILE "/etc/resolv.conf"
169# endif
170#endif
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000171
Simon Kelley55d290a2012-06-29 20:58:32 +0100172#ifndef RUNFILE
173# if defined(__ANDROID__)
174# define RUNFILE "/data/dnsmasq.pid"
175# else
176# define RUNFILE "/var/run/dnsmasq.pid"
177# endif
178#endif
Simon Kelleyc72daea2012-01-05 21:33:27 +0000179
180/* platform dependent options: these are determined automatically below
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000181
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100182HAVE_LINUX_NETWORK
Simon Kelley824af852008-02-12 20:43:05 +0000183HAVE_BSD_NETWORK
184HAVE_SOLARIS_NETWORK
185 define exactly one of these to alter interaction with kernel networking.
186
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000187HAVE_GETOPT_LONG
Simon Kelleyda632e72012-03-26 11:14:05 +0100188 defined when GNU-style getopt_long available.
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000189
190HAVE_ARC4RANDOM
Simon Kelleyc72daea2012-01-05 21:33:27 +0000191 defined if arc4random() available to get better security from DNS spoofs
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000192 by using really random ids (OpenBSD)
193
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000194HAVE_SOCKADDR_SA_LEN
Simon Kelleyc72daea2012-01-05 21:33:27 +0000195 defined if struct sockaddr has sa_len field (*BSD)
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000196*/
197
198/* Must preceed __linux__ since uClinux defines __linux__ too. */
Simon Kelleye17fb622006-01-14 20:33:46 +0000199#if defined(__uClinux__)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100200#define HAVE_LINUX_NETWORK
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000201#define HAVE_GETOPT_LONG
202#undef HAVE_ARC4RANDOM
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000203#undef HAVE_SOCKADDR_SA_LEN
Simon Kelley59353a62004-11-21 19:34:28 +0000204/* Never use fork() on uClinux. Note that this is subtly different from the
205 --keep-in-foreground option, since it also suppresses forking new
Simon Kelley5aabfc72007-08-29 11:24:47 +0100206 processes for TCP connections and disables the call-a-script on leasechange
207 system. It's intended for use on MMU-less kernels. */
Simon Kelleye17fb622006-01-14 20:33:46 +0000208#define NO_FORK
209
210#elif defined(__UCLIBC__)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100211#define HAVE_LINUX_NETWORK
Simon Kelleye17fb622006-01-14 20:33:46 +0000212#if defined(__UCLIBC_HAS_GNU_GETOPT__) || \
213 ((__UCLIBC_MAJOR__==0) && (__UCLIBC_MINOR__==9) && (__UCLIBC_SUBLEVEL__<21))
214# define HAVE_GETOPT_LONG
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100215#endif
Simon Kelleye17fb622006-01-14 20:33:46 +0000216#undef HAVE_ARC4RANDOM
Simon Kelleye17fb622006-01-14 20:33:46 +0000217#undef HAVE_SOCKADDR_SA_LEN
Simon Kelley7cebd202006-05-06 14:13:33 +0100218#if !defined(__ARCH_HAS_MMU__) && !defined(__UCLIBC_HAS_MMU__)
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000219# define NO_FORK
220#endif
Simon Kelley7cebd202006-05-06 14:13:33 +0100221#if defined(__UCLIBC_HAS_IPV6__)
222# ifndef IPV6_V6ONLY
223# define IPV6_V6ONLY 26
224# endif
Simon Kelleye17fb622006-01-14 20:33:46 +0000225#endif
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000226
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000227/* This is for glibc 2.x */
228#elif defined(__linux__)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100229#define HAVE_LINUX_NETWORK
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000230#define HAVE_GETOPT_LONG
231#undef HAVE_ARC4RANDOM
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000232#undef HAVE_SOCKADDR_SA_LEN
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000233
Simon Kelley9e038942008-05-30 20:06:34 +0100234#elif defined(__FreeBSD__) || \
235 defined(__OpenBSD__) || \
236 defined(__DragonFly__) || \
Simon Kelley8ef5ada2010-06-03 19:42:45 +0100237 defined(__FreeBSD_kernel__)
Simon Kelley824af852008-02-12 20:43:05 +0000238#define HAVE_BSD_NETWORK
Simon Kelley59353a62004-11-21 19:34:28 +0000239/* Later verions of FreeBSD have getopt_long() */
240#if defined(optional_argument) && defined(required_argument)
241# define HAVE_GETOPT_LONG
Simon Kelley59353a62004-11-21 19:34:28 +0000242#endif
Simon Kelley8ef5ada2010-06-03 19:42:45 +0100243#if !defined(__FreeBSD_kernel__)
Simon Kelley1a6bca82008-07-11 11:11:42 +0100244# define HAVE_ARC4RANDOM
245#endif
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000246#define HAVE_SOCKADDR_SA_LEN
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000247
248#elif defined(__APPLE__)
Simon Kelley824af852008-02-12 20:43:05 +0000249#define HAVE_BSD_NETWORK
Simon Kelley316e2732010-01-22 20:16:09 +0000250#define HAVE_GETOPT_LONG
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000251#define HAVE_ARC4RANDOM
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000252#define HAVE_SOCKADDR_SA_LEN
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000253/* Define before sys/socket.h is included so we get socklen_t */
254#define _BSD_SOCKLEN_T_
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000255
256#elif defined(__NetBSD__)
Simon Kelley824af852008-02-12 20:43:05 +0000257#define HAVE_BSD_NETWORK
Simon Kelleyfd9fa482004-10-21 20:24:00 +0100258#define HAVE_GETOPT_LONG
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000259#undef HAVE_ARC4RANDOM
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000260#define HAVE_SOCKADDR_SA_LEN
Simon Kelley824af852008-02-12 20:43:05 +0000261
262#elif defined(__sun) || defined(__sun__)
263#define HAVE_SOLARIS_NETWORK
Simon Kelley7622fc02009-06-04 20:32:05 +0100264#define HAVE_GETOPT_LONG
Simon Kelley824af852008-02-12 20:43:05 +0000265#undef HAVE_ARC4RANDOM
Simon Kelley824af852008-02-12 20:43:05 +0000266#undef HAVE_SOCKADDR_SA_LEN
Simon Kelley7622fc02009-06-04 20:32:05 +0100267#define ETHER_ADDR_LEN 6
268
Simon Kelley824af852008-02-12 20:43:05 +0000269#endif
270
Simon Kelleye17fb622006-01-14 20:33:46 +0000271/* Decide if we're going to support IPv6 */
272/* We assume that systems which don't have IPv6
273 headers don't have ntop and pton either */
274
Simon Kelleyc72daea2012-01-05 21:33:27 +0000275#if defined(INET6_ADDRSTRLEN) && defined(IPV6_V6ONLY)
Simon Kelleye17fb622006-01-14 20:33:46 +0000276# define HAVE_IPV6
277# define ADDRSTRLEN INET6_ADDRSTRLEN
Simon Kelleye17fb622006-01-14 20:33:46 +0000278#elif defined(INET_ADDRSTRLEN)
279# undef HAVE_IPV6
280# define ADDRSTRLEN INET_ADDRSTRLEN
281#else
282# undef HAVE_IPV6
283# define ADDRSTRLEN 16 /* 4*3 + 3 dots + NULL */
284#endif
285
Simon Kelleyc72daea2012-01-05 21:33:27 +0000286
287/* rules to implement compile-time option dependencies and
288 the NO_XXX flags */
289
290#ifdef NO_IPV6
291#undef HAVE_IPV6
Simon Kelley1f15b812009-10-13 17:49:32 +0100292#endif
293
Simon Kelleyc72daea2012-01-05 21:33:27 +0000294#ifdef NO_TFTP
295#undef HAVE_TFTP
296#endif
297
298#ifdef NO_DHCP
299#undef HAVE_DHCP
300#undef HAVE_DHCP6
301#endif
302
303#if defined(NO_DHCP6) || !defined(HAVE_IPV6)
304#undef HAVE_DHCP6
305#endif
306
307/* DHCP6 needs DHCP too */
308#ifdef HAVE_DHCP6
309#define HAVE_DHCP
310#endif
311
312#if defined(NO_SCRIPT) || !defined(HAVE_DHCP) || defined(NO_FORK)
313#undef HAVE_SCRIPT
314#undef HAVE_LUASCRIPT
315#endif
316
317/* Must HAVE_SCRIPT to HAVE_LUASCRIPT */
318#ifdef HAVE_LUASCRIPT
319#define HAVE_SCRIPT
320#endif
321
Simon Kelley4820dce2012-12-18 18:30:30 +0000322#ifdef NO_AUTH
323#undef HAVE_AUTH
324#endif
Simon Kelleyc72daea2012-01-05 21:33:27 +0000325
326/* Define a string indicating which options are in use.
327 DNSMASQP_COMPILE_OPTS is only defined in dnsmasq.c */
328
329#ifdef DNSMASQ_COMPILE_OPTS
330
331static char *compile_opts =
332#ifndef HAVE_IPV6
333"no-"
334#endif
335"IPv6 "
336#ifndef HAVE_GETOPT_LONG
337"no-"
338#endif
339"GNU-getopt "
340#ifdef HAVE_BROKEN_RTC
341"no-RTC "
342#endif
343#ifdef NO_FORK
344"no-MMU "
345#endif
346#ifndef HAVE_DBUS
347"no-"
348#endif
349"DBus "
350#ifndef LOCALEDIR
351"no-"
352#endif
353"i18n "
354#if !defined(LOCALEDIR) && !defined(HAVE_IDN)
355"no-"
356#endif
357"IDN "
358#ifndef HAVE_DHCP
359"no-"
360#endif
361"DHCP "
362#if defined(HAVE_DHCP)
363# if !defined (HAVE_DHCP6)
364 "no-"
365# endif
366 "DHCPv6 "
367# if !defined(HAVE_SCRIPT)
368 "no-scripts "
369# else
370# if !defined(HAVE_LUASCRIPT)
371 "no-"
372# endif
373 "Lua "
374# endif
375#endif
376#ifndef HAVE_TFTP
377"no-"
378#endif
379"TFTP "
380#ifndef HAVE_CONNTRACK
381"no-"
382#endif
Simon Kelley4820dce2012-12-18 18:30:30 +0000383"conntrack "
384#ifndef HAVE_AUTH
385"no-"
386#endif
387 "auth";
Simon Kelleyc72daea2012-01-05 21:33:27 +0000388
389#endif
390
391
392