]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed 'single parent' and peer->options bugs.
authorwessels <>
Tue, 17 Mar 1998 04:45:00 +0000 (04:45 +0000)
committerwessels <>
Tue, 17 Mar 1998 04:45:00 +0000 (04:45 +0000)
We had mixed (options & FOO) and EBIT_SET(options, FOO) which was
clearly wrong.  Only the EBIT macros can be used with the enumerated
peer->options flags.

We never got any single parent uses because getSingleParent()
was checked only *after* direct == DIRECT_NO.

Removed 'single_parent_bypass' option.  Now, we'll require that
a single parent have the 'no-query' option.

src/cache_cf.cc
src/http.cc
src/neighbors.cc
src/peer_select.cc
src/protos.h
src/structs.h

index 3c2d64e253788430cb65e19af90d38c207ca75ab..f7b4f98e471d3127592984f6d226560fba562848 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.cc,v 1.257 1998/03/07 23:43:01 rousskov Exp $
+ * $Id: cache_cf.cc,v 1.258 1998/03/16 21:45:00 wessels Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -677,21 +677,7 @@ dump_peer(StoreEntry * entry, const char *name, peer * p)
            neighborTypeStr(p),
            p->http_port,
            p->icp_port);
-       if (EBIT_TEST(p->options, NEIGHBOR_PROXY_ONLY))
-           storeAppendPrintf(entry, " proxy-only");
-       if (EBIT_TEST(p->options, NEIGHBOR_NO_QUERY))
-           storeAppendPrintf(entry, " no-query");
-       if (EBIT_TEST(p->options, NEIGHBOR_DEFAULT_PARENT))
-           storeAppendPrintf(entry, " default");
-       if (EBIT_TEST(p->options, NEIGHBOR_ROUNDROBIN))
-           storeAppendPrintf(entry, " round-robin");
-       if (EBIT_TEST(p->options, NEIGHBOR_MCAST_RESPONDER))
-           storeAppendPrintf(entry, " multicast-responder");
-       if (EBIT_TEST(p->options, NEIGHBOR_CLOSEST_ONLY))
-           storeAppendPrintf(entry, " closest-only");
-       if (p->mcast.ttl > 0)
-           storeAppendPrintf(entry, " ttl=%d", p->mcast.ttl);
-       storeAppendPrintf(entry, "\n");
+       dump_peer_options(entry, p);
        p = p->next;
     }
 }
