1 diff -urN djbdns-1.05.org/MULTIPLEIP djbdns-1.05/MULTIPLEIP
2 --- djbdns-1.05.org/MULTIPLEIP Thu Jan 1 01:00:00 1970
3 +++ djbdns-1.05/MULTIPLEIP Sat Apr 28 22:15:42 2001
6 +When applied, dnscache will accept a /-delimited list of IP address in $IP
7 +and bind to each in turn. This allows one to have dnscache listen on, say,
8 +external IP 1.2.3.4 which only client group A can reach, and, say,
9 +internal IP 4.3.2.1 which only client group B can reach. Assuming 1.2.3.4
10 +and 4.3.2.1 are on the same machine, instead of running two independent
11 +dnscache instances on 1.2.3.4 and 4.3.2.1, one instance can bind to both
12 +IP's and serve queries from the shared cache. Simply put 1.2.3.4/4.3.2.1 in env/IP.
14 +http://danp.net/djbdns/patches.html
15 diff -r -u djbdns+ipv6/dnscache.c djbdns-1.05/dnscache.c
16 --- djbdns+ipv6/dnscache.c 2004-09-29 21:17:03.000000000 +0200
17 +++ djbdns-1.05/dnscache.c 2004-09-29 22:02:38.018542064 +0200
29 static char myipoutgoing[16];
30 -static char myipincoming[16];
31 static char buf[1024];
32 uint64 numqueries = 0;
38 + iopause_fd *udp53io;
39 + iopause_fd *tcp53io;
41 + struct interf *next;
45 +struct interf *interhead = 0;
48 static struct udpclient {
51 uint64 active; /* query number, if active; otherwise 0 */
58 if (!u[j].active) return;
60 if (response_len > 512) response_tc();
61 - socket_send6(udp53,response,response_len,u[j].ip,u[j].port,u[j].scope_id);
62 + socket_send6(u[j].fd,response,response_len,u[j].ip,u[j].port,u[j].scope_id);
63 log_querydone(&u[j].active,response_len);
64 u[j].active = 0; --uactive;
78 - len = socket_recv6(udp53,buf,sizeof buf,x->ip,&x->port,&x->scope_id);
79 + len = socket_recv6(x->fd,buf,sizeof buf,x->ip,&x->port,&x->scope_id);
80 if (len == -1) return;
81 if (len >= sizeof buf) return;
82 if (x->port < 1024) if (x->port != 53) return;
94 uint64 active; /* query number or 1, if active; otherwise 0 */
97 char ip[16]; /* send response to this address */
98 uint16 port; /* send response to this port */
115 - x->tcp = socket_accept6(tcp53,x->ip,&x->port,&x->scope_id);
116 + x->tcp = socket_accept6(x->fd,x->ip,&x->port,&x->scope_id);
117 if (x->tcp == -1) return;
118 if (x->port < 1024) if (x->port != 53) { close(x->tcp); return; }
119 if (!okclient(x->ip)) { close(x->tcp); return; }
120 @@ -310,19 +321,24 @@
121 log_tcpopen(x->ip,x->port);
124 +#define FATAL "dnscache: fatal: "
126 -iopause_fd io[3 + MAXUDP + MAXTCP];
127 -iopause_fd *udp53io;
128 -iopause_fd *tcp53io;
132 static void doit(void)
135 struct taia deadline;
137 + struct interf *inter;
141 + io = (iopause_fd *) alloc((numio + 1 + MAXUDP + MAXTCP) * sizeof(iopause_fd));
143 + strerr_die2sys(111,FATAL,"unable to alloc io: ");
147 taia_uint(&deadline,120);
148 @@ -330,13 +346,15 @@
152 - udp53io = io + iolen++;
153 - udp53io->fd = udp53;
154 - udp53io->events = IOPAUSE_READ;
156 - tcp53io = io + iolen++;
157 - tcp53io->fd = tcp53;
158 - tcp53io->events = IOPAUSE_READ;
159 + for (inter = interhead; inter != 0; inter = inter->next) {
160 + inter->udp53io = io + iolen++;
161 + inter->udp53io->fd = inter->udp53;
162 + inter->udp53io->events = IOPAUSE_READ;
164 + inter->tcp53io = io + iolen++;
165 + inter->tcp53io->fd = inter->tcp53;
166 + inter->tcp53io->events = IOPAUSE_READ;
169 for (j = 0;j < MAXUDP;++j)
171 @@ -378,23 +396,30 @@
176 - if (udp53io->revents)
180 - if (tcp53io->revents)
183 + for (inter = interhead; inter != 0; inter = inter->next) {
184 + if (inter->udp53io)
185 + if (inter->udp53io->revents)
186 + u_new(inter->udp53);
188 + if (inter->tcp53io)
189 + if (inter->tcp53io->revents)
190 + t_new(inter->tcp53);
195 -#define FATAL "dnscache: fatal: "
206 + char iperr[IP4_FMT];
207 + struct interf *inter;
208 + struct interf *itmp;
209 unsigned int i, j, k;
210 unsigned long cachesize;
211 static stralloc sa = {0};
212 @@ -405,31 +430,50 @@
215 strerr_die2x(111,FATAL,"$IP not set");
216 - if (!ip6_scan(x,myipincoming))
217 - strerr_die3x(111,FATAL,"unable to parse IP address ",x);
219 + numio = pos = oldpos = 0;
220 + while (pos < len) {
221 + if (pos) oldpos = pos + 1;
222 + pos = oldpos + str_chr(x + oldpos,'/');
224 + if (!str_len(x + oldpos)) continue;
226 + if (!ip6_scan(x + oldpos,iptmp))
227 + strerr_die3x(111,FATAL,"unable to parse IP address ",x + oldpos);
229 + inter = (struct interf *) alloc(sizeof(struct interf));
231 + if (interhead == 0) interhead = inter;
232 + else if (interhead->next == 0) interhead->next = inter;
234 + for (itmp = interhead; itmp->next != 0; itmp = itmp->next);
235 + itmp->next = inter;
239 - /* if if IP is a mapped-IPv4 address, disable IPv6 functionality */
240 - /* this is actually a bad idea */
241 - if (ip6_isv4mapped(myipincoming))
245 - udp53 = socket_udp6();
247 - strerr_die2sys(111,FATAL,"unable to create UDP socket: ");
248 - if (socket_bind6_reuse(udp53,myipincoming,53,interface) == -1)
249 - strerr_die2sys(111,FATAL,"unable to bind UDP socket: ");
251 - tcp53 = socket_tcp6();
253 - strerr_die2sys(111,FATAL,"unable to create TCP socket: ");
254 - if (socket_bind6_reuse(tcp53,myipincoming,53,interface) == -1)
255 - strerr_die2sys(111,FATAL,"unable to bind TCP socket: ");
257 + inter->udp53 = socket_udp6();
258 + if (inter->udp53 == -1)
259 + strerr_die4sys(111,FATAL,"unable to create UDP socket for IP address ",x + oldpos,": ");
260 + if (socket_bind6_reuse(inter->udp53,iptmp,53,interface) == -1)
261 + strerr_die4sys(111,FATAL,"unable to bind UDP socket for IP address ",x + oldpos,": ");
263 + inter->tcp53 = socket_tcp6();
264 + if (inter->tcp53 == -1)
265 + strerr_die4sys(111,FATAL,"unable to create TCP socket for IP address ",x + oldpos,": ");
266 + if (socket_bind6_reuse(inter->tcp53,iptmp,53,interface) == -1)
267 + strerr_die4sys(111,FATAL,"unable to bind TCP socket for IP address ",x + oldpos,": ");
273 + if (interhead == 0)
274 + strerr_die2x(111,FATAL,"no interfaces to listen on");
278 - socket_tryreservein(udp53,131072);
279 + for (inter = interhead; inter != 0; inter = inter->next)
280 + socket_tryreservein(inter->udp53,131072);
282 byte_zero(seed,sizeof seed);
283 read(0,seed,sizeof seed);
286 strerr_die2sys(111,FATAL,"unable to read servers: ");
288 - if (socket_listen(tcp53,20) == -1)
289 - strerr_die2sys(111,FATAL,"unable to listen on TCP socket: ");
290 + for (inter = interhead; inter != 0; inter = inter->next)
291 + if (socket_listen(inter->tcp53,20) == -1) {
292 + iperr[ip4_fmt(iperr,inter->ip)] = 0;
293 + strerr_die4sys(111,FATAL,"unable to listen on TCP socket for IP ",iperr,": ");
298 diff -r -u djbdns+ipv6/log.c djbdns-1.05/log.c
299 --- djbdns+ipv6/log.c 2004-09-29 21:17:03.000000000 +0200
300 +++ djbdns-1.05/log.c 2004-09-29 21:47:02.523655344 +0200
306 +void log_listen(const char addr[16])
308 + string("listening on ");
312 diff -r -u djbdns+ipv6/log.h djbdns-1.05/log.h
313 --- djbdns+ipv6/log.h 2001-02-11 22:11:45.000000000 +0100
314 +++ djbdns-1.05/log.h 2004-09-29 21:18:46.114548728 +0200
318 extern void log_startup(void);
319 +extern void log_listen(const char *);
321 extern void log_query(uint64 *,const char *,unsigned int,const char *,const char *,const char *);
322 extern void log_querydrop(uint64 *);