]> git.pld-linux.org Git - packages/squid.git/blob - squid-2.5.STABLE4-connect_cleanup.patch
- new-style bcond, pl fixes
[packages/squid.git] / squid-2.5.STABLE4-connect_cleanup.patch
1 Index: squid/src/cf.data.pre
2 diff -c squid/src/cf.data.pre:1.245.2.54 squid/src/cf.data.pre:1.245.2.55
3 *** squid/src/cf.data.pre:1.245.2.54    Sat Nov 29 11:52:58 2003
4 --- squid/src/cf.data.pre       Sat Dec  6 10:19:36 2003
5 ***************
6 *** 1106,1112 ****
7   
8   NAME: dns_timeout
9   TYPE: time_t
10 ! DEFAULT: 5 minutes
11   LOC: Config.Timeout.idns_query
12   IFDEF: !USE_DNSSERVERS
13   DOC_START
14 --- 1106,1112 ----
15   
16   NAME: dns_timeout
17   TYPE: time_t
18 ! DEFAULT: 2 minutes
19   LOC: Config.Timeout.idns_query
20   IFDEF: !USE_DNSSERVERS
21   DOC_START
22 ***************
23 *** 1734,1741 ****
24   DEFAULT: 6 hours
25   DOC_START
26         Upper limit on how long Squid will cache positive DNS responses.
27 !       Default is 6 hours (360 minutes).  If you want to minimize the
28 !       use of Squid's ipcache, set this to 1, not 0.
29   DOC_END
30   
31   
32 --- 1734,1741 ----
33   DEFAULT: 6 hours
34   DOC_START
35         Upper limit on how long Squid will cache positive DNS responses.
36 !       Default is 6 hours (360 minutes). This directive must be set
37 !       larger than negative_dns_ttl.
38   DOC_END
39   
40   
41 ***************
42 *** 1743,1751 ****
43   COMMENT: time-units
44   TYPE: time_t
45   LOC: Config.negativeDnsTtl
46 ! DEFAULT: 5 minutes
47   DOC_START
48         Time-to-Live (TTL) for negative caching of failed DNS lookups.
49   DOC_END
50   
51   NAME: range_offset_limit
52 --- 1743,1754 ----
53   COMMENT: time-units
54   TYPE: time_t
55   LOC: Config.negativeDnsTtl
56 ! DEFAULT: 1 minute
57   DOC_START
58         Time-to-Live (TTL) for negative caching of failed DNS lookups.
59 +       This also makes sets the lower cache limit on positive lookups.
60 +       Minimum value is 1 second, and it is not recommendable to go
61 +       much below 10 seconds.
62   DOC_END
63   
64   NAME: range_offset_limit
65 ***************
66 *** 1776,1792 ****
67    -----------------------------------------------------------------------------
68   COMMENT_END
69   
70   NAME: connect_timeout
71   COMMENT: time-units
72   TYPE: time_t
73   LOC: Config.Timeout.connect
74 ! DEFAULT: 2 minutes
75   DOC_START
76 !       Some systems (notably Linux) can not be relied upon to properly
77 !       time out connect(2) requests.  Therefore the Squid process
78 !       enforces its own timeout on server connections.  This parameter
79 !       specifies how long to wait for the connect to complete.  The
80 !       default is two minutes (120 seconds).
81   DOC_END
82   
83   NAME: peer_connect_timeout
84 --- 1779,1803 ----
85    -----------------------------------------------------------------------------
86   COMMENT_END
87   
88 + NAME: forward_timeout
89 + COMMENT: time-units
90 + TYPE: time_t
91 + LOC: Config.Timeout.forward
92 + DEFAULT: 4 minutes
93 + DOC_START
94 +       This parameter specifies how long Squid should at most attempt in
95 +       finding a forwarding path for the request before giving up.
96 + DOC_END
97
98   NAME: connect_timeout
99   COMMENT: time-units
100   TYPE: time_t
101   LOC: Config.Timeout.connect
102 ! DEFAULT: 1 minute
103   DOC_START
104 !       This parameter specifies how long to wait for the TCP connect to
105 !       the requested server or peer to complete before Squid should
106 !       attempt to find another path where to forward the request.
107   DOC_END
108   
109   NAME: peer_connect_timeout
110 Index: squid/src/cache_cf.c
111 diff -c squid/src/cache_cf.c:1.396.2.15 squid/src/cache_cf.c:1.396.2.16
112 *** squid/src/cache_cf.c:1.396.2.15     Thu Nov  6 09:50:37 2003
113 --- squid/src/cache_cf.c        Sat Dec  6 10:19:36 2003
114 ***************
115 *** 431,436 ****
116 --- 431,444 ----
117             debug(22, 0) ("WARNING: 'maxconn' ACL (%s) won't work with client_db disabled\n", a->name);
118         }
119       }
120 +     if (Config.negativeDnsTtl <= 0) {
121 +       debug(22, 0) ("WARNING: resetting negative_dns_ttl to 1 second\n");
122 +       Config.negativeDnsTtl = 1;
123 +     }
124 +     if (Config.positiveDnsTtl < Config.negativeDnsTtl) {
125 +       debug(22, 0) ("NOTICE: positive_dns_ttl must be larger than negative_dns_ttl. Resetting negative_dns_ttl to match\n");
126 +       Config.positiveDnsTtl = Config.negativeDnsTtl;
127 +     }
128   }
129   
130   /* Parse a time specification from the config file.  Store the
131 Index: squid/src/dns.c
132 diff -c squid/src/dns.c:1.86.2.1 squid/src/dns.c:1.86.2.2
133 *** squid/src/dns.c:1.86.2.1    Tue Nov 12 00:12:22 2002
134 --- squid/src/dns.c     Sat Dec  6 10:19:37 2003
135 ***************
136 *** 97,103 ****
137         if (squid_curtime - first_warn > 3 * 60)
138             fatal("DNS servers not responding for 3 minutes");
139         debug(34, 1) ("dnsSubmit: queue overload, rejecting %s\n", lookup);
140 !       callback(data, "$fail Temporary network problem, please retry later");
141         return;
142       }
143       first_warn = 0;
144 --- 97,103 ----
145         if (squid_curtime - first_warn > 3 * 60)
146             fatal("DNS servers not responding for 3 minutes");
147         debug(34, 1) ("dnsSubmit: queue overload, rejecting %s\n", lookup);
148 !       callback(data, (char *) "$fail Temporary network problem, please retry later");
149         return;
150       }
151       first_warn = 0;
152 ***************
153 *** 112,118 ****
154   snmp_netDnsFn(variable_list * Var, snint * ErrP)
155   {
156       variable_list *Answer = NULL;
157 !     debug(49, 5) ("snmp_netDnsFn: Processing request:\n", Var->name[LEN_SQ_NET + 1]);
158       snmpDebugOid(5, Var->name, Var->name_length);
159       *ErrP = SNMP_ERR_NOERROR;
160       switch (Var->name[LEN_SQ_NET + 1]) {
161 --- 112,118 ----
162   snmp_netDnsFn(variable_list * Var, snint * ErrP)
163   {
164       variable_list *Answer = NULL;
165 !     debug(49, 5) ("snmp_netDnsFn: Processing request: %d\n", Var->name[LEN_SQ_NET + 1]);
166       snmpDebugOid(5, Var->name, Var->name_length);
167       *ErrP = SNMP_ERR_NOERROR;
168       switch (Var->name[LEN_SQ_NET + 1]) {
169 Index: squid/src/dns_internal.c
170 diff -c squid/src/dns_internal.c:1.45.2.1 squid/src/dns_internal.c:1.45.2.2
171 *** squid/src/dns_internal.c:1.45.2.1   Tue Jun 25 05:44:35 2002
172 --- squid/src/dns_internal.c    Sat Dec  6 10:19:37 2003
173 ***************
174 *** 64,69 ****
175 --- 64,71 ----
176       IDNSCB *callback;
177       void *callback_data;
178       int attempt;
179 +     const char *error;
180 +     int rcode;
181   };
182   
183   struct _ns {
184 ***************
185 *** 463,471 ****
186       }
187       dlinkDelete(&q->lru, &lru_list);
188       idnsRcodeCount(n, q->attempt);
189       if (n < 0) {
190         debug(78, 3) ("idnsGrokReply: error %d\n", rfc1035_errno);
191 !       if (-2 == n && ++q->attempt < MAX_ATTEMPT) {
192             /*
193              * RCODE 2 is "Server failure - The name server was
194              * unable to process this query due to a problem with
195 --- 465,476 ----
196       }
197       dlinkDelete(&q->lru, &lru_list);
198       idnsRcodeCount(n, q->attempt);
199 +     q->error = NULL;
200       if (n < 0) {
201         debug(78, 3) ("idnsGrokReply: error %d\n", rfc1035_errno);
202 !       q->error = rfc1035_error_message;
203 !       q->rcode = -n;
204 !       if (q->rcode == 2 && ++q->attempt < MAX_ATTEMPT) {
205             /*
206              * RCODE 2 is "Server failure - The name server was
207              * unable to process this query due to a problem with
208 ***************
209 *** 481,487 ****
210       valid = cbdataValid(q->callback_data);
211       cbdataUnlock(q->callback_data);
212       if (valid)
213 !       q->callback(q->callback_data, answers, n);
214       rfc1035RRDestroy(answers, n);
215       memFree(q, MEM_IDNS_QUERY);
216   }
217 --- 486,492 ----
218       valid = cbdataValid(q->callback_data);
219       cbdataUnlock(q->callback_data);
220       if (valid)
221 !       q->callback(q->callback_data, answers, n, q->error);
222       rfc1035RRDestroy(answers, n);
223       memFree(q, MEM_IDNS_QUERY);
224   }
225 ***************
226 *** 571,577 ****
227             /* name servers went away; reconfiguring or shutting down */
228             break;
229         q = n->data;
230 !       if (tvSubDsec(q->sent_t, current_time) < Config.Timeout.idns_retransmit * (1 << q->nsends % nns))
231             break;
232         debug(78, 3) ("idnsCheckQueue: ID %#04x timeout\n",
233             q->id);
234 --- 576,582 ----
235             /* name servers went away; reconfiguring or shutting down */
236             break;
237         q = n->data;
238 !       if (tvSubDsec(q->sent_t, current_time) < Config.Timeout.idns_retransmit * 1 << ((q->nsends - 1) / nns))
239             break;
240         debug(78, 3) ("idnsCheckQueue: ID %#04x timeout\n",
241             q->id);
242 ***************
243 *** 585,592 ****
244                 (int) q->id, q->nsends,
245                 tvSubDsec(q->start_t, current_time));
246             cbdataUnlock(q->callback_data);
247 !           if (v)
248 !               q->callback(q->callback_data, NULL, 0);
249             memFree(q, MEM_IDNS_QUERY);
250         }
251       }
252 --- 590,601 ----
253                 (int) q->id, q->nsends,
254                 tvSubDsec(q->start_t, current_time));
255             cbdataUnlock(q->callback_data);
256 !           if (v) {
257 !               if (q->rcode != 0)
258 !                   q->callback(q->callback_data, NULL, -q->rcode, q->error);
259 !               else
260 !                   q->callback(q->callback_data, NULL, -16, "Timeout");
261 !           }
262             memFree(q, MEM_IDNS_QUERY);
263         }
264       }
265 ***************
266 *** 683,689 ****
267       q->id = rfc1035BuildAQuery(name, q->buf, &q->sz);
268       if (0 == q->id) {
269         /* problem with query data -- query not sent */
270 !       callback(data, NULL, 0);
271         memFree(q, MEM_IDNS_QUERY);
272         return;
273       }
274 --- 692,698 ----
275       q->id = rfc1035BuildAQuery(name, q->buf, &q->sz);
276       if (0 == q->id) {
277         /* problem with query data -- query not sent */
278 !       callback(data, NULL, 0, "Internal error");
279         memFree(q, MEM_IDNS_QUERY);
280         return;
281       }
282 Index: squid/src/forward.c
283 diff -c squid/src/forward.c:1.82.2.5 squid/src/forward.c:1.82.2.6
284 *** squid/src/forward.c:1.82.2.5        Sat Nov 29 11:53:00 2003
285 --- squid/src/forward.c Sat Dec  6 10:19:37 2003
286 ***************
287 *** 138,144 ****
288         return 0;
289       if (fwdState->origin_tries > 2)
290         return 0;
291 !     if (squid_curtime - fwdState->start > Config.Timeout.connect)
292         return 0;
293       if (fwdState->flags.dont_retry)
294         return 0;
295 --- 138,144 ----
296         return 0;
297       if (fwdState->origin_tries > 2)
298         return 0;
299 !     if (squid_curtime - fwdState->start > Config.Timeout.forward)
300         return 0;
301       if (fwdState->flags.dont_retry)
302         return 0;
303 ***************
304 *** 365,371 ****
305       FwdServer *fs = fwdState->servers;
306       const char *host;
307       unsigned short port;
308 !     time_t ctimeout;
309       struct in_addr outgoing;
310       unsigned short tos;
311       assert(fs);
312 --- 365,372 ----
313       FwdServer *fs = fwdState->servers;
314       const char *host;
315       unsigned short port;
316 !     int ctimeout;
317 !     int ftimeout = Config.Timeout.forward - (squid_curtime - fwdState->start);
318       struct in_addr outgoing;
319       unsigned short tos;
320       assert(fs);
321 ***************
322 *** 386,391 ****
323 --- 387,396 ----
324         port = fwdState->request->port;
325         ctimeout = Config.Timeout.connect;
326       }
327 +     if (ftimeout < 0)
328 +       ftimeout = 5;
329 +     if (ftimeout < ctimeout)
330 +       ctimeout = ftimeout;
331       if (fwdCheckRetriable(fwdState)) {
332         if ((fd = pconnPop(host, port)) >= 0) {
333             debug(17, 3) ("fwdConnectStart: reusing pconn FD %d\n", fd);
334 Index: squid/src/fqdncache.c
335 diff -c squid/src/fqdncache.c:1.149.2.3 squid/src/fqdncache.c:1.149.2.4
336 *** squid/src/fqdncache.c:1.149.2.3     Thu Dec  4 03:10:12 2003
337 --- squid/src/fqdncache.c       Sat Dec  6 10:19:37 2003
338 ***************
339 *** 72,81 ****
340   
341   #if USE_DNSSERVERS
342   static HLPCB fqdncacheHandleReply;
343 ! static fqdncache_entry *fqdncacheParse(const char *buf);
344   #else
345   static IDNSCB fqdncacheHandleReply;
346 ! static fqdncache_entry *fqdncacheParse(rfc1035_rr *, int);
347   #endif
348   static void fqdncacheRelease(fqdncache_entry *);
349   static fqdncache_entry *fqdncacheCreateEntry(const char *name);
350 --- 72,81 ----
351   
352   #if USE_DNSSERVERS
353   static HLPCB fqdncacheHandleReply;
354 ! static fqdncache_entry *fqdncacheParse(fqdncache_entry *, const char *buf);
355   #else
356   static IDNSCB fqdncacheHandleReply;
357 ! static fqdncache_entry *fqdncacheParse(fqdncache_entry *, rfc1035_rr *, int, const char *error_message);
358   #endif
359   static void fqdncacheRelease(fqdncache_entry *);
360   static fqdncache_entry *fqdncacheCreateEntry(const char *name);
361 ***************
362 *** 189,199 ****
363   static void
364   fqdncacheAddEntry(fqdncache_entry * f)
365   {
366 !     hash_link *e = hash_lookup(fqdn_table, f->hash.key);
367       if (NULL != e) {
368 !       /* avoid colission */
369 !       fqdncache_entry *q = (fqdncache_entry *) e;
370 !       fqdncacheRelease(q);
371       }
372       hash_join(fqdn_table, &f->hash);
373       dlinkAdd(f, &f->lru, &lru_list);
374 --- 189,203 ----
375   static void
376   fqdncacheAddEntry(fqdncache_entry * f)
377   {
378 !     fqdncache_entry *e = (fqdncache_entry *) hash_lookup(fqdn_table, f->hash.key);
379       if (NULL != e) {
380 !       /* avoid collision */
381 !       if (f->flags.negcached && !e->flags.negcached && e->expires > squid_curtime) {
382 !           /* Don't waste good information */
383 !           fqdncacheFreeEntry(f);
384 !           return;
385 !       }
386 !       fqdncacheRelease(e);
387       }
388       hash_join(fqdn_table, &f->hash);
389       dlinkAdd(f, &f->lru, &lru_list);
390 ***************
391 *** 222,317 ****
392   
393   static fqdncache_entry *
394   #if USE_DNSSERVERS
395 ! fqdncacheParse(const char *inbuf)
396   {
397       LOCAL_ARRAY(char, buf, DNS_INBUF_SZ);
398       char *token;
399 -     static fqdncache_entry f;
400       int ttl;
401 !     memset(&f, '\0', sizeof(f));
402 !     f.expires = squid_curtime;
403 !     f.flags.negcached = 1;
404       if (inbuf == NULL) {
405 !       debug(35, 1) ("fqdncacheParse: Got <NULL> reply\n");
406 !       return &f;
407       }
408       xstrncpy(buf, inbuf, DNS_INBUF_SZ);
409       debug(35, 5) ("fqdncacheParse: parsing: {%s}\n", buf);
410       token = strtok(buf, w_space);
411       if (NULL == token) {
412 !       debug(35, 1) ("fqdncacheParse: Got <NULL>, expecting '$name'\n");
413 !       return &f;
414       }
415       if (0 == strcmp(token, "$fail")) {
416 -       f.expires = squid_curtime + Config.negativeDnsTtl;
417         token = strtok(NULL, "\n");
418         assert(NULL != token);
419 !       f.error_message = xstrdup(token);
420 !       return &f;
421       }
422       if (0 != strcmp(token, "$name")) {
423 !       debug(35, 1) ("fqdncacheParse: Got '%s', expecting '$name'\n", token);
424 !       return &f;
425       }
426       token = strtok(NULL, w_space);
427       if (NULL == token) {
428 !       debug(35, 1) ("fqdncacheParse: Got <NULL>, expecting TTL\n");
429 !       return &f;
430       }
431 !     f.flags.negcached = 0;
432       ttl = atoi(token);
433 !     if (ttl > 0 && ttl < Config.positiveDnsTtl)
434 !       f.expires = squid_curtime + ttl;
435 !     else
436 !       f.expires = squid_curtime + Config.positiveDnsTtl;
437       token = strtok(NULL, w_space);
438       if (NULL != token) {
439 !       f.names[0] = xstrdup(token);
440 !       f.name_count = 1;
441       }
442 !     return &f;
443   }
444   #else
445 ! fqdncacheParse(rfc1035_rr * answers, int nr)
446   {
447 -     static fqdncache_entry f;
448       int k;
449 !     int na = 0;
450 !     memset(&f, '\0', sizeof(f));
451 !     f.expires = squid_curtime + Config.negativeDnsTtl;
452 !     f.flags.negcached = 1;
453       if (nr < 0) {
454 !       debug(35, 3) ("fqdncacheParse: Lookup failed (error %d)\n",
455 !           rfc1035_errno);
456 !       assert(rfc1035_error_message);
457 !       f.error_message = xstrdup(rfc1035_error_message);
458 !       return &f;
459       }
460       if (nr == 0) {
461 !       debug(35, 3) ("fqdncacheParse: No DNS records\n");
462 !       f.error_message = xstrdup("No DNS records");
463 !       return &f;
464       }
465 !     debug(35, 3) ("fqdncacheParse: %d answers\n", nr);
466       assert(answers);
467       for (k = 0; k < nr; k++) {
468         if (answers[k].type != RFC1035_TYPE_PTR)
469             continue;
470         if (answers[k].class != RFC1035_CLASS_IN)
471             continue;
472 !       na++;
473 !       f.flags.negcached = 0;
474 !       f.names[0] = xstrndup(answers[k].rdata, answers[k].rdlength);
475 !       f.name_count = 1;
476 !       if (answers[k].ttl < Config.positiveDnsTtl)
477 !           f.expires = squid_curtime + answers[k].ttl;
478 !       else
479 !           f.expires = squid_curtime + Config.positiveDnsTtl;
480 !       return &f;
481 !     }
482 !     debug(35, 1) ("fqdncacheParse: No PTR record\n");
483 !     f.error_message = xstrdup("No PTR record");
484 !     return &f;
485   }
486   #endif
487   
488 --- 226,326 ----
489   
490   static fqdncache_entry *
491   #if USE_DNSSERVERS
492 ! fqdncacheParse(fqdncache_entry * f, const char *inbuf)
493   {
494       LOCAL_ARRAY(char, buf, DNS_INBUF_SZ);
495       char *token;
496       int ttl;
497 !     const char *name = (const char *) f->hash.key;
498 !     f->expires = squid_curtime + Config.negativeDnsTtl;
499 !     f->flags.negcached = 1;
500       if (inbuf == NULL) {
501 !       debug(35, 1) ("fqdncacheParse: Got <NULL> reply in response to '%s'\n", name);
502 !       f->error_message = xstrdup("Internal Error");
503 !       return f;
504       }
505       xstrncpy(buf, inbuf, DNS_INBUF_SZ);
506       debug(35, 5) ("fqdncacheParse: parsing: {%s}\n", buf);
507       token = strtok(buf, w_space);
508       if (NULL == token) {
509 !       debug(35, 1) ("fqdncacheParse: Got <NULL>, expecting '$name' in response to '%s'\n", name);
510 !       f->error_message = xstrdup("Internal Error");
511 !       return f;
512       }
513       if (0 == strcmp(token, "$fail")) {
514         token = strtok(NULL, "\n");
515         assert(NULL != token);
516 !       f->error_message = xstrdup(token);
517 !       return f;
518       }
519       if (0 != strcmp(token, "$name")) {
520 !       debug(35, 1) ("fqdncacheParse: Got '%s', expecting '$name' in response to '%s'\n", inbuf, name);
521 !       f->error_message = xstrdup("Internal Error");
522 !       return f;
523       }
524       token = strtok(NULL, w_space);
525       if (NULL == token) {
526 !       debug(35, 1) ("fqdncacheParse: Got '%s', expecting TTL in response to '%s'\n", inbuf, name);
527 !       f->error_message = xstrdup("Internal Error");
528 !       return f;
529       }
530 !     f->flags.negcached = 0;
531       ttl = atoi(token);
532 !     if (ttl == 0 || ttl > Config.positiveDnsTtl)
533 !       ttl = Config.positiveDnsTtl;
534 !     if (ttl < Config.negativeDnsTtl)
535 !       ttl = Config.negativeDnsTtl;
536 !     f->expires = squid_curtime + ttl;
537       token = strtok(NULL, w_space);
538       if (NULL != token) {
539 !       f->names[0] = xstrdup(token);
540 !       f->name_count = 1;
541       }
542 !     return f;
543   }
544   #else
545 ! fqdncacheParse(fqdncache_entry * f, rfc1035_rr * answers, int nr, const char *error_message)
546   {
547       int k;
548 !     int ttl = 0;
549 !     const char *name = (const char *) f->hash.key;
550 !     f->expires = squid_curtime + Config.negativeDnsTtl;
551 !     f->flags.negcached = 1;
552       if (nr < 0) {
553 !       debug(35, 3) ("fqdncacheParse: Lookup of '%s' failed (%s)\n", name, error_message);
554 !       f->error_message = xstrdup(error_message);
555 !       return f;
556       }
557       if (nr == 0) {
558 !       debug(35, 3) ("fqdncacheParse: No DNS records for '%s'\n", name);
559 !       f->error_message = xstrdup("No DNS records");
560 !       return f;
561       }
562 !     debug(35, 3) ("fqdncacheParse: %d answers for '%s'\n", nr, name);
563       assert(answers);
564       for (k = 0; k < nr; k++) {
565         if (answers[k].type != RFC1035_TYPE_PTR)
566             continue;
567         if (answers[k].class != RFC1035_CLASS_IN)
568             continue;
569 !       f->names[f->name_count++] = xstrndup(answers[k].rdata, answers[k].rdlength);
570 !       if (ttl == 0 || answers[k].ttl < ttl)
571 !           ttl = answers[k].ttl;
572 !       if (f->name_count >= FQDN_MAX_NAMES)
573 !           break;
574 !     }
575 !     if (f->name_count == 0) {
576 !       debug(35, 1) ("fqdncacheParse: No PTR record\n");
577 !       f->error_message = xstrdup("No PTR record");
578 !       return f;
579 !     }
580 !     if (ttl == 0 || ttl > Config.positiveDnsTtl)
581 !       ttl = Config.positiveDnsTtl;
582 !     if (ttl < Config.negativeDnsTtl)
583 !       ttl = Config.negativeDnsTtl;
584 !     f->expires = squid_curtime + ttl;
585 !     f->flags.negcached = 0;
586 !     return f;
587   }
588   #endif
589   
590 ***************
591 *** 319,348 ****
592   #if USE_DNSSERVERS
593   fqdncacheHandleReply(void *data, char *reply)
594   #else
595 ! fqdncacheHandleReply(void *data, rfc1035_rr * answers, int na)
596   #endif
597   {
598       int n;
599       generic_cbdata *c = data;
600       fqdncache_entry *f = c->data;
601 -     fqdncache_entry *x = NULL;
602       cbdataFree(c);
603       c = NULL;
604       n = ++FqdncacheStats.replies;
605       statHistCount(&statCounter.dns.svc_time,
606         tvSubMsec(f->request_time, current_time));
607   #if USE_DNSSERVERS
608 !     x = fqdncacheParse(reply);
609   #else
610 !     x = fqdncacheParse(answers, na);
611   #endif
612 -     assert(x);
613 -     f->name_count = x->name_count;
614 -     for (n = 0; n < (int) f->name_count; n++)
615 -       f->names[n] = x->names[n];
616 -     f->error_message = x->error_message;
617 -     f->expires = x->expires;
618 -     f->flags = x->flags;
619       fqdncacheAddEntry(f);
620       fqdncacheCallback(f);
621   }
622 --- 328,349 ----
623   #if USE_DNSSERVERS
624   fqdncacheHandleReply(void *data, char *reply)
625   #else
626 ! fqdncacheHandleReply(void *data, rfc1035_rr * answers, int na, const char *error_message)
627   #endif
628   {
629       int n;
630       generic_cbdata *c = data;
631       fqdncache_entry *f = c->data;
632       cbdataFree(c);
633       c = NULL;
634       n = ++FqdncacheStats.replies;
635       statHistCount(&statCounter.dns.svc_time,
636         tvSubMsec(f->request_time, current_time));
637   #if USE_DNSSERVERS
638 !     fqdncacheParse(f, reply);
639   #else
640 !     fqdncacheParse(f, answers, na, error_message);
641   #endif
642       fqdncacheAddEntry(f);
643       fqdncacheCallback(f);
644   }
645 Index: squid/src/ipcache.c
646 diff -c squid/src/ipcache.c:1.236.2.1 squid/src/ipcache.c:1.236.2.2
647 *** squid/src/ipcache.c:1.236.2.1       Fri Nov 28 12:14:32 2003
648 --- squid/src/ipcache.c Sat Dec  6 10:19:37 2003
649 ***************
650 *** 77,85 ****
651   static int ipcacheExpiredEntry(ipcache_entry *);
652   static int ipcache_testname(void);
653   #if USE_DNSSERVERS
654 ! static ipcache_entry *ipcacheParse(const char *buf);
655   #else
656 ! static ipcache_entry *ipcacheParse(rfc1035_rr *, int);
657   #endif
658   static ipcache_entry *ipcache_get(const char *);
659   static void ipcacheLockEntry(ipcache_entry *);
660 --- 77,85 ----
661   static int ipcacheExpiredEntry(ipcache_entry *);
662   static int ipcache_testname(void);
663   #if USE_DNSSERVERS
664 ! static ipcache_entry *ipcacheParse(ipcache_entry *, const char *buf);
665   #else
666 ! static ipcache_entry *ipcacheParse(ipcache_entry *, rfc1035_rr *, int, const char *error);
667   #endif
668   static ipcache_entry *ipcache_get(const char *);
669   static void ipcacheLockEntry(ipcache_entry *);
670 ***************
671 *** 199,209 ****
672   static void
673   ipcacheAddEntry(ipcache_entry * i)
674   {
675 !     hash_link *e = hash_lookup(ip_table, i->hash.key);
676       if (NULL != e) {
677 !       /* avoid colission */
678 !       ipcache_entry *q = (ipcache_entry *) e;
679 !       ipcacheRelease(q);
680       }
681       hash_join(ip_table, &i->hash);
682       dlinkAdd(i, &i->lru, &lru_list);
683 --- 199,213 ----
684   static void
685   ipcacheAddEntry(ipcache_entry * i)
686   {
687 !     ipcache_entry *e = (ipcache_entry *) hash_lookup(ip_table, i->hash.key);
688       if (NULL != e) {
689 !       /* avoid collision */
690 !       if (i->flags.negcached && !e->flags.negcached && e->expires > squid_curtime) {
691 !           /* Don't waste good information */
692 !           ipcacheFreeEntry(i);
693 !           return;
694 !       }
695 !       ipcacheRelease(e);
696       }
697       hash_join(ip_table, &i->hash);
698       dlinkAdd(i, &i->lru, &lru_list);
699 ***************
700 *** 230,326 ****
701       ipcacheUnlockEntry(i);
702   }
703   
704 - static ipcache_entry *
705   #if USE_DNSSERVERS
706 ! ipcacheParse(const char *inbuf)
707   {
708       LOCAL_ARRAY(char, buf, DNS_INBUF_SZ);
709       char *token;
710 !     static ipcache_entry i;
711 !     int j;
712       int k;
713       int ipcount = 0;
714       int ttl;
715       char A[32][16];
716 !     memset(&i, '\0', sizeof(i));
717 !     i.expires = squid_curtime;
718 !     i.flags.negcached = 1;
719       if (inbuf == NULL) {
720         debug(14, 1) ("ipcacheParse: Got <NULL> reply\n");
721 !       i.error_message = xstrdup("Internal Squid Error");
722 !       return &i;
723       }
724       xstrncpy(buf, inbuf, DNS_INBUF_SZ);
725       debug(14, 5) ("ipcacheParse: parsing: {%s}\n", buf);
726       token = strtok(buf, w_space);
727       if (NULL == token) {
728 !       debug(14, 1) ("ipcacheParse: Got <NULL>, expecting '$addr'\n");
729 !       return &i;
730       }
731       if (0 == strcmp(token, "$fail")) {
732 -       i.expires = squid_curtime + Config.negativeDnsTtl;
733         token = strtok(NULL, "\n");
734         assert(NULL != token);
735 !       i.error_message = xstrdup(token);
736 !       return &i;
737       }
738       if (0 != strcmp(token, "$addr")) {
739 !       debug(14, 1) ("ipcacheParse: Got '%s', expecting '$addr'\n", token);
740 !       return &i;
741       }
742       token = strtok(NULL, w_space);
743       if (NULL == token) {
744 !       debug(14, 1) ("ipcacheParse: Got <NULL>, expecting TTL\n");
745 !       return &i;
746       }
747 !     i.flags.negcached = 0;
748       ttl = atoi(token);
749 -     if (ttl > 0 && ttl < Config.positiveDnsTtl)
750 -       i.expires = squid_curtime + ttl;
751 -     else
752 -       i.expires = squid_curtime + Config.positiveDnsTtl;
753       while (NULL != (token = strtok(NULL, w_space))) {
754         xstrncpy(A[ipcount], token, 16);
755         if (++ipcount == 32)
756             break;
757       }
758 !     if (0 == ipcount) {
759 !       i.addrs.in_addrs = NULL;
760 !       i.addrs.bad_mask = NULL;
761       } else {
762 !       i.addrs.in_addrs = xcalloc(ipcount, sizeof(struct in_addr));
763 !       i.addrs.bad_mask = xcalloc(ipcount, sizeof(unsigned char));
764 !     }
765 !     for (j = 0, k = 0; k < ipcount; k++) {
766 !       if (safe_inet_addr(A[k], &i.addrs.in_addrs[j]))
767 !           j++;
768 !       else
769 !           debug(14, 1) ("ipcacheParse: Invalid IP address '%s'\n", A[k]);
770       }
771 !     i.addrs.count = (unsigned char) j;
772 !     return &i;
773   }
774   #else
775 ! ipcacheParse(rfc1035_rr * answers, int nr)
776   {
777 -     static ipcache_entry i;
778       int k;
779       int j;
780       int na = 0;
781 !     memset(&i, '\0', sizeof(i));
782 !     i.expires = squid_curtime + Config.negativeDnsTtl;
783 !     i.flags.negcached = 1;
784       if (nr < 0) {
785 !       debug(14, 3) ("ipcacheParse: Lookup failed (error %d)\n",
786 !           rfc1035_errno);
787 !       assert(rfc1035_error_message);
788 !       i.error_message = xstrdup(rfc1035_error_message);
789 !       return &i;
790       }
791       if (nr == 0) {
792 !       debug(14, 3) ("ipcacheParse: No DNS records\n");
793 !       i.error_message = xstrdup("No DNS records");
794 !       return &i;
795       }
796       assert(answers);
797       for (j = 0, k = 0; k < nr; k++) {
798 --- 234,339 ----
799       ipcacheUnlockEntry(i);
800   }
801   
802   #if USE_DNSSERVERS
803 ! static ipcache_entry *
804 ! ipcacheParse(ipcache_entry * i, const char *inbuf)
805   {
806       LOCAL_ARRAY(char, buf, DNS_INBUF_SZ);
807       char *token;
808 !     int j = 0;
809       int k;
810       int ipcount = 0;
811       int ttl;
812       char A[32][16];
813 !     const char *name = (const char *) i->hash.key;
814 !     i->expires = squid_curtime + Config.negativeDnsTtl;
815 !     i->flags.negcached = 1;
816 !     safe_free(i->addrs.in_addrs);
817 !     safe_free(i->addrs.bad_mask);
818 !     safe_free(i->error_message);
819 !     i->addrs.count = 0;
820       if (inbuf == NULL) {
821         debug(14, 1) ("ipcacheParse: Got <NULL> reply\n");
822 !       i->error_message = xstrdup("Internal Squid Error");
823 !       return i;
824       }
825       xstrncpy(buf, inbuf, DNS_INBUF_SZ);
826       debug(14, 5) ("ipcacheParse: parsing: {%s}\n", buf);
827       token = strtok(buf, w_space);
828       if (NULL == token) {
829 !       debug(14, 1) ("ipcacheParse: expecting result, got '%s'\n", inbuf);
830 !       i->error_message = xstrdup("Internal Squid Error");
831 !       return NULL;
832       }
833       if (0 == strcmp(token, "$fail")) {
834         token = strtok(NULL, "\n");
835         assert(NULL != token);
836 !       i->error_message = xstrdup(token);
837 !       return i;
838       }
839       if (0 != strcmp(token, "$addr")) {
840 !       debug(14, 1) ("ipcacheParse: expecting '$addr', got '%s' in response to '%s'\n", inbuf, name);
841 !       i->error_message = xstrdup("Internal Squid Error");
842 !       return NULL;
843       }
844       token = strtok(NULL, w_space);
845       if (NULL == token) {
846 !       debug(14, 1) ("ipcacheParse: expecting data, got '%s' in response to '%s'\n", inbuf, name);
847 !       i->error_message = xstrdup("Internal Squid Error");
848 !       return NULL;
849       }
850 !     i->flags.negcached = 0;
851       ttl = atoi(token);
852       while (NULL != (token = strtok(NULL, w_space))) {
853         xstrncpy(A[ipcount], token, 16);
854         if (++ipcount == 32)
855             break;
856       }
857 !     if (ipcount <= 0) {
858 !       debug(14, 1) ("ipcacheParse: No addresses in response to '%s'\n", name);
859       } else {
860 !       i->addrs.in_addrs = xcalloc(ipcount, sizeof(struct in_addr));
861 !       i->addrs.bad_mask = xcalloc(ipcount, sizeof(unsigned char));
862 !       for (j = 0, k = 0; k < ipcount; k++) {
863 !           if (safe_inet_addr(A[k], &i->addrs.in_addrs[j]))
864 !               j++;
865 !           else
866 !               debug(14, 1) ("ipcacheParse: Invalid IP address '%s' in response to '%s'\n", A[k], name);
867 !       }
868       }
869 !     i->addrs.count = (unsigned char) j;
870 !     if (ttl == 0 || ttl > Config.positiveDnsTtl)
871 !       ttl = Config.positiveDnsTtl;
872 !     if (ttl < Config.negativeDnsTtl)
873 !       ttl = Config.negativeDnsTtl;
874 !     i->expires = squid_curtime + ttl;
875 !     return i;
876   }
877   #else
878 ! static ipcache_entry *
879 ! ipcacheParse(ipcache_entry * i, rfc1035_rr * answers, int nr, const char *error_message)
880   {
881       int k;
882       int j;
883       int na = 0;
884 !     int ttl = 0;
885 !     const char *name = (const char *) i->hash.key;
886 !     i->expires = squid_curtime + Config.negativeDnsTtl;
887 !     i->flags.negcached = 1;
888 !     safe_free(i->addrs.in_addrs);
889 !     safe_free(i->addrs.bad_mask);
890 !     safe_free(i->error_message);
891 !     i->addrs.count = 0;
892       if (nr < 0) {
893 !       debug(14, 3) ("ipcacheParse: Lookup failed '%s' for '%s'\n",
894 !           error_message, (const char *) i->hash.key);
895 !       i->error_message = xstrdup(error_message);
896 !       return i;
897       }
898       if (nr == 0) {
899 !       debug(14, 3) ("ipcacheParse: No DNS records in response to '%s'\n", name);
900 !       i->error_message = xstrdup("No DNS records");
901 !       return i;
902       }
903       assert(answers);
904       for (j = 0, k = 0; k < nr; k++) {
905 ***************
906 *** 331,363 ****
907         na++;
908       }
909       if (na == 0) {
910 !       debug(14, 1) ("ipcacheParse: No Address records\n");
911 !       i.error_message = xstrdup("No Address records");
912 !       return &i;
913 !     }
914 !     i.flags.negcached = 0;
915 !     i.addrs.in_addrs = xcalloc(na, sizeof(struct in_addr));
916 !     i.addrs.bad_mask = xcalloc(na, sizeof(unsigned char));
917 !     i.addrs.count = (unsigned char) na;
918       for (j = 0, k = 0; k < nr; k++) {
919         if (answers[k].type != RFC1035_TYPE_A)
920             continue;
921         if (answers[k].class != RFC1035_CLASS_IN)
922             continue;
923 !       if (j == 0) {
924 !           if (answers[k].ttl < Config.positiveDnsTtl)
925 !               i.expires = squid_curtime + answers[k].ttl;
926 !           else
927 !               i.expires = squid_curtime + Config.positiveDnsTtl;
928 !       }
929         assert(answers[k].rdlength == 4);
930 !       xmemcpy(&i.addrs.in_addrs[j++], answers[k].rdata, 4);
931         debug(14, 3) ("ipcacheParse: #%d %s\n",
932             j - 1,
933 !           inet_ntoa(i.addrs.in_addrs[j - 1]));
934       }
935       assert(j == na);
936 !     return &i;
937   }
938   #endif
939   
940 --- 344,377 ----
941         na++;
942       }
943       if (na == 0) {
944 !       debug(14, 1) ("ipcacheParse: No Address records in response to '%s'\n", name);
945 !       i->error_message = xstrdup("No Address records");
946 !       return i;
947 !     }
948 !     i->flags.negcached = 0;
949 !     i->addrs.in_addrs = xcalloc(na, sizeof(struct in_addr));
950 !     i->addrs.bad_mask = xcalloc(na, sizeof(unsigned char));
951       for (j = 0, k = 0; k < nr; k++) {
952         if (answers[k].type != RFC1035_TYPE_A)
953             continue;
954         if (answers[k].class != RFC1035_CLASS_IN)
955             continue;
956 !       if (ttl == 0 || ttl > answers[k].ttl)
957 !           ttl = answers[k].ttl;
958         assert(answers[k].rdlength == 4);
959 !       xmemcpy(&i->addrs.in_addrs[j++], answers[k].rdata, 4);
960         debug(14, 3) ("ipcacheParse: #%d %s\n",
961             j - 1,
962 !           inet_ntoa(i->addrs.in_addrs[j - 1]));
963       }
964 +     i->addrs.count = (unsigned char) na;
965 +     if (ttl == 0 || ttl > Config.positiveDnsTtl)
966 +       ttl = Config.positiveDnsTtl;
967 +     if (ttl < Config.negativeDnsTtl)
968 +       ttl = Config.negativeDnsTtl;
969 +     i->expires = squid_curtime + ttl;
970       assert(j == na);
971 !     return i;
972   }
973   #endif
974   
975 ***************
976 *** 365,391 ****
977   #if USE_DNSSERVERS
978   ipcacheHandleReply(void *data, char *reply)
979   #else
980 ! ipcacheHandleReply(void *data, rfc1035_rr * answers, int na)
981   #endif
982   {
983       generic_cbdata *c = data;
984       ipcache_entry *i = c->data;
985 -     ipcache_entry *x = NULL;
986       cbdataFree(c);
987       c = NULL;
988       IpcacheStats.replies++;
989       statHistCount(&statCounter.dns.svc_time,
990         tvSubMsec(i->request_time, current_time));
991   #if USE_DNSSERVERS
992 !     x = ipcacheParse(reply);
993   #else
994 !     x = ipcacheParse(answers, na);
995   #endif
996 -     assert(x);
997 -     i->addrs = x->addrs;
998 -     i->error_message = x->error_message;
999 -     i->expires = x->expires;
1000 -     i->flags = x->flags;
1001       ipcacheAddEntry(i);
1002       ipcacheCallback(i);
1003   }
1004 --- 379,399 ----
1005   #if USE_DNSSERVERS
1006   ipcacheHandleReply(void *data, char *reply)
1007   #else
1008 ! ipcacheHandleReply(void *data, rfc1035_rr * answers, int na, const char *error_message)
1009   #endif
1010   {
1011       generic_cbdata *c = data;
1012       ipcache_entry *i = c->data;
1013       cbdataFree(c);
1014       c = NULL;
1015       IpcacheStats.replies++;
1016       statHistCount(&statCounter.dns.svc_time,
1017         tvSubMsec(i->request_time, current_time));
1018   #if USE_DNSSERVERS
1019 !     ipcacheParse(i, reply);
1020   #else
1021 !     ipcacheParse(i, answers, na, error_message);
1022   #endif
1023       ipcacheAddEntry(i);
1024       ipcacheCallback(i);
1025   }
1026 Index: squid/src/structs.h
1027 diff -c squid/src/structs.h:1.408.2.16 squid/src/structs.h:1.408.2.17
1028 *** squid/src/structs.h:1.408.2.16      Sat Nov 29 11:53:00 2003
1029 --- squid/src/structs.h Sat Dec  6 10:19:38 2003
1030 ***************
1031 *** 400,405 ****
1032 --- 400,406 ----
1033       struct {
1034         time_t read;
1035         time_t lifetime;
1036 +       time_t forward;
1037         time_t connect;
1038         time_t peer_connect;
1039         time_t request;
1040 Index: squid/src/typedefs.h
1041 diff -c squid/src/typedefs.h:1.132.2.2 squid/src/typedefs.h:1.132.2.3
1042 *** squid/src/typedefs.h:1.132.2.2      Sun May 11 11:30:13 2003
1043 --- squid/src/typedefs.h        Sat Dec  6 10:19:38 2003
1044 ***************
1045 *** 253,259 ****
1046   typedef int HLPSAVAIL(void *);
1047   typedef void HLPSONEQ(void *);
1048   typedef void HLPCMDOPTS(int *argc, char **argv);
1049 ! typedef void IDNSCB(void *, rfc1035_rr *, int);
1050   
1051   typedef void STINIT(SwapDir *);
1052   typedef void STNEWFS(SwapDir *);
1053 --- 253,259 ----
1054   typedef int HLPSAVAIL(void *);
1055   typedef void HLPSONEQ(void *);
1056   typedef void HLPCMDOPTS(int *argc, char **argv);
1057 ! typedef void IDNSCB(void *, rfc1035_rr *, int, const char *);
1058   
1059   typedef void STINIT(SwapDir *);
1060   typedef void STNEWFS(SwapDir *);
This page took 0.178567 seconds and 3 git commands to generate.