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