From: wessels <> Date: Wed, 16 Oct 1996 00:05:56 +0000 (+0000) Subject: fix running w/o dnsservers X-Git-Tag: SQUID_3_0_PRE1~5642 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dd7ad0a48329feb11525e6df98fd60ed65411e20;p=thirdparty%2Fsquid.git fix running w/o dnsservers --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 25a7af5300..63b6edd789 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,5 +1,5 @@ /* - * $Id: cache_cf.cc,v 1.109 1996/10/15 16:40:04 wessels Exp $ + * $Id: cache_cf.cc,v 1.110 1996/10/15 18:05:56 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -1426,10 +1426,10 @@ parseConfigFile(char *file_name) printf("Setting it to the maximum (%d).\n", DefaultDnsChildrenMax); Config.dnsChildren = DefaultDnsChildrenMax; } - if (Config.program.redirect) { + if (Config.Program.redirect) { if (Config.redirectChildren < 1) { Config.redirectChildren = 0; - safe_free(Config.program.redirect); + safe_free(Config.Program.redirect); } else if (Config.redirectChildren > DefaultRedirectChildrenMax) { printf("WARNING: redirect_children was set to a bad value: %d\n", Config.redirectChildren); @@ -1603,7 +1603,7 @@ configDoConfigure(void) Config.errHtmlText = xstrdup(null_string); storeConfigure(); if (httpd_accel_mode && !Config.Accel.withProxy) { - safe_free(Config.program.ftpget); - Config.program.ftpget = xstrdup("none"); + safe_free(Config.Program.ftpget); + Config.Program.ftpget = xstrdup("none"); } } diff --git a/src/dns.cc b/src/dns.cc index 5b800c5e87..18528d11af 100644 --- a/src/dns.cc +++ b/src/dns.cc @@ -1,5 +1,5 @@ /* - * $Id: dns.cc,v 1.20 1996/10/13 06:19:44 wessels Exp $ + * $Id: dns.cc,v 1.21 1996/10/15 18:05:56 wessels Exp $ * * DEBUG: section 34 Dnsserver interface * AUTHOR: Harvest Derived @@ -113,8 +113,8 @@ struct dnsQueueData { static int dnsOpenServer _PARAMS((char *command)); static dnsserver_t **dns_child_table = NULL; -static int NDnsServersAlloc = 0; +int NDnsServersAlloc = 0; char *dns_error_message = NULL; /* possible error message */ struct _dnsStats DnsStats; diff --git a/src/ipcache.cc b/src/ipcache.cc index 063171fcc4..9c529ac80a 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -1,5 +1,5 @@ /* - * $Id: ipcache.cc,v 1.72 1996/10/15 16:40:09 wessels Exp $ + * $Id: ipcache.cc,v 1.73 1996/10/15 18:05:58 wessels Exp $ * * DEBUG: section 14 IP Cache * AUTHOR: Harvest Derived @@ -142,10 +142,11 @@ static ipcache_entry *ipcache_parsebuffer _PARAMS((char *buf, dnsserver_t *)); static void ipcache_release _PARAMS((ipcache_entry *)); static ipcache_entry *ipcache_GetFirst _PARAMS((void)); static ipcache_entry *ipcache_GetNext _PARAMS((void)); -static ipcache_entry *ipcache_create _PARAMS((void)); +static ipcache_entry *ipcache_create _PARAMS((char *name)); static void ipcache_add_to_hash _PARAMS((ipcache_entry *)); static void ipcache_call_pending _PARAMS((ipcache_entry *)); -static void ipcache_add _PARAMS((char *, ipcache_entry *, struct hostent *, int)); +static ipcache_entry * ipcacheAddNew _PARAMS((char *, struct hostent *, ipcache_status_t)); +static void ipcacheAddHostent _PARAMS((ipcache_entry *, struct hostent *)); static int ipcacheHasPending _PARAMS((ipcache_entry *)); static ipcache_entry *ipcache_get _PARAMS((char *)); static void dummy_handler _PARAMS((int, ipcache_addrs *, void *)); @@ -381,21 +382,19 @@ ipcache_purgelru(void) /* create blank ipcache_entry */ static ipcache_entry * -ipcache_create(void) +ipcache_create(char *name) { static ipcache_entry *new; - if (meta_data.ipcache_count > ipcache_high) { if (ipcache_purgelru() < 0) debug(14, 0, "HELP!! IP Cache is overflowing!\n"); } meta_data.ipcache_count++; new = xcalloc(1, sizeof(ipcache_entry)); - /* set default to 4, in case parser fail to get token $h_length from - * dnsserver. */ + new->name = xstrdup(name); new->expires = squid_curtime + Config.negativeDnsTtl; + ipcache_add_to_hash(new); return new; - } static void @@ -408,36 +407,38 @@ ipcache_add_to_hash(ipcache_entry * i) debug(14, 5, "ipcache_add_to_hash: name <%s>\n", i->name); } - static void -ipcache_add(char *name, ipcache_entry * i, struct hostent *hp, int cached) +ipcacheAddHostent(ipcache_entry *i, struct hostent *hp) { - int addr_count; - int k; + int addr_count = 0; + int k; + safe_free(i->addrs.in_addrs); + while ((addr_count < 255) && *(hp->h_addr_list + addr_count)) + ++addr_count; + i->addrs.count = (unsigned char) addr_count; + i->addrs.in_addrs = xcalloc(addr_count, sizeof(struct in_addr)); + for (k = 0; k < addr_count; k++) + memcpy(&i->addrs.in_addrs[k].s_addr, + *(hp->h_addr_list + k), + hp->h_length); + i->status = IP_CACHED; +} +static ipcache_entry * +ipcacheAddNew(char *name, struct hostent *hp, ipcache_status_t status) +{ + ipcache_entry *i; if (ipcache_get(name)) fatal_dump("ipcache_add: somebody adding a duplicate!"); - debug(14, 10, "ipcache_add: Adding name '%s' (%s).\n", name, - cached ? "cached" : "not cached"); - i->name = xstrdup(name); - if (cached) { - /* count for IPs */ - addr_count = 0; - while ((addr_count < 255) && *(hp->h_addr_list + addr_count)) - ++addr_count; - i->addrs.count = (unsigned char) addr_count; - i->addrs.in_addrs = xcalloc(addr_count, sizeof(struct in_addr)); - for (k = 0; k < addr_count; k++) - memcpy(&i->addrs.in_addrs[k].s_addr, - *(hp->h_addr_list + k), - hp->h_length); - i->status = IP_CACHED; - i->expires = squid_curtime + Config.positiveDnsTtl; - } else { - i->status = IP_NEGATIVE_CACHED; - i->expires = squid_curtime + Config.negativeDnsTtl; - } - ipcache_add_to_hash(i); + debug(14, 10, "ipcache_add: Adding '%s', status=%c\n", + name, + ipcache_status_char[status]); + i = ipcache_create(name); + if (hp) + ipcacheAddHostent(i, hp); + i->status = status; + i->lastref = squid_curtime; + return i; } /* walks down the pending list, calling handlers */ @@ -654,11 +655,8 @@ ipcache_nbgethostbyname(char *name, int fd, IPH handler, void *handlerData) /* MISS: No entry, create the new one */ debug(14, 5, "ipcache_nbgethostbyname: MISS for '%s'\n", name); IpcacheStats.misses++; - i = ipcache_create(); - i->name = xstrdup(name); - i->status = IP_PENDING; + i = ipcacheAddNew(name, NULL, IP_PENDING); ipcacheAddPending(i, fd, handler, handlerData); - ipcache_add_to_hash(i); } else if (i->status == IP_CACHED || i->status == IP_NEGATIVE_CACHED) { /* HIT */ debug(14, 4, "ipcache_nbgethostbyname: HIT for '%s'\n", name); @@ -682,8 +680,12 @@ ipcache_nbgethostbyname(char *name, int fd, IPH handler, void *handlerData) if ((dnsData = dnsGetFirstAvailable())) ipcache_dnsDispatch(dnsData, i); - else + else if (NDnsServersAlloc > 0) ipcacheEnqueue(i); + else { + ipcache_gethostbyname(name, IP_BLOCKING_LOOKUP); + ipcache_call_pending(i); + } } static void @@ -782,6 +784,7 @@ ipcache_gethostbyname(char *name, int flags) if (!name) fatal_dump("ipcache_gethostbyname: NULL name"); + debug(14, 3, "ipcache_gethostbyname: '%s', flags=%x\n", name, flags); IpcacheStats.requests++; if ((i = ipcache_get(name))) { if (ipcacheExpiredEntry(i)) { @@ -791,8 +794,10 @@ ipcache_gethostbyname(char *name, int flags) } if (i) { if (i->status == IP_PENDING || i->status == IP_DISPATCHED) { - IpcacheStats.pending_hits++; - return NULL; + if (!BIT_TEST(flags, IP_BLOCKING_LOOKUP)) { + IpcacheStats.pending_hits++; + return NULL; + } } else if (i->status == IP_NEGATIVE_CACHED) { IpcacheStats.negative_hits++; dns_error_message = i->error_message; @@ -806,14 +811,17 @@ ipcache_gethostbyname(char *name, int flags) IpcacheStats.misses++; if ((addrs = ipcacheCheckNumeric(name))) return addrs; - if (flags & IP_BLOCKING_LOOKUP) { + if (BIT_TEST(flags,IP_BLOCKING_LOOKUP)) { IpcacheStats.ghbn_calls++; + debug(14, 3, "ipcache_gethostbyname: blocking on gethostbyname() for '%s'\n", name); hp = gethostbyname(name); if (hp && hp->h_name && (hp->h_name[0] != '\0') && ip_table) { /* good address, cached */ - ipcache_add(name, ipcache_create(), hp, 1); - i = ipcache_get(name); - i->lastref = squid_curtime; + if (i == NULL) { + i = ipcacheAddNew(name, hp, IP_CACHED); + } else { + ipcacheAddHostent(i, hp); + } i->expires = squid_curtime + Config.positiveDnsTtl; #if LIBRESOLV_DNS_TTL_HACK if (_dns_ttl_ > -1) @@ -823,9 +831,7 @@ ipcache_gethostbyname(char *name, int flags) } /* bad address, negative cached */ if (ip_table) { - ipcache_add(name, ipcache_create(), hp, 0); - i = ipcache_get(name); - i->lastref = squid_curtime; + i = ipcacheAddNew(name, hp, IP_NEGATIVE_CACHED); i->expires = squid_curtime + Config.negativeDnsTtl; return NULL; }