1 /* dnsmasq is Copyright (c) 2000-2015 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 VERSION "2.74"
19 #define FTABSIZ 150 /* max number of outstanding requests (default) */
20 #define MAX_PROCS 20 /* max no children for TCP requests */
21 #define CHILD_LIFETIME 150 /* secs 'till terminated (RFC1035 suggests > 120s) */
22 #define TCP_MAX_QUERIES 100 /* Maximum number of queries per incoming TCP connection */
23 #define EDNS_PKTSZ 4096 /* default max EDNS.0 UDP packet from RFC5625 */
24 #define SAFE_PKTSZ 1280 /* "go anywhere" UDP packet size */
25 #define KEYBLOCK_LEN 40 /* choose to mininise fragmentation when storing DNSSEC keys */
26 #define DNSSEC_WORK 50 /* Max number of queries to validate one question */
27 #define TIMEOUT 10 /* drop UDP queries after TIMEOUT seconds */
28 #define FORWARD_TEST 50 /* try all servers every 50 queries */
29 #define FORWARD_TIME 20 /* or 20 seconds */
30 #define RANDOM_SOCKS 64 /* max simultaneous random ports */
31 #define LEASE_RETRY 60 /* on error, retry writing leasefile after LEASE_RETRY seconds */
32 #define CACHESIZ 150 /* default cache size */
33 #define TTL_FLOOR_LIMIT 3600 /* don't allow --min-cache-ttl to raise TTL above this under any circumstances */
34 #define MAXLEASES 1000 /* maximum number of DHCP leases */
35 #define PING_WAIT 3 /* wait for ping address-in-use test */
36 #define PING_CACHE_TIME 30 /* Ping test assumed to be valid this long. */
37 #define DECLINE_BACKOFF 600 /* disable DECLINEd static addresses for this long */
38 #define DHCP_PACKET_MAX 16384 /* hard limit on DHCP packet size */
39 #define SMALLDNAME 50 /* most domain names are smaller than this */
40 #define CNAME_CHAIN 10 /* chains longer than this atr dropped for loop protection */
41 #define HOSTSFILE "/etc/hosts"
42 #define ETHERSFILE "/etc/ethers"
43 #define DEFLEASE 3600 /* default lease time, 1 hour */
44 #define CHUSER "nobody"
46 #define TFTP_MAX_CONNECTIONS 50 /* max simultaneous connections */
47 #define LOG_MAX 5 /* log-queue length */
48 #define RANDFILE "/dev/urandom"
49 #define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* Default - may be overridden by config */
50 #define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
51 #define AUTH_TTL 600 /* default TTL for auth DNS */
52 #define SOA_REFRESH 1200 /* SOA refresh default */
53 #define SOA_RETRY 180 /* SOA retry default */
54 #define SOA_EXPIRY 1209600 /* SOA expiry default */
55 #define LOOP_TEST_DOMAIN "test" /* domain for loop testing, "test" is reserved by RFC 2606 and won't therefore clash */
56 #define LOOP_TEST_TYPE T_TXT
58 /* compile-time options: uncomment below to enable or do eg.
59 make COPTS=-DHAVE_BROKEN_RTC
62 define this on embedded systems which don't have an RTC
63 which keeps time over reboots. Causes dnsmasq to use uptime
64 for timing, and keep lease lengths rather than expiry times
65 in its leases file. This also make dnsmasq "flash disk friendly".
66 Normally, dnsmasq tries very hard to keep the on-disk leases file
67 up-to-date: rewriting it after every renewal. When HAVE_BROKEN_RTC
68 is in effect, the lease file is only written when a new lease is
69 created, or an old one destroyed. (Because those are the only times
70 it changes.) This vastly reduces the number of file writes, and makes
71 it viable to keep the lease file on a flash filesystem.
72 NOTE: when enabling or disabling this, be sure to delete any old
73 leases file, otherwise dnsmasq may get very confused.
76 define this to get dnsmasq's built-in TFTP server.
79 define this to get dnsmasq's DHCPv4 server.
82 define this to get dnsmasq's DHCPv6 server. (implies HAVE_DHCP).
85 define this to get the ability to call scripts on lease-change.
88 define this to get the ability to call Lua script on lease-change. (implies HAVE_SCRIPT)
91 define this if you want to link against libdbus, and have dnsmasq
92 support some methods to allow (re)configuration of the upstream DNS
96 define this if you want international domain name support.
97 NOTE: for backwards compatibility, IDN support is automatically
98 included when internationalisation support is built, using the
99 *-i18n makefile targets, even if HAVE_IDN is not explicitly set.
102 define this to include code which propogates conntrack marks from
103 incoming DNS queries to the corresponding upstream queries. This adds
104 a build-dependency on libnetfilter_conntrack, but the resulting binary will
105 still run happily on a kernel without conntrack support.
108 define this to include the ability to selectively add resolved ip addresses
112 define this to include the facility to act as an authoritative DNS
113 server for one or more zones.
116 include DNSSEC validator.
119 include functionality to probe for and remove DNS forwarding loops.
122 use the Linux inotify facility to efficiently re-read configuration files.
132 these are avilable to explictly disable compile time options which would
133 otherwise be enabled automatically (HAVE_IPV6, >2Gb file sizes) or
134 which are enabled by default in the distributed source tree. Building dnsmasq
135 with something like "make COPTS=-DNO_SCRIPT" will do the trick.
138 Don't include the ECDSA cypher in DNSSEC validation. Needed for older Nettle versions.
140 Don't use and link against libgmp, Useful if nettle is built with --enable-mini-gmp.
145 the default locations of these files are determined below, but may be overridden
146 in a build command line using COPTS.
150 /* Defining this builds a binary which handles time differently and works better on a system without a
151 stable RTC (it uses uptime, not epoch time) and writes the DHCP leases file less often to avoid flash wear.
154 /* #define HAVE_BROKEN_RTC */
156 /* The default set of options to build. Built with these options, dnsmasq
157 has no library dependencies other than libc */
167 /* Build options which require external libraries.
169 Defining HAVE_<opt>_STATIC as _well_ as HAVE_<opt> will link the library statically.
171 You can use "make COPTS=-DHAVE_<opt>" instead of editing these.
174 /* #define HAVE_LUASCRIPT */
176 /* #define HAVE_IDN */
177 /* #define HAVE_CONNTRACK */
178 /* #define HAVE_DNSSEC */
181 /* Default locations for important system files. */
184 # if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
185 # define LEASEFILE "/var/db/dnsmasq.leases"
186 # elif defined(__sun__) || defined (__sun)
187 # define LEASEFILE "/var/cache/dnsmasq.leases"
188 # elif defined(__ANDROID__)
189 # define LEASEFILE "/data/misc/dhcp/dnsmasq.leases"
191 # define LEASEFILE "/var/lib/misc/dnsmasq.leases"
196 # if defined(__FreeBSD__)
197 # define CONFFILE "/usr/local/etc/dnsmasq.conf"
199 # define CONFFILE "/etc/dnsmasq.conf"
204 # if defined(__uClinux__)
205 # define RESOLVFILE "/etc/config/resolv.conf"
207 # define RESOLVFILE "/etc/resolv.conf"
212 # if defined(__ANDROID__)
213 # define RUNFILE "/data/dnsmasq.pid"
215 # define RUNFILE "/var/run/dnsmasq.pid"
219 /* platform dependent options: these are determined automatically below
224 define exactly one of these to alter interaction with kernel networking.
227 defined when GNU-style getopt_long available.
230 defined if struct sockaddr has sa_len field (*BSD)
233 /* Must preceed __linux__ since uClinux defines __linux__ too. */
234 #if defined(__uClinux__)
235 #define HAVE_LINUX_NETWORK
236 #define HAVE_GETOPT_LONG
237 #undef HAVE_SOCKADDR_SA_LEN
238 /* Never use fork() on uClinux. Note that this is subtly different from the
239 --keep-in-foreground option, since it also suppresses forking new
240 processes for TCP connections and disables the call-a-script on leasechange
241 system. It's intended for use on MMU-less kernels. */
244 #elif defined(__UCLIBC__)
245 #define HAVE_LINUX_NETWORK
246 #if defined(__UCLIBC_HAS_GNU_GETOPT__) || \
247 ((__UCLIBC_MAJOR__==0) && (__UCLIBC_MINOR__==9) && (__UCLIBC_SUBLEVEL__<21))
248 # define HAVE_GETOPT_LONG
250 #undef HAVE_SOCKADDR_SA_LEN
251 #if !defined(__ARCH_HAS_MMU__) && !defined(__UCLIBC_HAS_MMU__)
254 #if defined(__UCLIBC_HAS_IPV6__)
256 # define IPV6_V6ONLY 26
260 /* This is for glibc 2.x */
261 #elif defined(__linux__)
262 #define HAVE_LINUX_NETWORK
263 #define HAVE_GETOPT_LONG
264 #undef HAVE_SOCKADDR_SA_LEN
266 #elif defined(__FreeBSD__) || \
267 defined(__OpenBSD__) || \
268 defined(__DragonFly__) || \
269 defined(__FreeBSD_kernel__)
270 #define HAVE_BSD_NETWORK
271 /* Later verions of FreeBSD have getopt_long() */
272 #if defined(optional_argument) && defined(required_argument)
273 # define HAVE_GETOPT_LONG
275 #define HAVE_SOCKADDR_SA_LEN
277 #elif defined(__APPLE__)
278 #define HAVE_BSD_NETWORK
279 #define HAVE_GETOPT_LONG
280 #define HAVE_SOCKADDR_SA_LEN
281 /* Define before sys/socket.h is included so we get socklen_t */
282 #define _BSD_SOCKLEN_T_
283 /* Select the RFC_3542 version of the IPv6 socket API.
284 Define before netinet6/in6.h is included. */
285 #define __APPLE_USE_RFC_3542
288 #elif defined(__NetBSD__)
289 #define HAVE_BSD_NETWORK
290 #define HAVE_GETOPT_LONG
291 #define HAVE_SOCKADDR_SA_LEN
293 #elif defined(__sun) || defined(__sun__)
294 #define HAVE_SOLARIS_NETWORK
295 #define HAVE_GETOPT_LONG
296 #undef HAVE_SOCKADDR_SA_LEN
297 #define ETHER_ADDR_LEN 6
301 /* Decide if we're going to support IPv6 */
302 /* We assume that systems which don't have IPv6
303 headers don't have ntop and pton either */
305 #if defined(INET6_ADDRSTRLEN) && defined(IPV6_V6ONLY)
307 # define ADDRSTRLEN INET6_ADDRSTRLEN
309 # if !defined(INET_ADDRSTRLEN)
310 # define INET_ADDRSTRLEN 16 /* 4*3 + 3 dots + NULL */
313 # define ADDRSTRLEN INET_ADDRSTRLEN
317 /* rules to implement compile-time option dependencies and
333 #if defined(NO_DHCP6) || !defined(HAVE_IPV6)
337 /* DHCP6 needs DHCP too */
342 #if defined(NO_SCRIPT) || !defined(HAVE_DHCP) || defined(NO_FORK)
344 #undef HAVE_LUASCRIPT
347 /* Must HAVE_SCRIPT to HAVE_LUASCRIPT */
348 #ifdef HAVE_LUASCRIPT
356 #if defined(NO_IPSET)
364 #if defined (HAVE_LINUX_NETWORK) && !defined(NO_INOTIFY)
368 /* Define a string indicating which options are in use.
369 DNSMASQP_COMPILE_OPTS is only defined in dnsmasq.c */
371 #ifdef DNSMASQ_COMPILE_OPTS
373 static char *compile_opts =
378 #ifndef HAVE_GETOPT_LONG
382 #ifdef HAVE_BROKEN_RTC
396 #if !defined(LOCALEDIR) && !defined(HAVE_IDN)
404 #if defined(HAVE_DHCP)
405 # if !defined (HAVE_DHCP6)
409 # if !defined(HAVE_SCRIPT)
412 # if !defined(HAVE_LUASCRIPT)
422 #ifndef HAVE_CONNTRACK