1 /* dnsmasq is Copyright (c) 2000-2009 Simon Kelley
2 
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.
7 
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.
12 
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/>.
15 */
16 
17 #define VERSION "2.51"
18 
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 1280       /* default max EDNS.0 UDP packet from RFC2671 */
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 10       /* or 10 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 150         /* 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 #ifdef __uClinux__
37 #define RESOLVFILE "/etc/config/resolv.conf"
38 #else
39 #define RESOLVFILE "/etc/resolv.conf"
40 #endif
41 #define RUNFILE "/var/run/dnsmasq.pid"
42 
43 #ifndef LEASEFILE
44 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__NetBSD__)
45 #define LEASEFILE "/var/db/dnsmasq.leases"
46 #elif defined(__sun__) || defined(__sun)
47 #define LEASEFILE "/var/cache/dnsmasq.leases"
48 #elif defined(__ANDROID__)
49 #define LEASEFILE "/data/misc/dhcp/dnsmasq.leases"
50 #else
51 #define LEASEFILE "/var/lib/misc/dnsmasq.leases"
52 #endif
53 #endif
54 
55 #ifndef CONFFILE
56 #if defined(__FreeBSD__)
57 #define CONFFILE "/usr/local/etc/dnsmasq.conf"
58 #else
59 #define CONFFILE "/etc/dnsmasq.conf"
60 #endif
61 #endif
62 
63 #define DEFLEASE 3600 /* default lease time, 1 hour */
64 #define CHUSER "nobody"
65 #define CHGRP "dip"
66 #define DHCP_SERVER_PORT 67
67 #define DHCP_CLIENT_PORT 68
68 #define DHCP_SERVER_ALTPORT 1067
69 #define DHCP_CLIENT_ALTPORT 1068
70 #define LOG_MAX 5 /* log-queue length */
71 #define RANDFILE "/dev/urandom"
72 #define DAD_WAIT 20 /* retry binding IPv6 sockets for this long */
73 
74 /* A small collection of RR-types which are missing on some platforms */
75 
76 #ifndef T_SIG
77 #define T_SIG 24
78 #endif
79 
80 #ifndef T_SRV
81 #define T_SRV 33
82 #endif
83 
84 #ifndef T_OPT
85 #define T_OPT 41
86 #endif
87 
88 #ifndef T_TKEY
89 #define T_TKEY 249
90 #endif
91 
92 #ifndef T_TSIG
93 #define T_TSIG 250
94 #endif
95 
96 /* Follows system specific switches. If you run on a
97    new system, you may want to edit these.
98    May replace this with Autoconf one day.
99 
100 HAVE_LINUX_NETWORK
101 HAVE_BSD_NETWORK
102 HAVE_SOLARIS_NETWORK
103    define exactly one of these to alter interaction with kernel networking.
104 
105 HAVE_BROKEN_RTC
106    define this on embedded systems which don't have an RTC
107    which keeps time over reboots. Causes dnsmasq to use uptime
108    for timing, and keep lease lengths rather than expiry times
109    in its leases file. This also make dnsmasq "flash disk friendly".
110    Normally, dnsmasq tries very hard to keep the on-disk leases file
111    up-to-date: rewriting it after every renewal.  When HAVE_BROKEN_RTC
112    is in effect, the lease file is only written when a new lease is
113    created, or an old one destroyed. (Because those are the only times
114    it changes.) This vastly reduces the number of file writes, and makes
115    it viable to keep the lease file on a flash filesystem.
116    NOTE: when enabling or disabling this, be sure to delete any old
117    leases file, otherwise dnsmasq may get very confused.
118 
119 HAVE_DHCP
120    define this to get dnsmasq's DHCP server.
121 
122 HAVE_SCRIPT
123    define this to get the ability to call scripts on lease-change
124 
125 HAVE_GETOPT_LONG
126    define this if you have GNU libc or GNU getopt.
127 
128 HAVE_ARC4RANDOM
129    define this if you have arc4random() to get better security from DNS spoofs
130    by using really random ids (OpenBSD)
131 
132 HAVE_SOCKADDR_SA_LEN
133    define this if struct sockaddr has sa_len field (*BSD)
134 
135 NOTES:
136    For Linux you should define
137       HAVE_LINUX_NETWORK
138       HAVE_GETOPT_LONG
139   you should NOT define
140       HAVE_ARC4RANDOM
141       HAVE_SOCKADDR_SA_LEN
142 
143    For *BSD systems you should define
144      HAVE_BSD_NETWORK
145      HAVE_SOCKADDR_SA_LEN
146    and you MAY define
147      HAVE_ARC4RANDOM - OpenBSD and FreeBSD and NetBSD version 2.0 or later
148      HAVE_GETOPT_LONG - NetBSD, later FreeBSD
149                        (FreeBSD and OpenBSD only if you link GNU getopt)
150 
151 */
152 
153 /* platform independent options- uncomment to enable */
154 #define HAVE_DHCP
155 #define HAVE_SCRIPT
156 /* #define HAVE_BROKEN_RTC */
157 
158 /* Allow DHCP to be disabled with COPTS=-DNO_DHCP */
159 #ifdef NO_DHCP
160 #undef HAVE_DHCP
161 #endif
162 
163 /* Allow scripts to be disabled with COPTS=-DNO_SCRIPT */
164 #ifdef NO_SCRIPT
165 #undef HAVE_SCRIPT
166 #endif
167 
168 /* platform dependent options. */
169 
170 /* Must preceed __linux__ since uClinux defines __linux__ too. */
171 #if defined(__uClinux__)
172 #define HAVE_LINUX_NETWORK
173 #define HAVE_GETOPT_LONG
174 #undef HAVE_ARC4RANDOM
175 #undef HAVE_SOCKADDR_SA_LEN
176 /* Never use fork() on uClinux. Note that this is subtly different from the
177    --keep-in-foreground option, since it also  suppresses forking new
178    processes for TCP connections and disables the call-a-script on leasechange
179    system. It's intended for use on MMU-less kernels. */
180 #define NO_FORK
181 
182 #elif defined(__UCLIBC__)
183 #define HAVE_LINUX_NETWORK
184 #if defined(__UCLIBC_HAS_GNU_GETOPT__) || \
185     ((__UCLIBC_MAJOR__ == 0) && (__UCLIBC_MINOR__ == 9) && (__UCLIBC_SUBLEVEL__ < 21))
186 #define HAVE_GETOPT_LONG
187 #endif
188 #undef HAVE_ARC4RANDOM
189 #undef HAVE_SOCKADDR_SA_LEN
190 #if !defined(__ARCH_HAS_MMU__) && !defined(__UCLIBC_HAS_MMU__)
191 #define NO_FORK
192 #endif
193 #if defined(__UCLIBC_HAS_IPV6__)
194 #ifndef IPV6_V6ONLY
195 #define IPV6_V6ONLY 26
196 #endif
197 #endif
198 
199 /* This is for glibc 2.x */
200 #elif defined(__linux__)
201 #define HAVE_LINUX_NETWORK
202 #define HAVE_GETOPT_LONG
203 #undef HAVE_ARC4RANDOM
204 #undef HAVE_SOCKADDR_SA_LEN
205 
206 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || \
207     defined(__FreeBSD_kernel__)
208 #define HAVE_BSD_NETWORK
209 /* Later verions of FreeBSD have getopt_long() */
210 #if defined(optional_argument) && defined(required_argument)
211 #define HAVE_GETOPT_LONG
212 #endif
213 #if !defined(__FreeBSD_kernel__)
214 #define HAVE_ARC4RANDOM
215 #endif
216 #define HAVE_SOCKADDR_SA_LEN
217 
218 #elif defined(__APPLE__)
219 #define HAVE_BSD_NETWORK
220 #undef HAVE_GETOPT_LONG
221 #define HAVE_ARC4RANDOM
222 #define HAVE_SOCKADDR_SA_LEN
223 /* Define before sys/socket.h is included so we get socklen_t */
224 #define _BSD_SOCKLEN_T_
225 
226 #elif defined(__NetBSD__)
227 #define HAVE_BSD_NETWORK
228 #define HAVE_GETOPT_LONG
229 #undef HAVE_ARC4RANDOM
230 #define HAVE_SOCKADDR_SA_LEN
231 
232 #elif defined(__sun) || defined(__sun__)
233 #define HAVE_SOLARIS_NETWORK
234 #define HAVE_GETOPT_LONG
235 #undef HAVE_ARC4RANDOM
236 #undef HAVE_SOCKADDR_SA_LEN
237 #define _XPG4_2
238 #define __EXTENSIONS__
239 #define ETHER_ADDR_LEN 6
240 
241 #endif
242 
243 /* Decide if we're going to support IPv6 */
244 /* IPv6 can be forced off with "make COPTS=-DNO_IPV6" */
245 /* We assume that systems which don't have IPv6
246    headers don't have ntop and pton either */
247 
248 #if defined(INET6_ADDRSTRLEN) && defined(IPV6_V6ONLY) && !defined(NO_IPV6)
249 #define HAVE_IPV6
250 #define ADDRSTRLEN INET6_ADDRSTRLEN
251 #if defined(SOL_IPV6)
252 #define IPV6_LEVEL SOL_IPV6
253 #else
254 #define IPV6_LEVEL IPPROTO_IPV6
255 #endif
256 #elif defined(INET_ADDRSTRLEN)
257 #undef HAVE_IPV6
258 #define ADDRSTRLEN INET_ADDRSTRLEN
259 #else
260 #undef HAVE_IPV6
261 #define ADDRSTRLEN 16 /* 4*3 + 3 dots + NULL */
262 #endif
263 
264 /* Can't do scripts without fork */
265 #ifdef NOFORK
266 #undef HAVE_SCRIPT
267 #endif
268