1/* 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#ifdef OPENDNS_PARENTAL_CONTROL
15#define VERSION "2.15-OpenDNS-1"  /* Foxconn modified, Tony W.Y. Wang, 12/02/2008, @Parental Control OpenDNS */
16#else
17#define VERSION "2.15"
18#endif
19/* foxconn wklin modified start, 08/31/2007 */
20#ifdef MULTIPLE_PPPOE /* for downsize ram usage */
21#define FTABSIZ 50 /* max number of outstanding requests */
22#define MAX_PROCS 10 /* max no children for TCP requests */
23#define CHILD_LIFETIME 150 /* secs 'till terminated (RFC1035 suggests > 120s) */
24#define EDNS_PKTSZ 1280 /* default max EDNS.0 UDP packet from RFC2671 */
25#define TIMEOUT 20 /* drop UDP queries after TIMEOUT seconds */
26#define LOGRATE 120 /* log table overflows every LOGRATE seconds */
27#define CACHESIZ 0 /* default cache size */
28#define MAXTOK 50 /* token in DHCP leases */
29#define MAXLEASES 150 /* maximum number of DHCP leases */
30#define SMALLDNAME 40 /* most domain names are smaller than this */
31#else
32#define FTABSIZ 150 /* max number of outstanding requests */
33#define MAX_PROCS 20 /* max no children for TCP requests */
34#define CHILD_LIFETIME 150 /* secs 'till terminated (RFC1035 suggests > 120s) */
35#define EDNS_PKTSZ 1280 /* default max EDNS.0 UDP packet from RFC2671 */
36#define TIMEOUT 20 /* drop UDP queries after TIMEOUT seconds */
37#define LOGRATE 120 /* log table overflows every LOGRATE seconds */
38#define CACHESIZ 150 /* default cache size */
39#define MAXTOK 50 /* token in DHCP leases */
40#define MAXLEASES 150 /* maximum number of DHCP leases */
41#define SMALLDNAME 40 /* most domain names are smaller than this */
42#endif
43/* foxconn wklin modified end, 08/31/2007 */
44#define HOSTSFILE "/etc/hosts"
45#define ETHERSFILE "/etc/ethers"
46#ifdef __uClinux__
47#  define RESOLVFILE "/etc/config/resolv.conf"
48#else
49#  define RESOLVFILE "/etc/resolv.conf"
50#endif
51#define RUNFILE "/var/run/dnsmasq.pid"
52#if defined(__FreeBSD__) || defined (__OpenBSD__)
53#   define LEASEFILE "/var/db/dnsmasq.leases"
54#else
55#   define LEASEFILE "/var/lib/misc/dnsmasq.leases"
56#endif
57#if defined(__FreeBSD__)
58#   define CONFFILE "/usr/local/etc/dnsmasq.conf"
59#else
60#   define CONFFILE "/etc/dnsmasq.conf"
61#endif
62#define DEFLEASE 3600 /* default lease time, 1 hour */
63#define CHUSER "nobody"
64#define CHGRP "dip"
65#define IP6INTERFACES "/proc/net/if_inet6"
66#define UPTIME "/proc/uptime"
67#define DHCP_SERVER_PORT 67
68#define DHCP_CLIENT_PORT 68
69
70/* Logfile stuff - change this to change the options and facility */
71/* debug is true if the --no-daemon flag is given */
72#ifdef LOG_PERROR
73#  define DNSMASQ_LOG_OPT(debug)  (debug) ? LOG_PERROR : LOG_PID
74#else
75#  define DNSMASQ_LOG_OPT(debug)  (debug) ? 0 : LOG_PID
76#endif
77
78#ifdef LOG_LOCAL0
79#  define DNSMASQ_LOG_FAC(debug)  (debug) ? LOG_LOCAL0 : LOG_DAEMON
80#else
81#  define DNSMASQ_LOG_FAC(debug)  LOG_DAEMON
82#endif
83
84/* A small collection of RR-types which are missing on some platforms */
85
86#ifndef T_SRV
87#  define T_SRV 33
88#endif
89
90#ifndef T_OPT
91#  define T_OPT 41
92#endif
93
94/* Decide if we're going to support IPv6 */
95/* We assume that systems which don't have IPv6
96   headers don't have ntop and pton either */
97
98#if defined(INET6_ADDRSTRLEN) && defined(IPV6_V6ONLY) && !defined(NO_IPV6)
99#  define HAVE_IPV6
100#  define ADDRSTRLEN INET6_ADDRSTRLEN
101#  if defined(SOL_IPV6)
102#    define IPV6_LEVEL SOL_IPV6
103#  else
104#    define IPV6_LEVEL IPPROTO_IPV6
105#  endif
106#elif defined(INET_ADDRSTRLEN)
107#  undef HAVE_IPV6
108#  define ADDRSTRLEN INET_ADDRSTRLEN
109#else
110#  undef HAVE_IPV6
111#  define ADDRSTRLEN 16 /* 4*3 + 3 dots + NULL */
112#endif
113
114/* Get linux C library versions. */
115#if defined(__linux__) && !defined(__UCLIBC__) && !defined(__uClinux__)
116#  include <libio.h>
117#endif
118
119
120/* Follows system specific switches. If you run on a
121   new system, you may want to edit these.
122   May replace this with Autoconf one day.
123
124HAVE_LINUX_IPV6_PROC
125   define this to do IPv6 interface discovery using
126   proc/net/if_inet6 ala LINUX.
127
128HAVE_BROKEN_RTC
129   define this on embeded systems which don't have an RTC
130   which keeps time over reboots. Causes dnsmasq to use uptime()
131   for timing, and keep relative time values in its leases file.
132   Also enables "Flash disk mode". Normally, dnsmasq tries very hard to
133   keep the on-disk leases file up-to-date: rewriting it after every change.
134   When HAVE_BROKEN_RTC is in effect, a different regime is used:
135   The leases file is written when dnsmasq terminates, when it receives
136   SIGALRM, when a brand new lease is allocated, or every n seconds,
137   where n is one third  of the smallest time configured for leases
138   in a --dhcp-range or --dhcp-host option.
139   NOTE: when enabling or disabling this, be sure to delete any old
140   leases file, otherwise dnsmasq may get very confused.
141   This configuration currently only works on Linux, but could be made to
142   work on other systems by teaching dnsmasq_time() in utils.c how to
143   read the system uptime.
144
145HAVE_ISC_READER
146   define this to include the old ISC dhcpcd integration. Note that you cannot
147   set both HAVE_ISC_READER and HAVE_BROKEN_RTC.
148
149HAVE_GETOPT_LONG
150   define this if you have GNU libc or GNU getopt.
151
152HAVE_ARC4RANDOM
153   define this if you have arc4random() to get better security from DNS spoofs
154   by using really random ids (OpenBSD)
155
156HAVE_RANDOM
157   define this if you have the 4.2BSD random() function (and its
158   associated srandom() function), which is at least as good as (if not
159   better than) the rand() function.
160
161HAVE_DEV_RANDOM
162   define this if you have the /dev/random device, which gives truly
163   random numbers but may run out of random numbers.
164
165HAVE_DEV_URANDOM
166   define this if you have the /dev/urandom device, which gives
167   semi-random numbers when it runs out of truly random numbers.
168
169HAVE_SOCKADDR_SA_LEN
170   define this if struct sockaddr has sa_len field (*BSD)
171
172HAVE_PSELECT
173   If your C library implements pselect, define this.
174
175HAVE_BPF
176   If your OS implements Berkeley PAcket filter, define this.
177
178NOTES:
179   For Linux you should define
180      HAVE_LINUX_IPV6_PROC
181      HAVE_GETOPT_LONG
182      HAVE_RANDOM
183      HAVE_DEV_RANDOM
184      HAVE_DEV_URANDOM
185  you should NOT define
186      HAVE_ARC4RANDOM
187      HAVE_SOCKADDR_SA_LEN
188
189   For *BSD systems you should define
190     HAVE_SOCKADDR_SA_LEN
191     HAVE_RANDOM
192     HAVE_BPF
193   you should NOT define
194     HAVE_LINUX_IPV6_PROC
195   and you MAY define
196     HAVE_ARC4RANDOM - OpenBSD and FreeBSD
197     HAVE_DEV_URANDOM - OpenBSD and FreeBSD
198     HAVE_DEV_RANDOM - FreeBSD (OpenBSD with hardware random number generator)
199     HAVE_GETOPT_LONG - only if you link GNU getopt.
200
201*/
202
203/* platform independent options. */
204#undef HAVE_BROKEN_RTC
205#undef HAVE_ISC_READER /* #define HAVE_ISC_READER */
206
207#if defined(HAVE_BROKEN_RTC) && defined(HAVE_ISC_READER)
208#  error HAVE_ISC_READER is not compatible with HAVE_BROKEN_RTC
209#endif
210
211/* platform dependent options. */
212
213/* Must preceed __linux__ since uClinux defines __linux__ too. */
214#if defined(__uClinux__) || defined(__UCLIBC__)
215#undef HAVE_LINUX_IPV6_PROC
216#define HAVE_GETOPT_LONG
217#undef HAVE_ARC4RANDOM
218#define HAVE_RANDOM
219#define HAVE_DEV_URANDOM
220#define HAVE_DEV_RANDOM
221#undef HAVE_SOCKADDR_SA_LEN
222#undef HAVE_PSELECT
223/* Don't fork into background on uClinux */
224#if defined(__uClinux__)
225#  define NO_FORK
226#endif
227
228/* libc5 - must precede __linux__ too */
229/* Note to build a libc5 binary on a modern Debian system:
230   install the packages altgcc libc5 and libc5-altdev
231   then run "make CC=i486-linuxlibc1-gcc" */
232/* Note that compling dnsmasq 2.x under libc5 and kernel 2.0.x
233   is probably doomed - no packet socket for starters. */
234#elif defined(__linux__) && \
235      defined(_LINUX_C_LIB_VERSION_MAJOR) && \
236      (_LINUX_C_LIB_VERSION_MAJOR == 5 )
237#undef HAVE_IPV6
238#undef HAVE_LINUX_IPV6_PROC
239#define HAVE_GETOPT_LONG
240#undef HAVE_ARC4RANDOM
241#define HAVE_RANDOM
242#define HAVE_DEV_URANDOM
243#define HAVE_DEV_RANDOM
244#undef HAVE_SOCKADDR_SA_LEN
245#undef HAVE_PSELECT
246/* Fix various misfeatures of libc5 headers */
247typedef unsigned long in_addr_t;
248typedef size_t socklen_t;
249
250/* This is for glibc 2.x */
251#elif defined(__linux__)
252#define HAVE_LINUX_IPV6_PROC
253#define HAVE_GETOPT_LONG
254#undef HAVE_ARC4RANDOM
255#define HAVE_RANDOM
256#define HAVE_DEV_URANDOM
257#define HAVE_DEV_RANDOM
258#undef HAVE_SOCKADDR_SA_LEN
259#define HAVE_PSELECT
260/* glibc < 2.2  has broken Sockaddr_in6 so we have to use our own. */
261/* glibc < 2.2 doesn't define in_addr_t */
262#if defined(__GLIBC__) && (__GLIBC__ == 2) && \
263    defined(__GLIBC_MINOR__) && (__GLIBC_MINOR__ < 2)
264typedef unsigned long in_addr_t;
265#if defined(HAVE_IPV6)
266#   define HAVE_BROKEN_SOCKADDR_IN6
267#endif
268#endif
269
270/* #elif defined(__OpenBSD__)
271#error The sockets API in OpenBSD does not provide facilities required by dnsmasq
272*/
273#elif defined(__FreeBSD__) || defined(__OpenBSD__)
274#undef HAVE_LINUX_IPV6_PROC
275#undef HAVE_GETOPT_LONG
276#define HAVE_ARC4RANDOM
277#define HAVE_RANDOM
278#define HAVE_DEV_URANDOM
279#define HAVE_SOCKADDR_SA_LEN
280#undef HAVE_PSELECT
281#define HAVE_BPF
282
283#elif defined(__APPLE__)
284#undef HAVE_LINUX_IPV6_PROC
285#undef HAVE_GETOPT_LONG
286#define HAVE_ARC4RANDOM
287#define HAVE_RANDOM
288#define HAVE_DEV_URANDOM
289#define HAVE_SOCKADDR_SA_LEN
290#undef HAVE_PSELECT
291#define HAVE_BPF
292#define BIND_8_COMPAT
293/* Define before sys/socket.h is included so we get socklen_t */
294#define _BSD_SOCKLEN_T_
295/* The three below are not defined in Mac OS X arpa/nameserv.h */
296#define IN6ADDRSZ 16
297
298#elif defined(__NetBSD__)
299#undef HAVE_LINUX_IPV6_PROC
300#undef HAVE_GETOPT_LONG
301#undef HAVE_ARC4RANDOM
302#define HAVE_RANDOM
303#undef HAVE_DEV_URANDOM
304#undef HAVE_DEV_RANDOM
305#define HAVE_SOCKADDR_SA_LEN
306#undef HAVE_PSELECT
307#define HAVE_BPF
308
309/* env "LIBS=-lsocket -lnsl" make */
310#elif defined(__sun) || defined(__sun__)
311#undef HAVE_LINUX_IPV6_PROC
312#undef HAVE_GETOPT_LONG
313#undef HAVE_ARC4RANDOM
314#define HAVE_RANDOM
315#undef HAVE_DEV_URANDOM
316#undef HAVE_DEV_RANDOM
317#undef HAVE_SOCKADDR_SA_LEN
318#undef HAVE_PSELECT
319#define HAVE_BPF
320#endif
321
322
323
324
325