• 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 #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 
97 /* Follows system specific switches. If you run on a
98    new system, you may want to edit these.
99    May replace this with Autoconf one day.
100 
101 HAVE_LINUX_NETWORK
102 HAVE_BSD_NETWORK
103 HAVE_SOLARIS_NETWORK
104    define exactly one of these to alter interaction with kernel networking.
105 
106 HAVE_BROKEN_RTC
107    define this on embedded systems which don't have an RTC
108    which keeps time over reboots. Causes dnsmasq to use uptime
109    for timing, and keep lease lengths rather than expiry times
110    in its leases file. This also make dnsmasq "flash disk friendly".
111    Normally, dnsmasq tries very hard to keep the on-disk leases file
112    up-to-date: rewriting it after every renewal.  When HAVE_BROKEN_RTC
113    is in effect, the lease file is only written when a new lease is
114    created, or an old one destroyed. (Because those are the only times
115    it changes.) This vastly reduces the number of file writes, and makes
116    it viable to keep the lease file on a flash filesystem.
117    NOTE: when enabling or disabling this, be sure to delete any old
118    leases file, otherwise dnsmasq may get very confused.
119 
120 HAVE_DHCP
121    define this to get dnsmasq's DHCP server.
122 
123 HAVE_SCRIPT
124    define this to get the ability to call scripts on lease-change
125 
126 HAVE_GETOPT_LONG
127    define this if you have GNU libc or GNU getopt.
128 
129 HAVE_ARC4RANDOM
130    define this if you have arc4random() to get better security from DNS spoofs
131    by using really random ids (OpenBSD)
132 
133 HAVE_SOCKADDR_SA_LEN
134    define this if struct sockaddr has sa_len field (*BSD)
135 
136 NOTES:
137    For Linux you should define
138       HAVE_LINUX_NETWORK
139       HAVE_GETOPT_LONG
140   you should NOT define
141       HAVE_ARC4RANDOM
142       HAVE_SOCKADDR_SA_LEN
143 
144    For *BSD systems you should define
145      HAVE_BSD_NETWORK
146      HAVE_SOCKADDR_SA_LEN
147    and you MAY define
148      HAVE_ARC4RANDOM - OpenBSD and FreeBSD and NetBSD version 2.0 or later
149      HAVE_GETOPT_LONG - NetBSD, later FreeBSD
150                        (FreeBSD and OpenBSD only if you link GNU getopt)
151 
152 */
153 
154 /* platform independent options- uncomment to enable */
155 #define HAVE_DHCP
156 #define HAVE_SCRIPT
157 /* #define HAVE_BROKEN_RTC */
158 
159 /* Allow DHCP to be disabled with COPTS=-DNO_DHCP */
160 #ifdef NO_DHCP
161 #undef HAVE_DHCP
162 #endif
163 
164 /* Allow scripts to be disabled with COPTS=-DNO_SCRIPT */
165 #ifdef NO_SCRIPT
166 #undef HAVE_SCRIPT
167 #endif
168 
169 
170 
171 /* platform dependent options. */
172 
173 /* Must preceed __linux__ since uClinux defines __linux__ too. */
174 #if defined(__uClinux__)
175 #define HAVE_LINUX_NETWORK
176 #define HAVE_GETOPT_LONG
177 #undef HAVE_ARC4RANDOM
178 #undef HAVE_SOCKADDR_SA_LEN
179 /* Never use fork() on uClinux. Note that this is subtly different from the
180    --keep-in-foreground option, since it also  suppresses forking new
181    processes for TCP connections and disables the call-a-script on leasechange
182    system. It's intended for use on MMU-less kernels. */
183 #define NO_FORK
184 
185 #elif defined(__UCLIBC__)
186 #define HAVE_LINUX_NETWORK
187 #if defined(__UCLIBC_HAS_GNU_GETOPT__) || \
188    ((__UCLIBC_MAJOR__==0) && (__UCLIBC_MINOR__==9) && (__UCLIBC_SUBLEVEL__<21))
189 #    define HAVE_GETOPT_LONG
190 #endif
191 #undef HAVE_ARC4RANDOM
192 #undef HAVE_SOCKADDR_SA_LEN
193 #if !defined(__ARCH_HAS_MMU__) && !defined(__UCLIBC_HAS_MMU__)
194 #  define NO_FORK
195 #endif
196 #if defined(__UCLIBC_HAS_IPV6__)
197 #  ifndef IPV6_V6ONLY
198 #    define IPV6_V6ONLY 26
199 #  endif
200 #endif
201 
202 /* This is for glibc 2.x */
203 #elif defined(__linux__)
204 #define HAVE_LINUX_NETWORK
205 #define HAVE_GETOPT_LONG
206 #undef HAVE_ARC4RANDOM
207 #undef HAVE_SOCKADDR_SA_LEN
208 
209 #elif defined(__FreeBSD__) || \
210       defined(__OpenBSD__) || \
211       defined(__DragonFly__) || \
212       defined (__FreeBSD_kernel__)
213 #define HAVE_BSD_NETWORK
214 /* Later verions of FreeBSD have getopt_long() */
215 #if defined(optional_argument) && defined(required_argument)
216 #   define HAVE_GETOPT_LONG
217 #endif
218 #if !defined (__FreeBSD_kernel__)
219 #   define HAVE_ARC4RANDOM
220 #endif
221 #define HAVE_SOCKADDR_SA_LEN
222 
223 #elif defined(__APPLE__)
224 #define HAVE_BSD_NETWORK
225 #undef HAVE_GETOPT_LONG
226 #define HAVE_ARC4RANDOM
227 #define HAVE_SOCKADDR_SA_LEN
228 /* Define before sys/socket.h is included so we get socklen_t */
229 #define _BSD_SOCKLEN_T_
230 
231 #elif defined(__NetBSD__)
232 #define HAVE_BSD_NETWORK
233 #define HAVE_GETOPT_LONG
234 #undef HAVE_ARC4RANDOM
235 #define HAVE_SOCKADDR_SA_LEN
236 
237 #elif defined(__sun) || defined(__sun__)
238 #define HAVE_SOLARIS_NETWORK
239 #define HAVE_GETOPT_LONG
240 #undef HAVE_ARC4RANDOM
241 #undef HAVE_SOCKADDR_SA_LEN
242 #define _XPG4_2
243 #define __EXTENSIONS__
244 #define ETHER_ADDR_LEN 6
245 
246 #endif
247 
248 /* Decide if we're going to support IPv6 */
249 /* IPv6 can be forced off with "make COPTS=-DNO_IPV6" */
250 /* We assume that systems which don't have IPv6
251    headers don't have ntop and pton either */
252 
253 #if defined(INET6_ADDRSTRLEN) && defined(IPV6_V6ONLY) && !defined(NO_IPV6)
254 #  define HAVE_IPV6
255 #  define ADDRSTRLEN INET6_ADDRSTRLEN
256 #  if defined(SOL_IPV6)
257 #    define IPV6_LEVEL SOL_IPV6
258 #  else
259 #    define IPV6_LEVEL IPPROTO_IPV6
260 #  endif
261 #elif defined(INET_ADDRSTRLEN)
262 #  undef HAVE_IPV6
263 #  define ADDRSTRLEN INET_ADDRSTRLEN
264 #else
265 #  undef HAVE_IPV6
266 #  define ADDRSTRLEN 16 /* 4*3 + 3 dots + NULL */
267 #endif
268 
269 /* Can't do scripts without fork */
270 #ifdef NOFORK
271 #  undef HAVE_SCRIPT
272 #endif
273 
274