From: wessels <> Date: Thu, 9 Apr 1998 14:24:15 +0000 (+0000) Subject: cycle through every address on every use X-Git-Tag: SQUID_3_0_PRE1~3536 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52926044bf33aa8651b84b14845ed1e8e3e6720b;p=thirdparty%2Fsquid.git cycle through every address on every use --- diff --git a/src/comm.cc b/src/comm.cc index 2be5d3c0f7..f4148951ba 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,7 +1,7 @@ /* - * $Id: comm.cc,v 1.248 1998/04/08 22:48:47 wessels Exp $ + * $Id: comm.cc,v 1.249 1998/04/09 08:25:50 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -342,7 +342,7 @@ commConnectDnsHandle(const ipcache_addrs * ia, void *data) } assert(ia->cur < ia->count); cs->in_addr = ia->in_addrs[ia->cur]; - ipcacheCycleAddr(cs->host); + ipcacheCycleAddr(cs->host, NULL); cs->addrcount = ia->count; cs->connstart = squid_curtime; commSetConnectTimeout(cs->fd, commBackoffTimeout((int) ia->count)); diff --git a/src/ipcache.cc b/src/ipcache.cc index 054c6faa66..25ceb10c87 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -1,6 +1,6 @@ /* - * $Id: ipcache.cc,v 1.177 1998/04/09 02:25:22 wessels Exp $ + * $Id: ipcache.cc,v 1.178 1998/04/09 08:24:15 wessels Exp $ * * DEBUG: section 14 IP Cache * AUTHOR: Harvest Derived @@ -753,11 +753,12 @@ ipcacheStatPrint(ipcache_entry * i, StoreEntry * sentry) (int) (i->expires - squid_curtime), (int) i->addrs.count, (int) i->addrs.badcount); - for (k = 0; k < (int) i->addrs.count; k++) + for (k = 0; k < (int) i->addrs.count; k++) { storeAppendPrintf(sentry, " %15s-%3s", inet_ntoa(i->addrs.in_addrs[k]), i->addrs.bad_mask[k] ? "BAD" : "OK "); if (i->addrs.count > 1 && k == i->addrs.cur) - storeAppendPrintf(sentry, ",CUR"), + storeAppendPrintf(sentry, ",CUR"); + } storeAppendPrintf(sentry, "\n"); } @@ -879,11 +880,11 @@ ipcacheUnlockEntry(ipcache_entry * i) ipcache_release(i); } +#if OLD_CODE void ipcacheCycleAddr(const char *name) { ipcache_entry *i; - ipcache_addrs *ia; unsigned char fullcircle; if ((i = ipcache_get(name)) == NULL) return; @@ -901,13 +902,43 @@ ipcacheCycleAddr(const char *name) } } } +#endif + +void +ipcacheCycleAddr(const char *name, ipcache_addrs *ia) +{ + ipcache_entry *i; + unsigned char k; + assert(name || ia); + if (NULL == ia) { + if ((i = ipcache_get(name)) == NULL) + return; + if (i->status != IP_CACHED) + return; + ia = &i->addrs; + } + for (k = 0; k < ia->count; k++) { + if (++ia->cur == ia->count) + ia->cur = 0; + if (!ia->bad_mask[ia->cur]) + break;; + } + if (k == ia->count) { + /* All bad, reset to All good */ + debug(14, 3)("ipcacheCycleAddr: Changing ALL %s addrs from BAD to OK\n", + name); + for (k = 0; k < ia->count; k++) + ia->bad_mask[k] = 0; + ia->badcount = 0; + ia->cur = 0; + } + debug(14,1)("ipcacheCycleAddr: %s now at %s\n", name, + inet_ntoa(ia->in_addrs[ia->cur])); +} -/* "MarkBad" function must leave the "cur" pointer at the next - * available good address, or the next bad address, in the list. - * This simulates the functionality of RemoveBadAddr() which it - * replaces. Marking, instead of removing, allows bad addresses - * to be retried as a last resort before returning an error to - * the user. +/* + * Marks the given address as BAD and calls ipcacheCycleAddr to + * advance the current pointer to the next OK address. */ void ipcacheMarkBadAddr(const char *name, struct in_addr addr) @@ -922,24 +953,14 @@ ipcacheMarkBadAddr(const char *name, struct in_addr addr) if (ia->in_addrs[k].s_addr == addr.s_addr) break; } - if (k == (int) ia->count) + if (k == (int) ia->count) /* not found */ return; if (!ia->bad_mask[k]) { ia->bad_mask[k] = TRUE; ia->badcount++; - debug(14, 2) ("ipcacheMarkBadAddr: %s [%s]\n", - name, inet_ntoa(ia->in_addrs[k])); - if (ia->badcount != ia->count) { - /* at least one good address left */ - i->expires = squid_curtime + Config.positiveDnsTtl; - while (ia->bad_mask[ia->cur]) - if (++ia->cur == ia->count) - ia->cur = 0; - return; - } + debug(14, 2) ("ipcacheMarkBadAddr: %s [%s]\n", name, inet_ntoa(addr)); } - if (++ia->cur == ia->count) - ia->cur = 0; + ipcacheCycleAddr(name, ia); } void @@ -955,16 +976,13 @@ ipcacheMarkGoodAddr(const char *name, struct in_addr addr) if (ia->in_addrs[k].s_addr == addr.s_addr) break; } - if (k == (int) ia->count) + if (k == (int) ia->count) /* not found */ return; - i->expires = squid_curtime + Config.positiveDnsTtl; - if (ia->bad_mask[k]) { - ia->bad_mask[k] = FALSE; - ia->badcount--; - i->expires = squid_curtime + Config.positiveDnsTtl; - debug(14, 2) ("ipcacheMarkGoodAddr: %s [%s]\n", - name, inet_ntoa(ia->in_addrs[k])); - } + if (!ia->bad_mask[k]) /* already OK */ + return; + ia->bad_mask[k] = FALSE; + ia->badcount--; + debug(14, 2) ("ipcacheMarkGoodAddr: %s [%s]\n", name, inet_ntoa(addr)); } static void diff --git a/src/protos.h b/src/protos.h index 4959c20921..6e1e904088 100644 --- a/src/protos.h +++ b/src/protos.h @@ -415,7 +415,7 @@ extern void ipcacheShutdownServers(void); extern void ipcache_init(void); extern void stat_ipcache_get(StoreEntry *); extern int ipcacheQueueDrain(void); -extern void ipcacheCycleAddr(const char *name); +extern void ipcacheCycleAddr(const char *name, ipcache_addrs *); extern void ipcacheMarkBadAddr(const char *name, struct in_addr); extern void ipcacheMarkGoodAddr(const char *name, struct in_addr); extern void ipcacheFreeMemory(void);