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 -urN djbdns-1.05.org/dnscache.c djbdns-1.05/dnscache.c
16 --- djbdns-1.05.org/dnscache.c Sun Feb 11 22:11:45 2001
17 +++ djbdns-1.05/dnscache.c Sat Apr 28 22:12:13 2001
29 static char myipoutgoing[4];
30 -static char myipincoming[4];
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_send4(udp53,response,response_len,u[j].ip,u[j].port);
62 + socket_send4(u[j].fd,response,response_len,u[j].ip,u[j].port);
63 log_querydone(&u[j].active,response_len);
64 u[j].active = 0; --uactive;
78 - len = socket_recv4(udp53,buf,sizeof buf,x->ip,&x->port);
79 + len = socket_recv4(x->fd,buf,sizeof buf,x->ip,&x->port);
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[4]; /* send response to this address */
98 uint16 port; /* send response to this port */
115 - x->tcp = socket_accept4(tcp53,x->ip,&x->port);
116 + x->tcp = socket_accept4(x->fd,x->ip,&x->port);
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 @@ -304,19 +315,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 @@ -324,13 +340,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 @@ -372,46 +390,82 @@
176 - if (udp53io->revents)
180 - if (tcp53io->revents)
182 + for (inter = interhead; inter != 0; inter = inter->next) {
183 + if (inter->udp53io)
184 + if (inter->udp53io->revents)
185 + u_new(inter->udp53);
187 + if (inter->tcp53io)
188 + if (inter->tcp53io->revents)
189 + t_new(inter->tcp53);
194 -#define FATAL "dnscache: fatal: "
205 + char iperr[IP4_FMT];
206 + struct interf *inter;
207 + struct interf *itmp;
208 unsigned long cachesize;
212 strerr_die2x(111,FATAL,"$IP not set");
213 - if (!ip4_scan(x,myipincoming))
214 - strerr_die3x(111,FATAL,"unable to parse IP address ",x);
216 - udp53 = socket_udp();
218 - strerr_die2sys(111,FATAL,"unable to create UDP socket: ");
219 - if (socket_bind4_reuse(udp53,myipincoming,53) == -1)
220 - strerr_die2sys(111,FATAL,"unable to bind UDP socket: ");
222 - tcp53 = socket_tcp();
224 - strerr_die2sys(111,FATAL,"unable to create TCP socket: ");
225 - if (socket_bind4_reuse(tcp53,myipincoming,53) == -1)
226 - strerr_die2sys(111,FATAL,"unable to bind TCP socket: ");
228 + numio = pos = oldpos = 0;
230 + while (pos < len) {
231 + if (pos) oldpos = pos + 1;
232 + pos = oldpos + str_chr(x + oldpos,'/');
234 + if (!str_len(x + oldpos)) continue;
236 + if (!ip4_scan(x + oldpos,iptmp))
237 + strerr_die3x(111,FATAL,"unable to parse IP address ",x + oldpos);
239 + inter = (struct interf *) alloc(sizeof(struct interf));
241 + if (interhead == 0) interhead = inter;
242 + else if (interhead->next == 0) interhead->next = inter;
244 + for (itmp = interhead; itmp->next != 0; itmp = itmp->next);
245 + itmp->next = inter;
250 + inter->udp53 = socket_udp();
251 + if (inter->udp53 == -1)
252 + strerr_die4sys(111,FATAL,"unable to create UDP socket for IP address ",x + oldpos,": ");
253 + if (socket_bind4_reuse(inter->udp53,iptmp,53) == -1)
254 + strerr_die4sys(111,FATAL,"unable to bind UDP socket for IP address ",x + oldpos,": ");
256 + inter->tcp53 = socket_tcp();
257 + if (inter->tcp53 == -1)
258 + strerr_die4sys(111,FATAL,"unable to create TCP socket for IP address ",x + oldpos,": ");
259 + if (socket_bind4_reuse(inter->tcp53,iptmp,53) == -1)
260 + strerr_die4sys(111,FATAL,"unable to bind TCP socket for IP address ",x + oldpos,": ");
266 + if (interhead == 0)
267 + strerr_die2x(111,FATAL,"no interfaces to listen on");
271 - socket_tryreservein(udp53,131072);
272 + for (inter = interhead; inter != 0; inter = inter->next)
273 + socket_tryreservein(inter->udp53,131072);
275 byte_zero(seed,sizeof seed);
276 read(0,seed,sizeof seed);
279 strerr_die2sys(111,FATAL,"unable to read servers: ");
281 - if (socket_listen(tcp53,20) == -1)
282 - strerr_die2sys(111,FATAL,"unable to listen on TCP socket: ");
283 + for (inter = interhead; inter != 0; inter = inter->next)
284 + if (socket_listen(inter->tcp53,20) == -1) {
285 + iperr[ip4_fmt(iperr,inter->ip)] = 0;
286 + strerr_die4sys(111,FATAL,"unable to listen on TCP socket for IP ",iperr,": ");
291 diff -urN djbdns-1.05.org/log.c djbdns-1.05/log.c
292 --- djbdns-1.05.org/log.c Sun Feb 11 22:11:45 2001
293 +++ djbdns-1.05/log.c Sat Apr 28 22:12:13 2001
298 +void log_listen(const char addr[4])
300 + string("listening on ");
305 void log_query(uint64 *qnum,const char client[4],unsigned int port,const char id[2],const char *q,const char qtype[2])
307 string("query "); number(*qnum); space();
308 diff -urN djbdns-1.05.org/log.h djbdns-1.05/log.h
309 --- djbdns-1.05.org/log.h Sun Feb 11 22:11:45 2001
310 +++ djbdns-1.05/log.h Sat Apr 28 22:12:13 2001
314 extern void log_startup(void);
315 +extern void log_listen(const char *);
317 extern void log_query(uint64 *,const char *,unsigned int,const char *,const char *,const char *);
318 extern void log_querydrop(uint64 *);