blob: 56bee838e9398f66f530acdc064528de8e2b41a8 [file] [log] [blame]
Simon Kelley9e4abcb2004-01-22 19:47:41 +00001/* dnsmasq is Copyright (c) 2000 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.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11*/
12
13/* Author's email: simon@thekelleys.org.uk */
14
Simon Kelley9c74ec02004-08-13 21:13:03 +010015#define VERSION "2.13"
Simon Kelley9e4abcb2004-01-22 19:47:41 +000016
17#define FTABSIZ 150 /* max number of outstanding requests */
Simon Kelleyfeba5c12004-07-27 20:28:58 +010018#define MAX_PROCS 20 /* max no children for TCP requests */
19#define CHILD_LIFETIME 150 /* secs 'till terminated (RFC1035 suggests > 120s) */
20#define EDNS_PKTSZ 1280 /* default max EDNS.0 UDP packet from RFC2671 */
21#define TIMEOUT 20 /* drop UDP queries after TIMEOUT seconds */
Simon Kelley9e4abcb2004-01-22 19:47:41 +000022#define LOGRATE 120 /* log table overflows every LOGRATE seconds */
23#define CACHESIZ 150 /* default cache size */
Simon Kelley33820b72004-04-03 21:10:00 +010024#define MAXTOK 50 /* token in DHCP leases */
Simon Kelley44a2a312004-03-10 20:04:35 +000025#define MAXLEASES 150 /* maximum number of DHCP leases */
Simon Kelley9e4abcb2004-01-22 19:47:41 +000026#define SMALLDNAME 40 /* most domain names are smaller than this */
Simon Kelley9e4abcb2004-01-22 19:47:41 +000027#define HOSTSFILE "/etc/hosts"
Simon Kelley44a2a312004-03-10 20:04:35 +000028#define ETHERSFILE "/etc/ethers"
Simon Kelley9e4abcb2004-01-22 19:47:41 +000029#ifdef __uClinux__
30# define RESOLVFILE "/etc/config/resolv.conf"
31#else
32# define RESOLVFILE "/etc/resolv.conf"
33#endif
34#define RUNFILE "/var/run/dnsmasq.pid"
Simon Kelley44a2a312004-03-10 20:04:35 +000035#if defined(__FreeBSD__) || defined (__OpenBSD__)
Simon Kelley9e4abcb2004-01-22 19:47:41 +000036# define LEASEFILE "/var/db/dnsmasq.leases"
37#else
38# define LEASEFILE "/var/lib/misc/dnsmasq.leases"
Simon Kelleyfeba5c12004-07-27 20:28:58 +010039#endif
40#if defined(__FreeBSD__)
41# define CONFFILE "/usr/local/etc/dnsmasq.conf"
42#else
Simon Kelleyb49644f2004-01-30 21:36:24 +000043# define CONFFILE "/etc/dnsmasq.conf"
Simon Kelley9e4abcb2004-01-22 19:47:41 +000044#endif
45#define DEFLEASE 3600 /* default lease time, 1 hour */
46#define CHUSER "nobody"
47#define CHGRP "dip"
48#define IP6INTERFACES "/proc/net/if_inet6"
Simon Kelley44a2a312004-03-10 20:04:35 +000049#define UPTIME "/proc/uptime"
Simon Kelley9e4abcb2004-01-22 19:47:41 +000050#define DHCP_SERVER_PORT 67
51#define DHCP_CLIENT_PORT 68
52
53/* Logfile stuff - change this to change the options and facility */
54/* debug is true if the --no-daemon flag is given */
55#ifdef LOG_PERROR
56# define DNSMASQ_LOG_OPT(debug) (debug) ? LOG_PERROR : LOG_PID
57#else
58# define DNSMASQ_LOG_OPT(debug) (debug) ? 0 : LOG_PID
59#endif
60
61#ifdef LOG_LOCAL0
62# define DNSMASQ_LOG_FAC(debug) (debug) ? LOG_LOCAL0 : LOG_DAEMON
63#else
64# define DNSMASQ_LOG_FAC(debug) LOG_DAEMON
65#endif
66
67
68/* Decide if we're going to support IPv6 */
69/* We assume that systems which don't have IPv6
70 headers don't have ntop and pton either */
71
Simon Kelleyfeba5c12004-07-27 20:28:58 +010072#if defined(INET6_ADDRSTRLEN) && defined(IPV6_V6ONLY) && !defined(NO_IPV6)
Simon Kelley9e4abcb2004-01-22 19:47:41 +000073# define HAVE_IPV6
74# define ADDRSTRLEN INET6_ADDRSTRLEN
Simon Kelley44a2a312004-03-10 20:04:35 +000075# if defined(SOL_IPV6)
76# define IPV6_LEVEL SOL_IPV6
77# else
78# define IPV6_LEVEL IPPROTO_IPV6
79# endif
Simon Kelley9e4abcb2004-01-22 19:47:41 +000080#elif defined(INET_ADDRSTRLEN)
81# undef HAVE_IPV6
82# define ADDRSTRLEN INET_ADDRSTRLEN
83#else
84# undef HAVE_IPV6
85# define ADDRSTRLEN 16 /* 4*3 + 3 dots + NULL */
86#endif
87
88/* Get linux C library versions. */
89#if defined(__linux__) && !defined(__UCLIBC__) && !defined(__uClinux__)
90# include <libio.h>
91#endif
92
93
94/* Follows system specific switches. If you run on a
95 new system, you may want to edit these.
96 May replace this with Autoconf one day.
97
Simon Kelley9e4abcb2004-01-22 19:47:41 +000098HAVE_LINUX_IPV6_PROC
99 define this to do IPv6 interface discovery using
100 proc/net/if_inet6 ala LINUX.
101
Simon Kelley44a2a312004-03-10 20:04:35 +0000102HAVE_BROKEN_RTC
103 define this on embeded systems which don't have an RTC
104 which keeps time over reboots. Causes dnsmasq to use uptime()
105 for timing, and keep relative time values in its leases file.
106 Also enables "Flash disk mode". Normally, dnsmasq tries very hard to
107 keep the on-disk leases file up-to-date: rewriting it after every change.
108 When HAVE_BROKEN_RTC is in effect, a different regime is used:
109 The leases file is written when dnsmasq terminates, when it receives
110 SIGALRM, when a brand new lease is allocated, or every n seconds,
111 where n is one third of the smallest time configured for leases
112 in a --dhcp-range or --dhcp-host option.
113 NOTE: when enabling or disabling this, be sure to delete any old
114 leases file, otherwise dnsmasq may get very confused.
115 This configuration currently only works on Linux, but could be made to
116 work on other systems by teaching dnsmasq_time() in utils.c how to
117 read the system uptime.
118
Simon Kelley33820b72004-04-03 21:10:00 +0100119HAVE_ISC_READER
120 define this to include the old ISC dhcpcd integration. Note that you cannot
121 set both HAVE_ISC_READER and HAVE_BROKEN_RTC.
122
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000123HAVE_GETOPT_LONG
124 define this if you have GNU libc or GNU getopt.
125
126HAVE_ARC4RANDOM
127 define this if you have arc4random() to get better security from DNS spoofs
128 by using really random ids (OpenBSD)
129
130HAVE_RANDOM
131 define this if you have the 4.2BSD random() function (and its
132 associated srandom() function), which is at least as good as (if not
133 better than) the rand() function.
134
135HAVE_DEV_RANDOM
136 define this if you have the /dev/random device, which gives truly
137 random numbers but may run out of random numbers.
138
139HAVE_DEV_URANDOM
140 define this if you have the /dev/urandom device, which gives
141 semi-random numbers when it runs out of truly random numbers.
142
143HAVE_SOCKADDR_SA_LEN
144 define this if struct sockaddr has sa_len field (*BSD)
145
146HAVE_PSELECT
147 If your C library implements pselect, define this.
148
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000149HAVE_BPF
150 If your OS implements Berkeley PAcket filter, define this.
151
152NOTES:
153 For Linux you should define
154 HAVE_LINUX_IPV6_PROC
155 HAVE_GETOPT_LONG
156 HAVE_RANDOM
157 HAVE_DEV_RANDOM
158 HAVE_DEV_URANDOM
Simon Kelley44a2a312004-03-10 20:04:35 +0000159 you should NOT define
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000160 HAVE_ARC4RANDOM
161 HAVE_SOCKADDR_SA_LEN
162
163 For *BSD systems you should define
164 HAVE_SOCKADDR_SA_LEN
165 HAVE_RANDOM
166 HAVE_BPF
167 you should NOT define
168 HAVE_LINUX_IPV6_PROC
169 and you MAY define
170 HAVE_ARC4RANDOM - OpenBSD and FreeBSD
171 HAVE_DEV_URANDOM - OpenBSD and FreeBSD
172 HAVE_DEV_RANDOM - FreeBSD (OpenBSD with hardware random number generator)
173 HAVE_GETOPT_LONG - only if you link GNU getopt.
174
175*/
176
Simon Kelley33820b72004-04-03 21:10:00 +0100177/* platform independent options. */
178#undef HAVE_BROKEN_RTC
179#define HAVE_ISC_READER
180
181#if defined(HAVE_BROKEN_RTC) && defined(HAVE_ISC_READER)
182# error HAVE_ISC_READER is not compatible with HAVE_BROKEN_RTC
183#endif
184
185/* platform dependent options. */
186
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000187/* Must preceed __linux__ since uClinux defines __linux__ too. */
188#if defined(__uClinux__) || defined(__UCLIBC__)
189#undef HAVE_LINUX_IPV6_PROC
190#define HAVE_GETOPT_LONG
191#undef HAVE_ARC4RANDOM
192#define HAVE_RANDOM
193#define HAVE_DEV_URANDOM
194#define HAVE_DEV_RANDOM
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000195#undef HAVE_SOCKADDR_SA_LEN
196#undef HAVE_PSELECT
197/* Don't fork into background on uClinux */
198#if defined(__uClinux__)
199# define NO_FORK
200#endif
201
202/* libc5 - must precede __linux__ too */
203/* Note to build a libc5 binary on a modern Debian system:
204 install the packages altgcc libc5 and libc5-altdev
205 then run "make CC=i486-linuxlibc1-gcc" */
206/* Note that compling dnsmasq 2.x under libc5 and kernel 2.0.x
207 is probably doomed - no packet socket for starters. */
208#elif defined(__linux__) && \
209 defined(_LINUX_C_LIB_VERSION_MAJOR) && \
210 (_LINUX_C_LIB_VERSION_MAJOR == 5 )
211#undef HAVE_IPV6
212#undef HAVE_LINUX_IPV6_PROC
213#define HAVE_GETOPT_LONG
214#undef HAVE_ARC4RANDOM
215#define HAVE_RANDOM
216#define HAVE_DEV_URANDOM
217#define HAVE_DEV_RANDOM
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000218#undef HAVE_SOCKADDR_SA_LEN
219#undef HAVE_PSELECT
220/* Fix various misfeatures of libc5 headers */
221#define T_SRV 33
222typedef unsigned long in_addr_t;
223typedef size_t socklen_t;
224
225/* This is for glibc 2.x */
226#elif defined(__linux__)
227#define HAVE_LINUX_IPV6_PROC
228#define HAVE_GETOPT_LONG
229#undef HAVE_ARC4RANDOM
230#define HAVE_RANDOM
231#define HAVE_DEV_URANDOM
232#define HAVE_DEV_RANDOM
233#undef HAVE_SOCKADDR_SA_LEN
234#define HAVE_PSELECT
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000235/* glibc < 2.2 has broken Sockaddr_in6 so we have to use our own. */
236/* glibc < 2.2 doesn't define in_addr_t */
237#if defined(__GLIBC__) && (__GLIBC__ == 2) && \
238 defined(__GLIBC_MINOR__) && (__GLIBC_MINOR__ < 2)
239typedef unsigned long in_addr_t;
240#if defined(HAVE_IPV6)
241# define HAVE_BROKEN_SOCKADDR_IN6
242#endif
243#endif
244
Simon Kelley44a2a312004-03-10 20:04:35 +0000245/* #elif defined(__OpenBSD__)
246#error The sockets API in OpenBSD does not provide facilities required by dnsmasq
247*/
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000248#elif defined(__FreeBSD__) || defined(__OpenBSD__)
249#undef HAVE_LINUX_IPV6_PROC
250#undef HAVE_GETOPT_LONG
251#define HAVE_ARC4RANDOM
252#define HAVE_RANDOM
253#define HAVE_DEV_URANDOM
254#define HAVE_SOCKADDR_SA_LEN
255#undef HAVE_PSELECT
256#define HAVE_BPF
257
258#elif defined(__APPLE__)
259#undef HAVE_LINUX_IPV6_PROC
260#undef HAVE_GETOPT_LONG
261#define HAVE_ARC4RANDOM
262#define HAVE_RANDOM
263#define HAVE_DEV_URANDOM
264#define HAVE_SOCKADDR_SA_LEN
265#undef HAVE_PSELECT
266#define HAVE_BPF
Simon Kelley33820b72004-04-03 21:10:00 +0100267#define BIND_8_COMPAT
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000268/* Define before sys/socket.h is included so we get socklen_t */
269#define _BSD_SOCKLEN_T_
270/* The two below are not defined in Mac OS X arpa/nameserv.h */
271#define IN6ADDRSZ 16
272#define T_SRV 33
273
274#elif defined(__NetBSD__)
275#undef HAVE_LINUX_IPV6_PROC
276#undef HAVE_GETOPT_LONG
277#undef HAVE_ARC4RANDOM
278#define HAVE_RANDOM
279#undef HAVE_DEV_URANDOM
280#undef HAVE_DEV_RANDOM
281#define HAVE_SOCKADDR_SA_LEN
282#undef HAVE_PSELECT
283#define HAVE_BPF
284
285/* env "LIBS=-lsocket -lnsl" make */
286#elif defined(__sun) || defined(__sun__)
287#undef HAVE_LINUX_IPV6_PROC
288#undef HAVE_GETOPT_LONG
289#undef HAVE_ARC4RANDOM
290#define HAVE_RANDOM
291#undef HAVE_DEV_URANDOM
292#undef HAVE_DEV_RANDOM
293#undef HAVE_SOCKADDR_SA_LEN
294#undef HAVE_PSELECT
295#define HAVE_BPF
296#endif
297
298
299
Simon Kelley33820b72004-04-03 21:10:00 +0100300