1 --- djbdns-1.05.orig/dnscache.c.orig Tue Feb 27 00:32:52 2001
2 +++ djbdns-1.05/dnscache.c Tue Feb 27 00:30:58 2001
14 static char myipoutgoing[4];
15 -static char myipincoming[4];
16 static char buf[1024];
17 uint64 numqueries = 0;
23 + iopause_fd *udp53io;
24 + iopause_fd *tcp53io;
26 + struct interf *next;
30 +struct interf *interhead = 0;
33 static struct udpclient {
36 uint64 active; /* query number, if active; otherwise 0 */
43 if (!u[j].active) return;
45 if (response_len > 512) response_tc();
46 - socket_send4(udp53,response,response_len,u[j].ip,u[j].port);
47 + socket_send4(u[j].fd,response,response_len,u[j].ip,u[j].port);
48 log_querydone(&u[j].active,response_len);
49 u[j].active = 0; --uactive;
63 - len = socket_recv4(udp53,buf,sizeof buf,x->ip,&x->port);
64 + len = socket_recv4(x->fd,buf,sizeof buf,x->ip,&x->port);
65 if (len == -1) return;
66 if (len >= sizeof buf) return;
67 if (x->port < 1024) if (x->port != 53) return;
79 uint64 active; /* query number or 1, if active; otherwise 0 */
82 char ip[4]; /* send response to this address */
83 uint16 port; /* send response to this port */
100 - x->tcp = socket_accept4(tcp53,x->ip,&x->port);
101 + x->tcp = socket_accept4(x->fd,x->ip,&x->port);
102 if (x->tcp == -1) return;
103 if (x->port < 1024) if (x->port != 53) { close(x->tcp); return; }
104 if (!okclient(x->ip)) { close(x->tcp); return; }
105 @@ -304,19 +315,24 @@
106 log_tcpopen(x->ip,x->port);
109 +#define FATAL "dnscache: fatal: "
111 -iopause_fd io[3 + MAXUDP + MAXTCP];
112 -iopause_fd *udp53io;
113 -iopause_fd *tcp53io;
117 static void doit(void)
120 struct taia deadline;
122 + struct interf *inter;
126 + io = (iopause_fd *) alloc((numio + 1 + MAXUDP + MAXTCP) * sizeof(iopause_fd));
128 + strerr_die2sys(111,FATAL,"unable to alloc io: ");
132 taia_uint(&deadline,120);
133 @@ -324,13 +340,15 @@
137 - udp53io = io + iolen++;
138 - udp53io->fd = udp53;
139 - udp53io->events = IOPAUSE_READ;
141 - tcp53io = io + iolen++;
142 - tcp53io->fd = tcp53;
143 - tcp53io->events = IOPAUSE_READ;
144 + for (inter = interhead; inter != 0; inter = inter->next) {
145 + inter->udp53io = io + iolen++;
146 + inter->udp53io->fd = inter->udp53;
147 + inter->udp53io->events = IOPAUSE_READ;
149 + inter->tcp53io = io + iolen++;
150 + inter->tcp53io->fd = inter->tcp53;
151 + inter->tcp53io->events = IOPAUSE_READ;
154 for (j = 0;j < MAXUDP;++j)
156 @@ -372,46 +390,82 @@
161 - if (udp53io->revents)
165 - if (tcp53io->revents)
167 + for (inter = interhead; inter != 0; inter = inter->next) {
168 + if (inter->udp53io)
169 + if (inter->udp53io->revents)
170 + u_new(inter->udp53);
172 + if (inter->tcp53io)
173 + if (inter->tcp53io->revents)
174 + t_new(inter->tcp53);
179 -#define FATAL "dnscache: fatal: "
190 + char iperr[IP4_FMT];
191 + struct interf *inter;
192 + struct interf *itmp;
193 unsigned long cachesize;
197 strerr_die2x(111,FATAL,"$IP not set");
198 - if (!ip4_scan(x,myipincoming))
199 - strerr_die3x(111,FATAL,"unable to parse IP address ",x);
201 - udp53 = socket_udp();
203 - strerr_die2sys(111,FATAL,"unable to create UDP socket: ");
204 - if (socket_bind4_reuse(udp53,myipincoming,53) == -1)
205 - strerr_die2sys(111,FATAL,"unable to bind UDP socket: ");
207 - tcp53 = socket_tcp();
209 - strerr_die2sys(111,FATAL,"unable to create TCP socket: ");
210 - if (socket_bind4_reuse(tcp53,myipincoming,53) == -1)
211 - strerr_die2sys(111,FATAL,"unable to bind TCP socket: ");
213 + numio = pos = oldpos = 0;
215 + while (pos < len) {
216 + if (pos) oldpos = pos + 1;
217 + pos = oldpos + str_chr(x + oldpos,'/');
219 + if (!str_len(x + oldpos)) continue;
221 + if (!ip4_scan(x + oldpos,iptmp))
222 + strerr_die3x(111,FATAL,"unable to parse IP address ",x + oldpos);
224 + inter = (struct interf *) alloc(sizeof(struct interf));
226 + if (interhead == 0) interhead = inter;
227 + else if (interhead->next == 0) interhead->next = inter;
229 + for (itmp = interhead; itmp->next != 0; itmp = itmp->next);
230 + itmp->next = inter;
235 + inter->udp53 = socket_udp();
236 + if (inter->udp53 == -1)
237 + strerr_die4sys(111,FATAL,"unable to create UDP socket for IP address ",x + oldpos,": ");
238 + if (socket_bind4_reuse(inter->udp53,iptmp,53) == -1)
239 + strerr_die4sys(111,FATAL,"unable to bind UDP socket for IP address ",x + oldpos,": ");
241 + inter->tcp53 = socket_tcp();
242 + if (inter->tcp53 == -1)
243 + strerr_die4sys(111,FATAL,"unable to create TCP socket for IP address ",x + oldpos,": ");
244 + if (socket_bind4_reuse(inter->tcp53,iptmp,53) == -1)
245 + strerr_die4sys(111,FATAL,"unable to bind TCP socket for IP address ",x + oldpos,": ");
251 + if (interhead == 0)
252 + strerr_die2x(111,FATAL,"no interfaces to listen on");
256 - socket_tryreservein(udp53,131072);
257 + for (inter = interhead; inter != 0; inter = inter->next)
258 + socket_tryreservein(inter->udp53,131072);
260 byte_zero(seed,sizeof seed);
261 read(0,seed,sizeof seed);
264 strerr_die2sys(111,FATAL,"unable to read servers: ");
266 - if (socket_listen(tcp53,20) == -1)
267 - strerr_die2sys(111,FATAL,"unable to listen on TCP socket: ");
268 + for (inter = interhead; inter != 0; inter = inter->next)
269 + if (socket_listen(inter->tcp53,20) == -1) {
270 + iperr[ip4_fmt(iperr,inter->ip)] = 0;
271 + strerr_die4sys(111,FATAL,"unable to listen on TCP socket for IP ",iperr,": ");
276 --- djbdns-1.05.orig/log.c.orig Tue Feb 27 00:33:02 2001
277 +++ djbdns-1.05/log.c Tue Feb 27 00:30:58 2001
282 +void log_listen(const char addr[4])
284 + string("listening on ");
289 void log_query(uint64 *qnum,const char client[4],unsigned int port,const char id[2],const char *q,const char qtype[2])
291 string("query "); number(*qnum); space();
292 --- djbdns-1.05.orig/log.h.orig Tue Feb 27 00:33:09 2001
293 +++ djbdns-1.05/log.h Tue Feb 27 00:30:58 2001
297 extern void log_startup(void);
298 +extern void log_listen(const char *);
300 extern void log_query(uint64 *,const char *,unsigned int,const char *,const char *,const char *);
301 extern void log_querydrop(uint64 *);