blob: 3e9470e3b0112f26b3d6d433879afbf1796a5e85 [file] [log] [blame]
Simon Kelleye17fb622006-01-14 20:33:46 +00001/* dnsmasq is Copyright (c) 2000-2006 Simon Kelley
Simon Kelley9e4abcb2004-01-22 19:47:41 +00002
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
Simon Kelley309331f2006-04-22 15:05:01 +010013#define VERSION "2.29"
Simon Kelley9e4abcb2004-01-22 19:47:41 +000014
15#define FTABSIZ 150 /* max number of outstanding requests */
Simon Kelleyfeba5c12004-07-27 20:28:58 +010016#define MAX_PROCS 20 /* max no children for TCP requests */
17#define CHILD_LIFETIME 150 /* secs 'till terminated (RFC1035 suggests > 120s) */
18#define EDNS_PKTSZ 1280 /* default max EDNS.0 UDP packet from RFC2671 */
19#define TIMEOUT 20 /* drop UDP queries after TIMEOUT seconds */
Simon Kelleycdeda282006-03-16 20:16:06 +000020#define LEASE_RETRY 60 /* on error, retry writing leasefile after LEASE_RETRY seconds */
Simon Kelley9e4abcb2004-01-22 19:47:41 +000021#define LOGRATE 120 /* log table overflows every LOGRATE seconds */
22#define CACHESIZ 150 /* default cache size */
Simon Kelley44a2a312004-03-10 20:04:35 +000023#define MAXLEASES 150 /* maximum number of DHCP leases */
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010024#define PING_WAIT 3 /* wait for ping address-in-use test */
25#define PING_CACHE_TIME 30 /* Ping test assumed to be valid this long. */
26#define DHCP_PACKET_MAX 16384 /* hard limit on DHCP packet size */
Simon Kelley9e4abcb2004-01-22 19:47:41 +000027#define SMALLDNAME 40 /* most domain names are smaller than this */
Simon Kelley9e4abcb2004-01-22 19:47:41 +000028#define HOSTSFILE "/etc/hosts"
Simon Kelley44a2a312004-03-10 20:04:35 +000029#define ETHERSFILE "/etc/ethers"
Simon Kelley9e4abcb2004-01-22 19:47:41 +000030#ifdef __uClinux__
31# define RESOLVFILE "/etc/config/resolv.conf"
32#else
33# define RESOLVFILE "/etc/resolv.conf"
34#endif
35#define RUNFILE "/var/run/dnsmasq.pid"
Simon Kelley44a2a312004-03-10 20:04:35 +000036#if defined(__FreeBSD__) || defined (__OpenBSD__)
Simon Kelley9e4abcb2004-01-22 19:47:41 +000037# define LEASEFILE "/var/db/dnsmasq.leases"
38#else
39# define LEASEFILE "/var/lib/misc/dnsmasq.leases"
Simon Kelleyfeba5c12004-07-27 20:28:58 +010040#endif
41#if defined(__FreeBSD__)
42# define CONFFILE "/usr/local/etc/dnsmasq.conf"
43#else
Simon Kelleyb49644f2004-01-30 21:36:24 +000044# define CONFFILE "/etc/dnsmasq.conf"
Simon Kelley9e4abcb2004-01-22 19:47:41 +000045#endif
46#define DEFLEASE 3600 /* default lease time, 1 hour */
47#define CHUSER "nobody"
48#define CHGRP "dip"
Simon Kelley9e4abcb2004-01-22 19:47:41 +000049#define DHCP_SERVER_PORT 67
50#define DHCP_CLIENT_PORT 68
51
Simon Kelley3d8df262005-08-29 12:19:27 +010052/* DBUS interface specifics */
53#define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq"
54#define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
55
Simon Kelley9e4abcb2004-01-22 19:47:41 +000056/* Logfile stuff - change this to change the options and facility */
57/* debug is true if the --no-daemon flag is given */
58#ifdef LOG_PERROR
59# define DNSMASQ_LOG_OPT(debug) (debug) ? LOG_PERROR : LOG_PID
60#else
61# define DNSMASQ_LOG_OPT(debug) (debug) ? 0 : LOG_PID
62#endif
63
64#ifdef LOG_LOCAL0
65# define DNSMASQ_LOG_FAC(debug) (debug) ? LOG_LOCAL0 : LOG_DAEMON
66#else
67# define DNSMASQ_LOG_FAC(debug) LOG_DAEMON
68#endif
69
Simon Kelley3be34542004-09-11 19:12:13 +010070/* A small collection of RR-types which are missing on some platforms */
71
72#ifndef T_SRV
73# define T_SRV 33
74#endif
75
76#ifndef T_OPT
77# define T_OPT 41
78#endif
Simon Kelley9e4abcb2004-01-22 19:47:41 +000079
Simon Kelley9e4abcb2004-01-22 19:47:41 +000080/* Get linux C library versions. */
81#if defined(__linux__) && !defined(__UCLIBC__) && !defined(__uClinux__)
82# include <libio.h>
83#endif
84
85
86/* Follows system specific switches. If you run on a
87 new system, you may want to edit these.
88 May replace this with Autoconf one day.
89
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010090HAVE_LINUX_NETWORK
91 define this to do networking the Linux way. When it's defined, the code will
92 use IP_PKTINFO, Linux capabilities and the RTnetlink system. If it's not defined,
93 a few facilities will be lost, namely support for multiple addresses on an interface,
94 DNS query retransmission, and (on some systems) wildcard interface binding.
Simon Kelley9e4abcb2004-01-22 19:47:41 +000095
Simon Kelley44a2a312004-03-10 20:04:35 +000096HAVE_BROKEN_RTC
Simon Kelley5e9e0ef2006-04-17 14:24:29 +010097 define this on embedded systems which don't have an RTC
98 which keeps time over reboots. Causes dnsmasq to use uptime
99 for timing, and keep lease lengths rather than expiry times
100 in its leases file. This also make dnsmasq "flash disk friendly".
101 Normally, dnsmasq tries very hard to keep the on-disk leases file
102 up-to-date: rewriting it after every renewal. When HAVE_BROKEN_RTC
103 is in effect, the lease file is only written when a new lease is
104 created, or an old one destroyed. (Because those are the only times
105 it changes.) This vastly reduces the number of file writes, and makes
106 it viable to keep the lease file on a flash filesystem.
Simon Kelley44a2a312004-03-10 20:04:35 +0000107 NOTE: when enabling or disabling this, be sure to delete any old
108 leases file, otherwise dnsmasq may get very confused.
Simon Kelley44a2a312004-03-10 20:04:35 +0000109
Simon Kelley33820b72004-04-03 21:10:00 +0100110HAVE_ISC_READER
111 define this to include the old ISC dhcpcd integration. Note that you cannot
112 set both HAVE_ISC_READER and HAVE_BROKEN_RTC.
113
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000114HAVE_GETOPT_LONG
115 define this if you have GNU libc or GNU getopt.
116
117HAVE_ARC4RANDOM
118 define this if you have arc4random() to get better security from DNS spoofs
119 by using really random ids (OpenBSD)
120
121HAVE_RANDOM
122 define this if you have the 4.2BSD random() function (and its
123 associated srandom() function), which is at least as good as (if not
124 better than) the rand() function.
125
126HAVE_DEV_RANDOM
127 define this if you have the /dev/random device, which gives truly
128 random numbers but may run out of random numbers.
129
130HAVE_DEV_URANDOM
131 define this if you have the /dev/urandom device, which gives
132 semi-random numbers when it runs out of truly random numbers.
133
134HAVE_SOCKADDR_SA_LEN
135 define this if struct sockaddr has sa_len field (*BSD)
136
Simon Kelley3d8df262005-08-29 12:19:27 +0100137HAVE_DBUS
138 Define this if you want to link against libdbus, and have dnsmasq
139 define some methods to allow (re)configuration of the upstream DNS
140 servers via DBus.
141
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000142NOTES:
143 For Linux you should define
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100144 HAVE_LINUX_NETWORK
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000145 HAVE_GETOPT_LONG
146 HAVE_RANDOM
147 HAVE_DEV_RANDOM
148 HAVE_DEV_URANDOM
Simon Kelley44a2a312004-03-10 20:04:35 +0000149 you should NOT define
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000150 HAVE_ARC4RANDOM
151 HAVE_SOCKADDR_SA_LEN
152
153 For *BSD systems you should define
154 HAVE_SOCKADDR_SA_LEN
155 HAVE_RANDOM
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000156 you should NOT define
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100157 HAVE_LINUX_NETWORK
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000158 and you MAY define
Simon Kelleyfd9fa482004-10-21 20:24:00 +0100159 HAVE_ARC4RANDOM - OpenBSD and FreeBSD and NetBSD version 2.0 or later
160 HAVE_DEV_URANDOM - OpenBSD and FreeBSD and NetBSD
161 HAVE_DEV_RANDOM - FreeBSD and NetBSD
162 (OpenBSD with hardware random number generator)
Simon Kelley59353a62004-11-21 19:34:28 +0000163 HAVE_GETOPT_LONG - NetBSD, later FreeBSD
Simon Kelleyfd9fa482004-10-21 20:24:00 +0100164 (FreeBSD and OpenBSD only if you link GNU getopt)
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000165
166*/
167
Simon Kelley309331f2006-04-22 15:05:01 +0100168/* platform independent options- uncomment to enable */
169/* #define HAVE_BROKEN_RTC */
170/* #define HAVE_ISC_READER */
171/* #define HAVE_DBUS */
Simon Kelley33820b72004-04-03 21:10:00 +0100172
173#if defined(HAVE_BROKEN_RTC) && defined(HAVE_ISC_READER)
174# error HAVE_ISC_READER is not compatible with HAVE_BROKEN_RTC
175#endif
176
177/* platform dependent options. */
178
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000179/* Must preceed __linux__ since uClinux defines __linux__ too. */
Simon Kelleye17fb622006-01-14 20:33:46 +0000180#if defined(__uClinux__)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100181#define HAVE_LINUX_NETWORK
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000182#define HAVE_GETOPT_LONG
183#undef HAVE_ARC4RANDOM
184#define HAVE_RANDOM
185#define HAVE_DEV_URANDOM
186#define HAVE_DEV_RANDOM
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000187#undef HAVE_SOCKADDR_SA_LEN
Simon Kelley59353a62004-11-21 19:34:28 +0000188/* Never use fork() on uClinux. Note that this is subtly different from the
189 --keep-in-foreground option, since it also suppresses forking new
190 processes for TCP connections. It's intended for use on MMU-less kernels. */
Simon Kelleye17fb622006-01-14 20:33:46 +0000191#define NO_FORK
192
193#elif defined(__UCLIBC__)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100194#define HAVE_LINUX_NETWORK
Simon Kelleye17fb622006-01-14 20:33:46 +0000195#if defined(__UCLIBC_HAS_GNU_GETOPT__) || \
196 ((__UCLIBC_MAJOR__==0) && (__UCLIBC_MINOR__==9) && (__UCLIBC_SUBLEVEL__<21))
197# define HAVE_GETOPT_LONG
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100198#else
Simon Kelleye17fb622006-01-14 20:33:46 +0000199# undef HAVE_GETOPT_LONG
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100200#endif
Simon Kelleye17fb622006-01-14 20:33:46 +0000201#undef HAVE_ARC4RANDOM
202#define HAVE_RANDOM
203#define HAVE_DEV_URANDOM
204#define HAVE_DEV_RANDOM
205#undef HAVE_SOCKADDR_SA_LEN
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100206#if !defined(__UCLIBC_HAS_MMU__)
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000207# define NO_FORK
208#endif
Simon Kelleye17fb622006-01-14 20:33:46 +0000209#if !defined(__UCLIBC_HAS_IPV6__)
210# define NO_IPV6
211#endif
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000212
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000213/* This is for glibc 2.x */
214#elif defined(__linux__)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100215#define HAVE_LINUX_NETWORK
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000216#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
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000222/* glibc < 2.2 has broken Sockaddr_in6 so we have to use our own. */
223/* glibc < 2.2 doesn't define in_addr_t */
224#if defined(__GLIBC__) && (__GLIBC__ == 2) && \
225 defined(__GLIBC_MINOR__) && (__GLIBC_MINOR__ < 2)
226typedef unsigned long in_addr_t;
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000227# define HAVE_BROKEN_SOCKADDR_IN6
228#endif
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000229
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000230#elif defined(__FreeBSD__) || defined(__OpenBSD__)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100231#undef HAVE_LINUX_NETWORK
Simon Kelley59353a62004-11-21 19:34:28 +0000232/* Later verions of FreeBSD have getopt_long() */
233#if defined(optional_argument) && defined(required_argument)
234# define HAVE_GETOPT_LONG
235#else
236# undef HAVE_GETOPT_LONG
237#endif
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000238#define HAVE_ARC4RANDOM
239#define HAVE_RANDOM
240#define HAVE_DEV_URANDOM
241#define HAVE_SOCKADDR_SA_LEN
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000242
243#elif defined(__APPLE__)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100244#undef HAVE_LINUX_NETWORK
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000245#undef HAVE_GETOPT_LONG
246#define HAVE_ARC4RANDOM
247#define HAVE_RANDOM
248#define HAVE_DEV_URANDOM
249#define HAVE_SOCKADDR_SA_LEN
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000250/* Define before sys/socket.h is included so we get socklen_t */
251#define _BSD_SOCKLEN_T_
Simon Kelleyfd9fa482004-10-21 20:24:00 +0100252/* This is not defined in Mac OS X arpa/nameserv.h */
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000253#define IN6ADDRSZ 16
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000254
255#elif defined(__NetBSD__)
Simon Kelley5e9e0ef2006-04-17 14:24:29 +0100256#undef HAVE_LINUX_NETWORK
Simon Kelleyfd9fa482004-10-21 20:24:00 +0100257#define HAVE_GETOPT_LONG
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000258#undef HAVE_ARC4RANDOM
259#define HAVE_RANDOM
Simon Kelleyfd9fa482004-10-21 20:24:00 +0100260#define HAVE_DEV_URANDOM
261#define HAVE_DEV_RANDOM
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000262#define HAVE_SOCKADDR_SA_LEN
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000263
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000264#endif
Simon Kelleye17fb622006-01-14 20:33:46 +0000265/* Decide if we're going to support IPv6 */
266/* We assume that systems which don't have IPv6
267 headers don't have ntop and pton either */
268
269#if defined(INET6_ADDRSTRLEN) && defined(IPV6_V6ONLY) && !defined(NO_IPV6)
270# define HAVE_IPV6
271# define ADDRSTRLEN INET6_ADDRSTRLEN
272# if defined(SOL_IPV6)
273# define IPV6_LEVEL SOL_IPV6
274# else
275# define IPV6_LEVEL IPPROTO_IPV6
276# endif
277#elif defined(INET_ADDRSTRLEN)
278# undef HAVE_IPV6
279# define ADDRSTRLEN INET_ADDRSTRLEN
280#else
281# undef HAVE_IPV6
282# define ADDRSTRLEN 16 /* 4*3 + 3 dots + NULL */
283#endif
284
Simon Kelley9e4abcb2004-01-22 19:47:41 +0000285