@@ -730,15 +716,15 @@ parse_peer(peer ** head)
     }
     while ((token = strtok(NULL, w_space))) {
        if (!strcasecmp(token, "proxy-only")) {
-           p->options |= NEIGHBOR_PROXY_ONLY;
+           EBIT_SET(p->options, NEIGHBOR_PROXY_ONLY);
        } else if (!strcasecmp(token, "no-query")) {
-           p->options |= NEIGHBOR_NO_QUERY;
+           EBIT_SET(p->options, NEIGHBOR_NO_QUERY);
        } else if (!strcasecmp(token, "multicast-responder")) {
-           p->options |= NEIGHBOR_MCAST_RESPONDER;
+           EBIT_SET(p->options, NEIGHBOR_MCAST_RESPONDER);
        } else if (!strncasecmp(token, "weight=", 7)) {
            p->weight = atoi(token + 7);
        } else if (!strncasecmp(token, "closest-only", 12)) {
-           p->options |= NEIGHBOR_CLOSEST_ONLY;
+           EBIT_SET(p->options, NEIGHBOR_CLOSEST_ONLY);
        } else if (!strncasecmp(token, "ttl=", 4)) {
            p->mcast.ttl = atoi(token + 4);
            if (p->mcast.ttl < 0)
@@ -746,9 +732,9 @@ parse_peer(peer ** head)
            if (p->mcast.ttl > 128)
                p->mcast.ttl = 128;
        } else if (!strncasecmp(token, "default", 7)) {
-           p->options |= NEIGHBOR_DEFAULT_PARENT;
+           EBIT_SET(p->options, NEIGHBOR_DEFAULT_PARENT);
        } else if (!strncasecmp(token, "round-robin", 11)) {
-           p->options |= NEIGHBOR_ROUNDROBIN;
+           EBIT_SET(p->options, NEIGHBOR_ROUNDROBIN);
        } else {
            debug(3, 0) ("parse_peer: token='%s'\n", token);
            self_destruct();
index 73e53ae52fe6dd62add6581c69f45b52d80fc84d..58aa75b48ff37ad96bf1d4b465df0fb429b74575 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: http.cc,v 1.254 1998/03/16 20:11:51 wessels Exp $
+ * $Id: http.cc,v 1.255 1998/03/16 21:45:01 wessels Exp $
  *
  * DEBUG: section 11    Hypertext Transfer Protocol (HTTP)
  * AUTHOR: Harvest Derived
@@ -836,7 +836,7 @@ httpStart(request_t * request, StoreEntry * entry, peer * e)
     Counter.server.all.requests++;
     Counter.server.http.requests++;
     if (e) {
-       if (e->options & NEIGHBOR_PROXY_ONLY)
+       if (EBIT_TEST(e->options, NEIGHBOR_PROXY_ONLY))
            storeReleaseRequest(entry);
        if ((fd = pconnPop(e->host, e->http_port)) >= 0) {
            debug(11, 3) ("httpStart: reusing pconn FD %d\n", fd);
index 0283fb1a892de4672b081ec0818172040c0d184a..66769fb684e15f1a3ec09d074ebcf07e150df54d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: neighbors.cc,v 1.179 1998/03/06 22:53:07 wessels Exp $
+ * $Id: neighbors.cc,v 1.180 1998/03/16 21:45:02 wessels Exp $
  *
  * DEBUG: section 15    Neighbor Routines
  * AUTHOR: Harvest Derived
@@ -223,9 +223,9 @@ peerWouldBePinged(const peer * p, request_t * request)
 {
     if (!peerAllowedToUse(p, request))
        return 0;
-    if (p->options & NEIGHBOR_NO_QUERY)
+    if (EBIT_TEST(p->options, NEIGHBOR_NO_QUERY))
        return 0;
-    if (p->options & NEIGHBOR_MCAST_RESPONDER)
+    if (EBIT_TEST(p->options, NEIGHBOR_MCAST_RESPONDER))
        return 0;
     /* the case below seems strange, but can happen if the
      * URL host is on the other side of a firewall */
@@ -277,6 +277,8 @@ getSingleParent(request_t * request)
            return NULL;        /* oops, found second parent */
        p = q;
     }
+    if (p != NULL && !EBIT_TEST(p->options, NEIGHBOR_NO_QUERY))
+       return NULL;
     debug(15, 3) ("getSingleParent: returning %s\n", p ? p->host : "NULL");
     return p;
 }
@@ -492,9 +494,9 @@ neighborsUdpPing(request_t * request,
 #if ALLOW_SOURCE_PING
     /* only do source_ping if we have neighbors */
     if (Config.npeers) {
-        const ipcache_addrs *ia = NULL;
-        struct sockaddr_in to_addr;
-        char *host = request->host;
+       const ipcache_addrs *ia = NULL;
+       struct sockaddr_in to_addr;
+       char *host = request->host;
        if (!Config.onoff.source_ping) {
            debug(15, 6) ("neighborsUdpPing: Source Ping is disabled.\n");
        } else if ((ia = ipcache_gethostbyname(host, 0))) {
@@ -976,6 +978,26 @@ neighborDumpNonPeers(StoreEntry * sentry)
     dump_peers(sentry, non_peers);
 }
 
+void
+dump_peer_options(StoreEntry * sentry, peer * p)
+{
+    if (EBIT_TEST(p->options, NEIGHBOR_PROXY_ONLY))
+       storeAppendPrintf(sentry, " proxy-only");
+    if (EBIT_TEST(p->options, NEIGHBOR_NO_QUERY))
+       storeAppendPrintf(sentry, " no-query");
+    if (EBIT_TEST(p->options, NEIGHBOR_DEFAULT_PARENT))
+       storeAppendPrintf(sentry, " default");
+    if (EBIT_TEST(p->options, NEIGHBOR_ROUNDROBIN))
+       storeAppendPrintf(sentry, " round-robin");
+    if (EBIT_TEST(p->options, NEIGHBOR_MCAST_RESPONDER))
+       storeAppendPrintf(sentry, " multicast-responder");
+    if (EBIT_TEST(p->options, NEIGHBOR_CLOSEST_ONLY))
+       storeAppendPrintf(sentry, " closest-only");
+    if (p->mcast.ttl > 0)
+       storeAppendPrintf(sentry, " ttl=%d", p->mcast.ttl);
+    storeAppendPrintf(sentry, "\n");
+}
+
 static void
 dump_peers(StoreEntry * sentry, peer * peers)
 {
@@ -992,6 +1014,8 @@ dump_peers(StoreEntry * sentry, peer * peers)
            e->host,
            e->http_port,
            e->icp_port);
+       storeAppendPrintf(sentry, "Flags      :");
+       dump_peer_options(sentry, e);
        for (i = 0; i < e->n_addresses; i++) {
            storeAppendPrintf(sentry, "Address[%d] : %s\n", i,
                inet_ntoa(e->addresses[i]));
index a97f0ba8bb581c5651545fa9f1012195db4f84d7..309c1d2a0aa167bfce3e51cee7c795c2be41361d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: peer_select.cc,v 1.40 1998/03/06 22:53:06 wessels Exp $
+ * $Id: peer_select.cc,v 1.41 1998/03/16 21:45:03 wessels Exp $
  *
  * DEBUG: section 44    Peer Selection Algorithm
  * AUTHOR: Duane Wessels
@@ -95,12 +95,6 @@ peerSelectIcpPing(request_t * request, int direct, StoreEntry * entry)
     assert(direct != DIRECT_YES);
     if (!EBIT_TEST(entry->flag, HIERARCHICAL) && direct != DIRECT_NO)
        return 0;
-    if (Config.onoff.single_parent_bypass)
-#if ALLOW_SOURCE_PING
-       if (!Config.onoff.source_ping)
-#endif
-           if (getSingleParent(request))
-               return 0;
     if (EBIT_TEST(entry->flag, KEY_PRIVATE) && !neighbors_do_private_keys)
        if (direct != DIRECT_NO)
            return 0;
@@ -119,10 +113,6 @@ peerGetSomeParent(request_t * request, hier_code * code)
        *code = DEFAULT_PARENT;
        return p;
     }
-    if ((p = getSingleParent(request))) {
-       *code = SINGLE_PARENT;
-       return p;
-    }
     if ((p = getRoundRobinParent(request))) {
        *code = ROUNDROBIN_PARENT;
        return p;
@@ -306,7 +296,11 @@ peerSelectFoo(ps_state * psstate)
        peerSelectCallback(psstate, NULL);
        return;
     }
-    if (peerSelectIcpPing(request, direct, entry)) {
+    psstate->single_parent = getSingleParent(request);
+    debug(0, 0) ("psstate->single_parent = %p\n", psstate->single_parent);
+    if (psstate->single_parent != NULL) {
+       debug(44, 3) ("peerSelect: found single parent, skipping ICP query\n");
+    } else if (peerSelectIcpPing(request, direct, entry)) {
        assert(entry->ping_status == PING_NONE);
        debug(44, 3) ("peerSelect: Doing ICP pings\n");
        psstate->icp.n_sent = neighborsUdpPing(request,
@@ -341,6 +335,11 @@ peerSelectFoo(ps_state * psstate)
        debug(44, 3) ("peerSelect: %s/%s\n", hier_strings[code], p->host);
        hierarchyNote(&request->hier, code, &psstate->icp, p->host);
        peerSelectCallback(psstate, p);
+    } else if ((p = psstate->single_parent)) {
+       code = SINGLE_PARENT;
+       debug(44, 3) ("peerSelect: %s/%s\n", hier_strings[code], p->host);
+       hierarchyNote(&request->hier, code, &psstate->icp, p->host);
+       peerSelectCallback(psstate, p);
     } else if (direct != DIRECT_NO) {
        code = DIRECT;
        debug(44, 3) ("peerSelect: %s/%s\n", hier_strings[code], request->host);
index 988f056ef3b89a694a112140cee5703dc9b13d97..0076dde48304c2997dc06ed2411dd63b2eba796f 100644 (file)
@@ -283,25 +283,25 @@ extern void httpHdrCcStatDumper(StoreEntry * sentry, int idx, double val, double
 /* Http Range Header Field */
 extern HttpHdrRange *httpHdrRangeParseCreate(const char *range_spec);
 /* returns true if ranges are valid; inits HttpHdrRange */
-extern int httpHdrRangeParseInit(HttpHdrRange *range, const char *range_spec);
-extern void httpHdrRangeDestroy(HttpHdrRange *range);
+extern int httpHdrRangeParseInit(HttpHdrRange * range, const char *range_spec);
+extern void httpHdrRangeDestroy(HttpHdrRange * range);
 extern HttpHdrRange *httpHdrRangeDup(const HttpHdrRange * range);
 extern void httpHdrRangePackInto(const HttpHdrRange * range, Packer * p);
 /* iterate through specs */
-extern int httpHdrRangeGetSpec(const HttpHdrRange *range, HttpHdrRangeSpec *spec, int *pos);
+extern int httpHdrRangeGetSpec(const HttpHdrRange * range, HttpHdrRangeSpec * spec, int *pos);
 
 /* Http Content Range Header Field */
 extern HttpHdrContRange *httpHdrContRangeParseCreate(const char *crange_spec);
 /* returns true if range is valid; inits HttpHdrContRange */
-extern int httpHdrContRangeParseInit(HttpHdrContRange *crange, const char *crange_spec);
-extern void httpHdrContRangeDestroy(HttpHdrContRange *crange);
+extern int httpHdrContRangeParseInit(HttpHdrContRange * crange, const char *crange_spec);
+extern void httpHdrContRangeDestroy(HttpHdrContRange * crange);
 extern HttpHdrContRange *httpHdrContRangeDup(const HttpHdrContRange * crange);
 extern void httpHdrContRangePackInto(const HttpHdrContRange * crange, Packer * p);
 
 /* Http Header Tools */
 extern HttpHeaderFieldInfo *httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs * attrs, int count);
-extern void httpHeaderDestroyFieldsInfo(HttpHeaderFieldInfo *info, int count);
-extern int httpHeaderIdByName(const char *name, int name_len, const HttpHeaderFieldInfo* attrs, int end, int mask);
+extern void httpHeaderDestroyFieldsInfo(HttpHeaderFieldInfo * info, int count);
+extern int httpHeaderIdByName(const char *name, int name_len, const HttpHeaderFieldInfo * attrs, int end, int mask);
 extern int httpHeaderCalcMask(const int *enums, int count);
 extern int strListGetItem(const char *str, char del, const char **item, int *ilen, const char **pos);
 extern const char *getStringPrefix(const char *str);
@@ -317,7 +317,7 @@ extern void httpHeaderInit(HttpHeader * hdr);
 extern void httpHeaderClean(HttpHeader * hdr);
 extern void httpHeaderDestroy(HttpHeader * hdr);
 /* clone */
-void httpHeaderCopy(HttpHeader *dest, const HttpHeader *src);
+void httpHeaderCopy(HttpHeader * dest, const HttpHeader * src);
 /* parse/pack */
 extern int httpHeaderParse(HttpHeader * hdr, const char *header_start, const char *header_end);
 extern void httpHeaderPackInto(const HttpHeader * hdr, Packer * p);
@@ -495,6 +495,7 @@ extern int neighborUp(const peer * e);
 extern void peerDestroy(peer * e);
 extern char *neighborTypeStr(const peer * e);
 extern void peerCheckConnectStart(peer *);
+extern void dump_peer_options(StoreEntry *, peer *);
 
 extern void netdbInit(void);
 
@@ -572,7 +573,7 @@ extern void memInitModule();
 extern void memCleanModule();
 extern void memConfigure();
 extern void *memAllocate(mem_type);
-extern void *memAllocBuf(size_t net_size, size_t *gross_size);
+extern void *memAllocBuf(size_t net_size, size_t * gross_size);
 extern void memFree(mem_type, void *);
 extern void memFreeBuf(size_t size, void *);
 extern void memFree4K(void *);
@@ -802,7 +803,7 @@ extern void PrintRusage(void);
 extern void dumpMallocStats(void);
 
 extern void pumpInit(int fd, request_t * r, char *uri);
-extern void pumpStart(int, StoreEntry *, request_t *, CWCB *callback, void *);
+extern void pumpStart(int, StoreEntry *, request_t *, CWCB * callback, void *);
 extern int pumpMethod(method_t method);
 extern int pumpRestart(request_t *);
 
@@ -863,12 +864,12 @@ extern void gb_flush(gb_t *);     /* internal, do not use this */
 #define strSet(s,ptr,ch) (s).buf[ptr-(s).buf] = (ch)
 #define strCut(s,pos) (s).buf[pos] = '\0'
 /* #define strCat(s,str)  stringAppend(&(s), (str), strlen(str)+1) */
-extern void stringInit(String *s, const char *str);
-extern void stringLimitInit(String *s, const char *str, int len);
-extern String stringDup(const String *s);
-extern void stringClean(String *s);
-extern void stringReset(String *s, const char *str);
-extern void stringAppend(String *s, const char *buf, int len);
+extern void stringInit(String * s, const char *str);
+extern void stringLimitInit(String * s, const char *str, int len);
+extern String stringDup(const String * s);
+extern void stringClean(String * s);
+extern void stringReset(String * s, const char *str);
+extern void stringAppend(String * s, const char *buf, int len);
 /* extern void stringAppendf(String *s, const char *fmt, ...); */
 
 /*
index a4536ecad368ce0fbae7420fb90f8bd44f48ef1d..cdd47158fdfebc05a2501c6ad7f2668ac789a48e 100644 (file)
@@ -48,8 +48,8 @@ struct _acl_arp_data {
 
 struct _String {
     /* never reference these directly! */
-    unsigned short int size; /* buffer size; 64K limit */
-    unsigned short int len;  /* current length  */
+    unsigned short int size;   /* buffer size; 64K limit */
+    unsigned short int len;    /* current length  */
     char *buf;
 };
 
@@ -480,8 +480,8 @@ struct _HttpBody {
 
 /* http header extention field */
 struct _HttpHdrExtField {
-    String name;  /* field-name  from HTTP/1.1 (no column after name) */
-    String value; /* field-value from HTTP/1.1 */
+    String name;               /* field-name  from HTTP/1.1 (no column after name) */
+    String value;              /* field-value from HTTP/1.1 */
 };
 
 /* http cache control header field */
@@ -507,7 +507,7 @@ struct _HttpHdrRange {
 /* http content-range header field */
 struct _HttpHdrContRange {
     HttpHdrRangeSpec spec;
-    size_t elength; /* entity length, not content length */
+    size_t elength;            /* entity length, not content length */
 };
 
 
@@ -848,6 +848,7 @@ struct _ps_state {
     void *callback_data;
     peer *first_parent_miss;
     peer *closest_parent_miss;
+    peer *single_parent;
     icp_ping_data icp;
     aclCheck_t *acl_checklist;
 };
@@ -1009,7 +1010,7 @@ struct _request_t {
     char login[MAX_LOGIN_SZ];
     char host[SQUIDHOSTNAMELEN + 1];
     u_short port;
-#if 0 /* trying new interface */
+#if 0                          /* trying new interface */
     char urlpath[MAX_URL];
 #else
     String urlpath;