1 /* dnsmasq is Copyright (c) 2000-2011 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.57"
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 EDNS_PKTSZ 4096 /* default max EDNS.0 UDP packet from RFC5625 */
23 #define TIMEOUT 10 /* drop UDP queries after TIMEOUT seconds */
24 #define FORWARD_TEST 50 /* try all servers every 50 queries */
25 #define FORWARD_TIME 20 /* or 20 seconds */
26 #define RANDOM_SOCKS 64 /* max simultaneous random ports */
27 #define LEASE_RETRY 60 /* on error, retry writing leasefile after LEASE_RETRY seconds */
28 #define CACHESIZ 150 /* default cache size */
29 #define MAXLEASES 1000 /* maximum number of DHCP leases */
30 #define PING_WAIT 3 /* wait for ping address-in-use test */
31 #define PING_CACHE_TIME 30 /* Ping test assumed to be valid this long. */
32 #define DECLINE_BACKOFF 600 /* disable DECLINEd static addresses for this long */
33 #define DHCP_PACKET_MAX 16384 /* hard limit on DHCP packet size */
34 #define SMALLDNAME 40 /* most domain names are smaller than this */
35 #define HOSTSFILE "/etc/hosts"
36 #define ETHERSFILE "/etc/ethers"
38 # define RESOLVFILE "/etc/config/resolv.conf"
40 # define RESOLVFILE "/etc/resolv.conf"
42 #define RUNFILE "/var/run/dnsmasq.pid"
45 # if defined(__FreeBSD__) || defined (__OpenBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
46 # define LEASEFILE "/var/db/dnsmasq.leases"
47 # elif defined(__sun__) || defined (__sun)
48 # define LEASEFILE "/var/cache/dnsmasq.leases"
49 # elif defined(__ANDROID__)
50 # define LEASEFILE "/data/misc/dhcp/dnsmasq.leases"
52 # define LEASEFILE "/var/lib/misc/dnsmasq.leases"
57 # if defined(__FreeBSD__)
58 # define CONFFILE "/usr/local/etc/dnsmasq.conf"
60 # define CONFFILE "/etc/dnsmasq.conf"
64 #define DEFLEASE 3600 /* default lease time, 1 hour */
65 #define CHUSER "nobody"
67 #define NAMESERVER_PORT 53
68 #define DHCP_SERVER_PORT 67
69 #define DHCP_CLIENT_PORT 68
70 #define DHCP_SERVER_ALTPORT 1067
71 #define DHCP_CLIENT_ALTPORT 1068
74 #define TFTP_MAX_CONNECTIONS 50 /* max simultaneous connections */
75 #define LOG_MAX 5 /* log-queue length */
76 #define RANDFILE "/dev/urandom"
77 #define DAD_WAIT 20 /* retry binding IPv6 sockets for this long */
78 #define EDNS0_OPTION_MAC 5 /* dyndns.org temporary assignment */
80 /* DBUS interface specifics */
81 #define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq"
82 #define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
84 /* Follows system specific switches. If you run on a
85 new system, you may want to edit these.
86 May replace this with Autoconf one day.
91 define exactly one of these to alter interaction with kernel networking.
94 define this on embedded systems which don't have an RTC
95 which keeps time over reboots. Causes dnsmasq to use uptime
96 for timing, and keep lease lengths rather than expiry times
97 in its leases file. This also make dnsmasq "flash disk friendly".
98 Normally, dnsmasq tries very hard to keep the on-disk leases file
99 up-to-date: rewriting it after every renewal. When HAVE_BROKEN_RTC
100 is in effect, the lease file is only written when a new lease is
101 created, or an old one destroyed. (Because those are the only times
102 it changes.) This vastly reduces the number of file writes, and makes
103 it viable to keep the lease file on a flash filesystem.
104 NOTE: when enabling or disabling this, be sure to delete any old
105 leases file, otherwise dnsmasq may get very confused.
108 define this to get dnsmasq's built-in TFTP server.
111 define this to get dnsmasq's DHCP server.
114 define this to get the ability to call scripts on lease-change
117 define this if you have GNU libc or GNU getopt.
120 define this if you have arc4random() to get better security from DNS spoofs
121 by using really random ids (OpenBSD)
124 define this if struct sockaddr has sa_len field (*BSD)
127 define this if you want to link against libdbus, and have dnsmasq
128 support some methods to allow (re)configuration of the upstream DNS
132 define this if you want international domain name support.
133 NOTE: for backwards compatibility, IDN support is automatically
134 included when internationalisation support is built, using the
135 *-i18n makefile targets, even if HAVE_IDN is not explicitly set.
138 For Linux you should define
141 you should NOT define
145 For *BSD systems you should define
149 HAVE_ARC4RANDOM - OpenBSD and FreeBSD and NetBSD version 2.0 or later
150 HAVE_GETOPT_LONG - NetBSD, later FreeBSD
151 (FreeBSD and OpenBSD only if you link GNU getopt)
155 /* platform independent options- uncomment to enable */
159 /* #define HAVE_BROKEN_RTC */
161 /* #define HAVE_IDN */
163 /* Allow TFTP to be disabled with COPTS=-DNO_TFTP */
168 /* Allow DHCP to be disabled with COPTS=-DNO_DHCP */
173 /* Allow scripts to be disabled with COPTS=-DNO_SCRIPT */
180 /* platform dependent options. */
182 /* Must preceed __linux__ since uClinux defines __linux__ too. */
183 #if defined(__uClinux__)
184 #define HAVE_LINUX_NETWORK
185 #define HAVE_GETOPT_LONG
186 #undef HAVE_ARC4RANDOM
187 #undef HAVE_SOCKADDR_SA_LEN
188 /* Never use fork() on uClinux. Note that this is subtly different from the
189 --keep-in-foreground option, since it also suppresses forking new
190 processes for TCP connections and disables the call-a-script on leasechange
191 system. It's intended for use on MMU-less kernels. */
194 #elif defined(__UCLIBC__)
195 #define HAVE_LINUX_NETWORK
196 #if defined(__UCLIBC_HAS_GNU_GETOPT__) || \
197 ((__UCLIBC_MAJOR__==0) && (__UCLIBC_MINOR__==9) && (__UCLIBC_SUBLEVEL__<21))
198 # define HAVE_GETOPT_LONG
200 #undef HAVE_ARC4RANDOM
201 #undef HAVE_SOCKADDR_SA_LEN
202 #if !defined(__ARCH_HAS_MMU__) && !defined(__UCLIBC_HAS_MMU__)
205 #if defined(__UCLIBC_HAS_IPV6__)
207 # define IPV6_V6ONLY 26
211 /* This is for glibc 2.x */
212 #elif defined(__linux__)
213 #define HAVE_LINUX_NETWORK
214 #define HAVE_GETOPT_LONG
215 #undef HAVE_ARC4RANDOM
216 #undef HAVE_SOCKADDR_SA_LEN
218 #elif defined(__FreeBSD__) || \
219 defined(__OpenBSD__) || \
220 defined(__DragonFly__) || \
221 defined(__FreeBSD_kernel__)
222 #define HAVE_BSD_NETWORK
223 /* Later verions of FreeBSD have getopt_long() */
224 #if defined(optional_argument) && defined(required_argument)
225 # define HAVE_GETOPT_LONG
227 #if !defined(__FreeBSD_kernel__)
228 # define HAVE_ARC4RANDOM
230 #define HAVE_SOCKADDR_SA_LEN
232 #elif defined(__APPLE__)
233 #define HAVE_BSD_NETWORK
234 #define HAVE_GETOPT_LONG
235 #define HAVE_ARC4RANDOM
236 #define HAVE_SOCKADDR_SA_LEN
237 /* Define before sys/socket.h is included so we get socklen_t */
238 #define _BSD_SOCKLEN_T_
240 #elif defined(__NetBSD__)
241 #define HAVE_BSD_NETWORK
242 #define HAVE_GETOPT_LONG
243 #undef HAVE_ARC4RANDOM
244 #define HAVE_SOCKADDR_SA_LEN
246 #elif defined(__sun) || defined(__sun__)
247 #define HAVE_SOLARIS_NETWORK
248 #define HAVE_GETOPT_LONG
249 #undef HAVE_ARC4RANDOM
250 #undef HAVE_SOCKADDR_SA_LEN
251 #define ETHER_ADDR_LEN 6
255 /* Decide if we're going to support IPv6 */
256 /* IPv6 can be forced off with "make COPTS=-DNO_IPV6" */
257 /* We assume that systems which don't have IPv6
258 headers don't have ntop and pton either */
260 #if defined(INET6_ADDRSTRLEN) && defined(IPV6_V6ONLY) && !defined(NO_IPV6)
262 # define ADDRSTRLEN INET6_ADDRSTRLEN
263 # if defined(SOL_IPV6)
264 # define IPV6_LEVEL SOL_IPV6
266 # define IPV6_LEVEL IPPROTO_IPV6
268 #elif defined(INET_ADDRSTRLEN)
270 # define ADDRSTRLEN INET_ADDRSTRLEN
273 # define ADDRSTRLEN 16 /* 4*3 + 3 dots + NULL */
276 /* Can't do scripts without fork */