]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 2556: HTCP fails without icp_port
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 17 Jan 2009 03:04:27 +0000 (16:04 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 17 Jan 2009 03:04:27 +0000 (16:04 +1300)
Removes requirement for ICP port to be open for peer UDP queries to take
place.

TODO: Some work still needs to be done to separate the timeout from
icp_timeout and break ICP specific query logics out into icp code files.
But that is just cleanup for later.

src/htcp.cc
src/htcp.h
src/neighbors.cc

index 6a9ce5455dd4c9b6ce4f39175fba6988b8ca9d38..dd44362ffebd4f023cfbc1c4cd48b13b67bca73d 100644 (file)
@@ -1553,7 +1553,7 @@ htcpInit(void)
     }
 }
 
-void
+int
 htcpQuery(StoreEntry * e, HttpRequest * req, peer * p)
 {
     cache_key *save_key;
@@ -1567,7 +1567,7 @@ htcpQuery(StoreEntry * e, HttpRequest * req, peer * p)
     http_state_flags flags;
 
     if (htcpInSocket < 0)
-        return;
+        return 0;
 
     old_squid_format = p->options.htcp_oldsquid;
 
@@ -1612,7 +1612,7 @@ htcpQuery(StoreEntry * e, HttpRequest * req, peer * p)
 
     if (!pktlen) {
         debugs(31, 1, "htcpQuery: htcpBuildPacket() failed");
-        return;
+        return -1;
     }
 
     htcpSend(pkt, (int) pktlen, &p->in_addr);
@@ -1621,6 +1621,8 @@ htcpQuery(StoreEntry * e, HttpRequest * req, peer * p)
     storeKeyCopy(save_key, (const cache_key *)e->key);
     queried_addr[stuff.msg_id % N_QUERIED_KEYS] = p->in_addr;
     debugs(31, 3, "htcpQuery: key (" << save_key << ") " << storeKeyText(save_key));
+
+    return 1;
 }
 
 /*
index 5f3791462c3b44e3aeb4872072b632926190d34e..094a610cea0793b0406e8b83e2437ea0d51c7bb8 100644 (file)
@@ -62,7 +62,22 @@ typedef class HtcpReplyData htcpReplyData;
 
 SQUIDCEXTERN void neighborsHtcpReply(const cache_key *, htcpReplyData *, const struct sockaddr_in *);
 SQUIDCEXTERN void htcpInit(void);
-SQUIDCEXTERN void htcpQuery(StoreEntry * e, HttpRequest * req, peer * p);
+
+/**
+ * \ingroup ServerProtocolHTCP
+ *
+ * Generate and Send an HTCP query to the specified peer.
+ *
+ * \param e
+ * \param req
+ * \param p
+ * \retval 1    Successfully sent request.
+ * \retval 0    Unable to send request at this time. HTCP may be shutting down or starting up.
+ *             Don't wait for a reply or count in stats as sent.
+ * \retval -1   Error sending request.
+ */
+SQUIDCEXTERN int htcpQuery(StoreEntry * e, HttpRequest * req, peer * p);
+
 SQUIDCEXTERN void htcpSocketShutdown(void);
 SQUIDCEXTERN void htcpSocketClose(void);
 
index 12288f29eb7f045571854e564a225272bdf6103f..094e342b97a25047660a880f0c67f13b968fb601 100644 (file)
@@ -647,9 +647,6 @@ neighborsUdpPing(HttpRequest * request,
     if (Config.peers == NULL)
         return 0;
 
-    if (theOutIcpConnection < 0)
-        fatal("neighborsUdpPing: There is no ICP socket!");
-
     assert(entry->swap_status == SWAPOUT_NONE);
 
     mem->start_ping = current_time;
@@ -673,9 +670,6 @@ neighborsUdpPing(HttpRequest * request,
 
         debugs(15, 4, "neighborsUdpPing: pinging peer " << p->host << " for '" << url << "'");
 
-        if (p->type == PEER_MULTICAST)
-            mcastSetTtl(theOutIcpConnection, p->mcast.ttl);
-
         debugs(15, 3, "neighborsUdpPing: key = '" << entry->getMD5Text() << "'");
 
         debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum);
@@ -683,34 +677,42 @@ neighborsUdpPing(HttpRequest * request,
 #if USE_HTCP
 
         if (p->options.htcp) {
+            if (Config.Port.htcp <= 0) {
+                debugs(15, DBG_CRITICAL, "HTCP is disabled! Cannot send HTCP request to peer.");
+                continue;
+            }
+
             debugs(15, 3, "neighborsUdpPing: sending HTCP query");
-            htcpQuery(entry, request, p);
+            if (htcpQuery(entry, request, p) <= 0) continue; // unable to send.
         } else
 #endif
-            if (p->icp.port == echo_port) {
-                debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
-                echo_hdr.reqnum = reqnum;
-                query = _icp_common_t::createMessage(ICP_DECHO, 0, url, reqnum, 0);
-                icpUdpSend(theOutIcpConnection,
-                           &p->in_addr,
-                           query,
-                           LOG_ICP_QUERY,
-                           0);
+        {
+            if (Config.Port.icp <= 0 || theOutIcpConnection <= 0) {
+                debugs(15, DBG_CRITICAL, "ICP is disabled! Cannot send ICP request to peer.");
+                continue;
             } else {
-                flags = 0;
 
-                if (Config.onoff.query_icmp)
-                    if (p->icp.version == ICP_VERSION_2)
-                        flags |= ICP_FLAG_SRC_RTT;
+                if (p->type == PEER_MULTICAST)
+                    mcastSetTtl(theOutIcpConnection, p->mcast.ttl);
 
-                query = _icp_common_t::createMessage(ICP_QUERY, flags, url, reqnum, 0);
+                if (p->icp.port == echo_port) {
+                    debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
+                    echo_hdr.reqnum = reqnum;
+                    query = _icp_common_t::createMessage(ICP_DECHO, 0, url, reqnum, 0);
+                    icpUdpSend(theOutIcpConnection, &p->in_addr, query, LOG_ICP_QUERY, 0);
+                } else {
+                    flags = 0;
 
-                icpUdpSend(theOutIcpConnection,
-                           &p->in_addr,
-                           query,
-                           LOG_ICP_QUERY,
-                           0);
+                    if (Config.onoff.query_icmp)
+                        if (p->icp.version == ICP_VERSION_2)
+                            flags |= ICP_FLAG_SRC_RTT;
+
+                    query = _icp_common_t::createMessage(ICP_QUERY, flags, url, reqnum, 0);
+
+                    icpUdpSend(theOutIcpConnection, &p->in_addr, query, LOG_ICP_QUERY, 0);
+                }
             }
+        }
 
         queries_sent++;