1 /* dnsmasq is Copyright (c) 2000-2013 Simon Kelley
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
5 the Free Software Foundation; version 2 dated June, 1991, or
6 (at your option) version 3 dated 29 June, 2007.
8 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.
13 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/>.
17 #define FTABSIZ 150 /* max number of outstanding requests (default) */
18 #define MAX_PROCS 20 /* max no children for TCP requests */
19 #define CHILD_LIFETIME 150 /* secs 'till terminated (RFC1035 suggests > 120s) */
20 #define EDNS_PKTSZ 4096 /* default max EDNS.0 UDP packet from RFC5625 */
21 #define KEYBLOCK_LEN 140 /* choose to mininise fragmentation when storing DNSSEC keys */
22 #define TIMEOUT 10 /* drop UDP queries after TIMEOUT seconds */
23 #define FORWARD_TEST 50 /* try all servers every 50 queries */
24 #define FORWARD_TIME 20 /* or 20 seconds */
25 #define RANDOM_SOCKS 64 /* max simultaneous random ports */
26 #define LEASE_RETRY 60 /* on error, retry writing leasefile after LEASE_RETRY seconds */
27 #define CACHESIZ 150 /* default cache size */
28 #define MAXLEASES 1000 /* maximum number of DHCP leases */
29 #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. */
31 #define DECLINE_BACKOFF 600 /* disable DECLINEd static addresses for this long */
32 #define DHCP_PACKET_MAX 16384 /* hard limit on DHCP packet size */
33 #define SMALLDNAME 40 /* most domain names are smaller than this */
34 #define HOSTSFILE "/etc/hosts"
35 #define ETHERSFILE "/etc/ethers"
36 #define DEFLEASE 3600 /* default lease time, 1 hour */
37 #define CHUSER "nobody"
39 #define TFTP_MAX_CONNECTIONS 50 /* max simultaneous connections */
40 #define LOG_MAX 5 /* log-queue length */
41 #define RANDFILE "/dev/urandom"
42 #define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* Default - may be overridden by config */
43 #define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
44 #define AUTH_TTL 600 /* default TTL for auth DNS */
45 #define SOA_REFRESH 1200 /* SOA refresh default */
46 #define SOA_RETRY 180 /* SOA retry default */
47 #define SOA_EXPIRY 1209600 /* SOA expiry default */
49 /* compile-time options: uncomment below to enable or do eg.
50 make COPTS=-DHAVE_BROKEN_RTC
53 define this on embedded systems which don't have an RTC
54 which keeps time over reboots. Causes dnsmasq to use uptime
55 for timing, and keep lease lengths rather than expiry times
56 in its leases file. This also make dnsmasq "flash disk friendly".
57 Normally, dnsmasq tries very hard to keep the on-disk leases file
58 up-to-date: rewriting it after every renewal. When HAVE_BROKEN_RTC
59 is in effect, the lease file is only written when a new lease is
60 created, or an old one destroyed. (Because those are the only times
61 it changes.) This vastly reduces the number of file writes, and makes
62 it viable to keep the lease file on a flash filesystem.
63 NOTE: when enabling or disabling this, be sure to delete any old
64 leases file, otherwise dnsmasq may get very confused.
71 define this to get dnsmasq's built-in TFTP server.
74 define this to get dnsmasq's DHCPv4 server.
77 define this to get dnsmasq's DHCPv6 server. (implies HAVE_DHCP).
80 define this to get the ability to call scripts on lease-change.
83 define this to get the ability to call Lua script on lease-change. (implies HAVE_SCRIPT)
86 define this if you want to link against libdbus, and have dnsmasq
87 support some methods to allow (re)configuration of the upstream DNS
91 define this if you want international domain name support.
92 NOTE: for backwards compatibility, IDN support is automatically
93 included when internationalisation support is built, using the
94 *-i18n makefile targets, even if HAVE_IDN is not explicitly set.
97 define this to include code which propogates conntrack marks from
98 incoming DNS queries to the corresponding upstream queries. This adds
99 a build-dependency on libnetfilter_conntrack, but the resulting binary will
100 still run happily on a kernel without conntrack support.
103 define this to include the ability to selectively add resolved ip addresses
107 define this to include the facility to act as an authoritative DNS
108 server for one or more zones.
118 these are avilable to explictly disable compile time options which would
119 otherwise be enabled automatically (HAVE_IPV6, >2Gb file sizes) or
120 which are enabled by default in the distributed source tree. Building dnsmasq
121 with something like "make COPTS=-DNO_SCRIPT" will do the trick.
126 the default locations of these files are determined below, but may be overridden
127 in a build command line using COPTS.
132 /* The default set of options to build. Built with these options, dnsmasq
133 has no library dependencies other than libc */
141 /* #define HAVE_LUASCRIPT */
142 /* #define HAVE_BROKEN_RTC */
143 /* #define HAVE_DBUS */
144 /* #define HAVE_IDN */
145 /* #define HAVE_CONNTRACK */
148 /* Default locations for important system files. */
151 # if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
152 # define LEASEFILE "/var/db/dnsmasq.leases"
153 # elif defined(__sun__) || defined (__sun)
154 # define LEASEFILE "/var/cache/dnsmasq.leases"
155 # elif defined(__ANDROID__)
156 # define LEASEFILE "/data/misc/dhcp/dnsmasq.leases"
158 # define LEASEFILE "/var/lib/misc/dnsmasq.leases"
163 # if defined(__FreeBSD__)
164 # define CONFFILE "/usr/local/etc/dnsmasq.conf"
166 # define CONFFILE "/etc/dnsmasq.conf"
171 # if defined(__uClinux__)
172 # define RESOLVFILE "/etc/config/resolv.conf"
174 # define RESOLVFILE "/etc/resolv.conf"
179 # if defined(__ANDROID__)
180 # define RUNFILE "/data/dnsmasq.pid"
182 # define RUNFILE "/var/run/dnsmasq.pid"
186 /* platform dependent options: these are determined automatically below
191 define exactly one of these to alter interaction with kernel networking.
194 defined when GNU-style getopt_long available.
197 defined if struct sockaddr has sa_len field (*BSD)
200 /* Must preceed __linux__ since uClinux defines __linux__ too. */
201 #if defined(__uClinux__)
202 #define HAVE_LINUX_NETWORK
203 #define HAVE_GETOPT_LONG
204 #undef HAVE_SOCKADDR_SA_LEN
205 /* Never use fork() on uClinux. Note that this is subtly different from the
206 --keep-in-foreground option, since it also suppresses forking new
207 processes for TCP connections and disables the call-a-script on leasechange
208 system. It's intended for use on MMU-less kernels. */
211 #elif defined(__UCLIBC__)
212 #define HAVE_LINUX_NETWORK
213 #if defined(__UCLIBC_HAS_GNU_GETOPT__) || \
214 ((__UCLIBC_MAJOR__==0) && (__UCLIBC_MINOR__==9) && (__UCLIBC_SUBLEVEL__<21))
215 # define HAVE_GETOPT_LONG
217 #undef HAVE_SOCKADDR_SA_LEN
218 #if !defined(__ARCH_HAS_MMU__) && !defined(__UCLIBC_HAS_MMU__)
221 #if defined(__UCLIBC_HAS_IPV6__)
223 # define IPV6_V6ONLY 26
227 /* This is for glibc 2.x */
228 #elif defined(__linux__)
229 #define HAVE_LINUX_NETWORK
230 #define HAVE_GETOPT_LONG
231 #undef HAVE_SOCKADDR_SA_LEN
233 #elif defined(__FreeBSD__) || \
234 defined(__OpenBSD__) || \
235 defined(__DragonFly__) || \
236 defined(__FreeBSD_kernel__)
237 #define HAVE_BSD_NETWORK
238 /* Later verions of FreeBSD have getopt_long() */
239 #if defined(optional_argument) && defined(required_argument)
240 # define HAVE_GETOPT_LONG
242 #define HAVE_SOCKADDR_SA_LEN
244 #elif defined(__APPLE__)
245 #define HAVE_BSD_NETWORK
246 #define HAVE_GETOPT_LONG
247 #define HAVE_SOCKADDR_SA_LEN
248 /* Define before sys/socket.h is included so we get socklen_t */
249 #define _BSD_SOCKLEN_T_
250 /* Select the RFC_3542 version of the IPv6 socket API.
251 Define before netinet6/in6.h is included. */
252 #define __APPLE_USE_RFC_3542
254 #elif defined(__NetBSD__)
255 #define HAVE_BSD_NETWORK
256 #define HAVE_GETOPT_LONG
257 #define HAVE_SOCKADDR_SA_LEN
259 #elif defined(__sun) || defined(__sun__)
260 #define HAVE_SOLARIS_NETWORK
261 #define HAVE_GETOPT_LONG
262 #undef HAVE_SOCKADDR_SA_LEN
263 #define ETHER_ADDR_LEN 6
267 /* Decide if we're going to support IPv6 */
268 /* We assume that systems which don't have IPv6
269 headers don't have ntop and pton either */
271 #if defined(INET6_ADDRSTRLEN) && defined(IPV6_V6ONLY)
273 # define ADDRSTRLEN INET6_ADDRSTRLEN
275 # if !defined(INET_ADDRSTRLEN)
276 # define INET_ADDRSTRLEN 16 /* 4*3 + 3 dots + NULL */
279 # define ADDRSTRLEN INET_ADDRSTRLEN
283 /* rules to implement compile-time option dependencies and
299 #if defined(NO_DHCP6) || !defined(HAVE_IPV6)
303 /* DHCP6 needs DHCP too */
308 #if defined(NO_SCRIPT) || !defined(HAVE_DHCP) || defined(NO_FORK)
310 #undef HAVE_LUASCRIPT
313 /* Must HAVE_SCRIPT to HAVE_LUASCRIPT */
314 #ifdef HAVE_LUASCRIPT
322 #if defined(NO_IPSET) || !defined(HAVE_LINUX_NETWORK)
327 #define HAVE_LEASEFILE_EXPIRE
330 /* Define a string indicating which options are in use.
331 DNSMASQP_COMPILE_OPTS is only defined in dnsmasq.c */
333 #ifdef DNSMASQ_COMPILE_OPTS
335 static char *compile_opts
=
340 #ifndef HAVE_GETOPT_LONG
344 #ifdef HAVE_BROKEN_RTC
358 #if !defined(LOCALEDIR) && !defined(HAVE_IDN)
366 #if defined(HAVE_DHCP)
367 # if !defined (HAVE_DHCP6)
371 # if !defined(HAVE_SCRIPT)
374 # if !defined(HAVE_LUASCRIPT)
384 #ifndef HAVE_CONNTRACK