]>
Commit | Line | Data |
---|---|---|
a8288d73 | 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 | |
4 | @@ -0,0 +1,10 @@ | |
5 | + | |
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. | |
13 | + | |
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 | |
18 | @@ -6,6 +6,7 @@ | |
19 | #include "error.h" | |
20 | #include "ip4.h" | |
21 | #include "ip6.h" | |
22 | +#include "str.h" | |
23 | #include "uint16.h" | |
24 | #include "uint64.h" | |
25 | #include "socket.h" | |
26 | @@ -52,12 +53,20 @@ | |
27 | ||
28 | ||
29 | static char myipoutgoing[16]; | |
30 | -static char myipincoming[16]; | |
31 | static char buf[1024]; | |
32 | uint64 numqueries = 0; | |
33 | ||
34 | +struct interf { | |
35 | + char ip[16]; | |
36 | + int udp53; | |
37 | + int tcp53; | |
38 | + iopause_fd *udp53io; | |
39 | + iopause_fd *tcp53io; | |
40 | + | |
41 | + struct interf *next; | |
42 | +}; | |
43 | ||
44 | -static int udp53; | |
45 | +struct interf *interhead = 0; | |
46 | ||
47 | #define MAXUDP 200 | |
48 | static struct udpclient { | |
49 | @@ -65,6 +74,7 @@ | |
50 | struct taia start; | |
51 | uint64 active; /* query number, if active; otherwise 0 */ | |
52 | iopause_fd *io; | |
53 | + int fd; | |
54 | char ip[16]; | |
55 | uint16 port; | |
56 | char id[2]; | |
57 | @@ -84,12 +94,12 @@ | |
58 | if (!u[j].active) return; | |
59 | response_id(u[j].id); | |
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; | |
65 | } | |
66 | ||
67 | -void u_new(void) | |
68 | +void u_new(int fd) | |
69 | { | |
70 | int j; | |
71 | int i; | |
72 | @@ -114,8 +124,9 @@ | |
73 | ||
74 | x = u + j; | |
75 | taia_now(&x->start); | |
76 | + x->fd=fd; | |
77 | ||
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; | |
83 | @@ -134,8 +145,6 @@ | |
84 | } | |
85 | } | |
86 | ||
87 | -static int tcp53; | |
88 | - | |
89 | #define MAXTCP 20 | |
90 | struct tcpclient { | |
91 | struct query q; | |
92 | @@ -143,6 +152,7 @@ | |
93 | struct taia timeout; | |
94 | uint64 active; /* query number or 1, if active; otherwise 0 */ | |
95 | iopause_fd *io; | |
96 | + int fd; | |
97 | char ip[16]; /* send response to this address */ | |
98 | uint16 port; /* send response to this port */ | |
99 | char id[2]; | |
100 | @@ -272,7 +282,7 @@ | |
101 | x->state = 0; | |
102 | } | |
103 | ||
104 | -void t_new(void) | |
105 | +void t_new(int fd) | |
106 | { | |
107 | int i; | |
108 | int j; | |
109 | @@ -296,8 +306,9 @@ | |
110 | ||
111 | x = t + j; | |
112 | taia_now(&x->start); | |
113 | + x->fd=fd; | |
114 | ||
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); | |
122 | } | |
123 | ||
124 | +#define FATAL "dnscache: fatal: " | |
125 | ||
126 | -iopause_fd io[3 + MAXUDP + MAXTCP]; | |
127 | -iopause_fd *udp53io; | |
128 | -iopause_fd *tcp53io; | |
129 | +iopause_fd *io = 0; | |
130 | +int numio; | |
131 | ||
132 | static void doit(void) | |
133 | { | |
134 | int j; | |
135 | struct taia deadline; | |
136 | struct taia stamp; | |
137 | + struct interf *inter; | |
138 | int iolen; | |
139 | int r; | |
140 | ||
141 | + io = (iopause_fd *) alloc((numio + 1 + MAXUDP + MAXTCP) * sizeof(iopause_fd)); | |
142 | + if (!io) | |
143 | + strerr_die2sys(111,FATAL,"unable to alloc io: "); | |
144 | + | |
145 | for (;;) { | |
146 | taia_now(&stamp); | |
147 | taia_uint(&deadline,120); | |
148 | @@ -330,13 +346,15 @@ | |
149 | ||
150 | iolen = 0; | |
151 | ||
152 | - udp53io = io + iolen++; | |
153 | - udp53io->fd = udp53; | |
154 | - udp53io->events = IOPAUSE_READ; | |
155 | - | |
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; | |
163 | + | |
164 | + inter->tcp53io = io + iolen++; | |
165 | + inter->tcp53io->fd = inter->tcp53; | |
166 | + inter->tcp53io->events = IOPAUSE_READ; | |
167 | + } | |
168 | ||
169 | for (j = 0;j < MAXUDP;++j) | |
170 | if (u[j].active) { | |
171 | @@ -378,23 +396,30 @@ | |
172 | t_rw(j); | |
173 | } | |
174 | ||
175 | - if (udp53io) | |
176 | - if (udp53io->revents) | |
177 | - u_new(); | |
178 | - | |
179 | - if (tcp53io) | |
180 | - if (tcp53io->revents) | |
181 | - t_new(); | |
182 | - } | |
183 | + for (inter = interhead; inter != 0; inter = inter->next) { | |
184 | + if (inter->udp53io) | |
185 | + if (inter->udp53io->revents) | |
186 | + u_new(inter->udp53); | |
187 | + | |
188 | + if (inter->tcp53io) | |
189 | + if (inter->tcp53io->revents) | |
190 | + t_new(inter->tcp53); | |
191 | + } | |
192 | + } | |
193 | } | |
194 | ||
195 | -#define FATAL "dnscache: fatal: " | |
196 | - | |
197 | char seed[128]; | |
198 | ||
199 | int main() | |
200 | { | |
201 | char *x; | |
202 | + int len; | |
203 | + int pos; | |
204 | + int oldpos; | |
205 | + char iptmp[4]; | |
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 @@ | |
213 | x = env_get("IP"); | |
214 | if (!x) | |
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); | |
218 | + len = str_len(x); | |
219 | + numio = pos = oldpos = 0; | |
220 | + while (pos < len) { | |
221 | + if (pos) oldpos = pos + 1; | |
222 | + pos = oldpos + str_chr(x + oldpos,'/'); | |
223 | + x[pos] = 0; | |
224 | + if (!str_len(x + oldpos)) continue; | |
225 | + | |
226 | + if (!ip6_scan(x + oldpos,iptmp)) | |
227 | + strerr_die3x(111,FATAL,"unable to parse IP address ",x + oldpos); | |
228 | + | |
229 | + inter = (struct interf *) alloc(sizeof(struct interf)); | |
230 | + | |
231 | + if (interhead == 0) interhead = inter; | |
232 | + else if (interhead->next == 0) interhead->next = inter; | |
233 | + else { | |
234 | + for (itmp = interhead; itmp->next != 0; itmp = itmp->next); | |
235 | + itmp->next = inter; | |
236 | + } | |
237 | ||
238 | -#if 0 | |
239 | - /* if if IP is a mapped-IPv4 address, disable IPv6 functionality */ | |
240 | - /* this is actually a bad idea */ | |
241 | - if (ip6_isv4mapped(myipincoming)) | |
242 | - noipv6 = 1; | |
243 | -#endif | |
244 | - | |
245 | - udp53 = socket_udp6(); | |
246 | - if (udp53 == -1) | |
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: "); | |
250 | - | |
251 | - tcp53 = socket_tcp6(); | |
252 | - if (tcp53 == -1) | |
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: "); | |
256 | + inter->next = 0; | |
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,": "); | |
262 | + | |
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,": "); | |
268 | + | |
269 | + numio++; | |
270 | + log_listen(iptmp); | |
271 | + } | |
272 | + | |
273 | + if (interhead == 0) | |
274 | + strerr_die2x(111,FATAL,"no interfaces to listen on"); | |
275 | ||
276 | droproot(FATAL); | |
277 | ||
278 | - socket_tryreservein(udp53,131072); | |
279 | + for (inter = interhead; inter != 0; inter = inter->next) | |
280 | + socket_tryreservein(inter->udp53,131072); | |
281 | ||
282 | byte_zero(seed,sizeof seed); | |
283 | read(0,seed,sizeof seed); | |
284 | @@ -471,8 +515,11 @@ | |
285 | if (!roots_init()) | |
286 | strerr_die2sys(111,FATAL,"unable to read servers: "); | |
287 | ||
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,": "); | |
294 | + } | |
295 | ||
296 | log_startup(); | |
297 | doit(); | |
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 | |
301 | @@ -285,3 +285,10 @@ | |
302 | number(tactive); | |
303 | line(); | |
304 | } | |
305 | + | |
306 | +void log_listen(const char addr[16]) | |
307 | +{ | |
308 | + string("listening on "); | |
309 | + ip(addr); | |
310 | + line(); | |
311 | +} | |
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 | |
315 | @@ -4,6 +4,7 @@ | |
316 | #include "uint64.h" | |
317 | ||
318 | extern void log_startup(void); | |
319 | +extern void log_listen(const char *); | |
320 | ||
321 | extern void log_query(uint64 *,const char *,unsigned int,const char *,const char *,const char *); | |
322 | extern void log_querydrop(uint64 *); |