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 | 1ab84e2 | 2004-01-29 16:48:35 +0000 | [diff] [blame^] | 15 | #define VERSION "2.1" |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 16 | |
| 17 | #define FTABSIZ 150 /* max number of outstanding requests */ |
| 18 | #define TIMEOUT 40 /* drop queries after TIMEOUT seconds */ |
| 19 | #define LOGRATE 120 /* log table overflows every LOGRATE seconds */ |
| 20 | #define CACHESIZ 150 /* default cache size */ |
| 21 | #define SMALLDNAME 40 /* most domain names are smaller than this */ |
| 22 | #define CONFFILE "/etc/dnsmasq.conf" |
| 23 | #define HOSTSFILE "/etc/hosts" |
| 24 | #ifdef __uClinux__ |
| 25 | # define RESOLVFILE "/etc/config/resolv.conf" |
| 26 | #else |
| 27 | # define RESOLVFILE "/etc/resolv.conf" |
| 28 | #endif |
| 29 | #define RUNFILE "/var/run/dnsmasq.pid" |
| 30 | #ifdef __FreeBSD__ |
| 31 | # define LEASEFILE "/var/db/dnsmasq.leases" |
| 32 | #else |
| 33 | # define LEASEFILE "/var/lib/misc/dnsmasq.leases" |
| 34 | #endif |
| 35 | #define DEFLEASE 3600 /* default lease time, 1 hour */ |
| 36 | #define CHUSER "nobody" |
| 37 | #define CHGRP "dip" |
| 38 | #define IP6INTERFACES "/proc/net/if_inet6" |
| 39 | #define DHCP_SERVER_PORT 67 |
| 40 | #define DHCP_CLIENT_PORT 68 |
| 41 | |
| 42 | /* Logfile stuff - change this to change the options and facility */ |
| 43 | /* debug is true if the --no-daemon flag is given */ |
| 44 | #ifdef LOG_PERROR |
| 45 | # define DNSMASQ_LOG_OPT(debug) (debug) ? LOG_PERROR : LOG_PID |
| 46 | #else |
| 47 | # define DNSMASQ_LOG_OPT(debug) (debug) ? 0 : LOG_PID |
| 48 | #endif |
| 49 | |
| 50 | #ifdef LOG_LOCAL0 |
| 51 | # define DNSMASQ_LOG_FAC(debug) (debug) ? LOG_LOCAL0 : LOG_DAEMON |
| 52 | #else |
| 53 | # define DNSMASQ_LOG_FAC(debug) LOG_DAEMON |
| 54 | #endif |
| 55 | |
| 56 | |
| 57 | /* Decide if we're going to support IPv6 */ |
| 58 | /* We assume that systems which don't have IPv6 |
| 59 | headers don't have ntop and pton either */ |
| 60 | |
| 61 | #if defined(INET6_ADDRSTRLEN) |
| 62 | # define HAVE_IPV6 |
| 63 | # define ADDRSTRLEN INET6_ADDRSTRLEN |
| 64 | #elif defined(INET_ADDRSTRLEN) |
| 65 | # undef HAVE_IPV6 |
| 66 | # define ADDRSTRLEN INET_ADDRSTRLEN |
| 67 | #else |
| 68 | # undef HAVE_IPV6 |
| 69 | # define ADDRSTRLEN 16 /* 4*3 + 3 dots + NULL */ |
| 70 | #endif |
| 71 | |
| 72 | /* Get linux C library versions. */ |
| 73 | #if defined(__linux__) && !defined(__UCLIBC__) && !defined(__uClinux__) |
| 74 | # include <libio.h> |
| 75 | #endif |
| 76 | |
| 77 | |
| 78 | /* Follows system specific switches. If you run on a |
| 79 | new system, you may want to edit these. |
| 80 | May replace this with Autoconf one day. |
| 81 | |
| 82 | |
| 83 | HAVE_LINUX_IPV6_PROC |
| 84 | define this to do IPv6 interface discovery using |
| 85 | proc/net/if_inet6 ala LINUX. |
| 86 | |
| 87 | HAVE_GETOPT_LONG |
| 88 | define this if you have GNU libc or GNU getopt. |
| 89 | |
| 90 | HAVE_ARC4RANDOM |
| 91 | define this if you have arc4random() to get better security from DNS spoofs |
| 92 | by using really random ids (OpenBSD) |
| 93 | |
| 94 | HAVE_RANDOM |
| 95 | define this if you have the 4.2BSD random() function (and its |
| 96 | associated srandom() function), which is at least as good as (if not |
| 97 | better than) the rand() function. |
| 98 | |
| 99 | HAVE_DEV_RANDOM |
| 100 | define this if you have the /dev/random device, which gives truly |
| 101 | random numbers but may run out of random numbers. |
| 102 | |
| 103 | HAVE_DEV_URANDOM |
| 104 | define this if you have the /dev/urandom device, which gives |
| 105 | semi-random numbers when it runs out of truly random numbers. |
| 106 | |
| 107 | HAVE_SOCKADDR_SA_LEN |
| 108 | define this if struct sockaddr has sa_len field (*BSD) |
| 109 | |
| 110 | HAVE_PSELECT |
| 111 | If your C library implements pselect, define this. |
| 112 | |
| 113 | HAVE_PF_PACKET |
| 114 | If your OS implements packet sockets, define this. |
| 115 | |
| 116 | HAVE_BPF |
| 117 | If your OS implements Berkeley PAcket filter, define this. |
| 118 | |
| 119 | NOTES: |
| 120 | For Linux you should define |
| 121 | HAVE_LINUX_IPV6_PROC |
| 122 | HAVE_GETOPT_LONG |
| 123 | HAVE_RANDOM |
| 124 | HAVE_DEV_RANDOM |
| 125 | HAVE_DEV_URANDOM |
| 126 | HAVE_PF_PACKET |
| 127 | you should NOT define |
| 128 | HAVE_ARC4RANDOM |
| 129 | HAVE_SOCKADDR_SA_LEN |
| 130 | |
| 131 | For *BSD systems you should define |
| 132 | HAVE_SOCKADDR_SA_LEN |
| 133 | HAVE_RANDOM |
| 134 | HAVE_BPF |
| 135 | you should NOT define |
| 136 | HAVE_LINUX_IPV6_PROC |
| 137 | and you MAY define |
| 138 | HAVE_ARC4RANDOM - OpenBSD and FreeBSD |
| 139 | HAVE_DEV_URANDOM - OpenBSD and FreeBSD |
| 140 | HAVE_DEV_RANDOM - FreeBSD (OpenBSD with hardware random number generator) |
| 141 | HAVE_GETOPT_LONG - only if you link GNU getopt. |
| 142 | |
| 143 | */ |
| 144 | |
| 145 | /* Must preceed __linux__ since uClinux defines __linux__ too. */ |
| 146 | #if defined(__uClinux__) || defined(__UCLIBC__) |
| 147 | #undef HAVE_LINUX_IPV6_PROC |
| 148 | #define HAVE_GETOPT_LONG |
| 149 | #undef HAVE_ARC4RANDOM |
| 150 | #define HAVE_RANDOM |
| 151 | #define HAVE_DEV_URANDOM |
| 152 | #define HAVE_DEV_RANDOM |
| 153 | #define HAVE_PF_PACKET |
| 154 | #undef HAVE_SOCKADDR_SA_LEN |
| 155 | #undef HAVE_PSELECT |
| 156 | /* Don't fork into background on uClinux */ |
| 157 | #if defined(__uClinux__) |
| 158 | # define NO_FORK |
| 159 | #endif |
| 160 | |
| 161 | /* libc5 - must precede __linux__ too */ |
| 162 | /* Note to build a libc5 binary on a modern Debian system: |
| 163 | install the packages altgcc libc5 and libc5-altdev |
| 164 | then run "make CC=i486-linuxlibc1-gcc" */ |
| 165 | /* Note that compling dnsmasq 2.x under libc5 and kernel 2.0.x |
| 166 | is probably doomed - no packet socket for starters. */ |
| 167 | #elif defined(__linux__) && \ |
| 168 | defined(_LINUX_C_LIB_VERSION_MAJOR) && \ |
| 169 | (_LINUX_C_LIB_VERSION_MAJOR == 5 ) |
| 170 | #undef HAVE_IPV6 |
| 171 | #undef HAVE_LINUX_IPV6_PROC |
| 172 | #define HAVE_GETOPT_LONG |
| 173 | #undef HAVE_ARC4RANDOM |
| 174 | #define HAVE_RANDOM |
| 175 | #define HAVE_DEV_URANDOM |
| 176 | #define HAVE_DEV_RANDOM |
| 177 | #undef HAVE_PF_PACKET |
| 178 | #undef HAVE_SOCKADDR_SA_LEN |
| 179 | #undef HAVE_PSELECT |
| 180 | /* Fix various misfeatures of libc5 headers */ |
| 181 | #define T_SRV 33 |
| 182 | typedef unsigned long in_addr_t; |
| 183 | typedef size_t socklen_t; |
| 184 | |
| 185 | /* This is for glibc 2.x */ |
| 186 | #elif defined(__linux__) |
| 187 | #define HAVE_LINUX_IPV6_PROC |
| 188 | #define HAVE_GETOPT_LONG |
| 189 | #undef HAVE_ARC4RANDOM |
| 190 | #define HAVE_RANDOM |
| 191 | #define HAVE_DEV_URANDOM |
| 192 | #define HAVE_DEV_RANDOM |
| 193 | #undef HAVE_SOCKADDR_SA_LEN |
| 194 | #define HAVE_PSELECT |
| 195 | #define HAVE_PF_PACKET |
| 196 | /* glibc < 2.2 has broken Sockaddr_in6 so we have to use our own. */ |
| 197 | /* glibc < 2.2 doesn't define in_addr_t */ |
| 198 | #if defined(__GLIBC__) && (__GLIBC__ == 2) && \ |
| 199 | defined(__GLIBC_MINOR__) && (__GLIBC_MINOR__ < 2) |
| 200 | typedef unsigned long in_addr_t; |
| 201 | #if defined(HAVE_IPV6) |
| 202 | # define HAVE_BROKEN_SOCKADDR_IN6 |
| 203 | #endif |
| 204 | #endif |
| 205 | |
| 206 | #elif defined(__FreeBSD__) || defined(__OpenBSD__) |
| 207 | #undef HAVE_LINUX_IPV6_PROC |
| 208 | #undef HAVE_GETOPT_LONG |
| 209 | #define HAVE_ARC4RANDOM |
| 210 | #define HAVE_RANDOM |
| 211 | #define HAVE_DEV_URANDOM |
| 212 | #define HAVE_SOCKADDR_SA_LEN |
| 213 | #undef HAVE_PSELECT |
| 214 | #define HAVE_BPF |
| 215 | |
| 216 | #elif defined(__APPLE__) |
| 217 | #undef HAVE_LINUX_IPV6_PROC |
| 218 | #undef HAVE_GETOPT_LONG |
| 219 | #define HAVE_ARC4RANDOM |
| 220 | #define HAVE_RANDOM |
| 221 | #define HAVE_DEV_URANDOM |
| 222 | #define HAVE_SOCKADDR_SA_LEN |
| 223 | #undef HAVE_PSELECT |
| 224 | #define HAVE_BPF |
| 225 | /* Define before sys/socket.h is included so we get socklen_t */ |
| 226 | #define _BSD_SOCKLEN_T_ |
| 227 | /* The two below are not defined in Mac OS X arpa/nameserv.h */ |
| 228 | #define IN6ADDRSZ 16 |
| 229 | #define T_SRV 33 |
| 230 | |
| 231 | #elif defined(__NetBSD__) |
| 232 | #undef HAVE_LINUX_IPV6_PROC |
| 233 | #undef HAVE_GETOPT_LONG |
| 234 | #undef HAVE_ARC4RANDOM |
| 235 | #define HAVE_RANDOM |
| 236 | #undef HAVE_DEV_URANDOM |
| 237 | #undef HAVE_DEV_RANDOM |
| 238 | #define HAVE_SOCKADDR_SA_LEN |
| 239 | #undef HAVE_PSELECT |
| 240 | #define HAVE_BPF |
| 241 | |
| 242 | /* env "LIBS=-lsocket -lnsl" make */ |
| 243 | #elif defined(__sun) || defined(__sun__) |
| 244 | #undef HAVE_LINUX_IPV6_PROC |
| 245 | #undef HAVE_GETOPT_LONG |
| 246 | #undef HAVE_ARC4RANDOM |
| 247 | #define HAVE_RANDOM |
| 248 | #undef HAVE_DEV_URANDOM |
| 249 | #undef HAVE_DEV_RANDOM |
| 250 | #undef HAVE_SOCKADDR_SA_LEN |
| 251 | #undef HAVE_PSELECT |
| 252 | #define HAVE_BPF |
| 253 | #endif |
| 254 | |
| 255 | |
| 256 | |