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