]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 2556: HTCP fails without icp_port
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 16 Jan 2009 15:10:39 +0000 (04:10 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 16 Jan 2009 15:10:39 +0000 (04:10 +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 4a7527417a152e76d5d41f195654a85e3442b4f9..be50df166ad7f857c40af079fe93e29cef423fa2 100644 (file)
@@ -1516,7 +1516,7 @@ htcpInit(void)
     }
 }
 
-void
+int
 htcpQuery(StoreEntry * e, HttpRequest * req, peer * p)
 {
     cache_key *save_key;
@@ -1530,7 +1530,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;
     memset(&flags, '\0', sizeof(flags));
@@ -1555,7 +1555,7 @@ htcpQuery(StoreEntry * e, HttpRequest * req, peer * p)
     mb.clean();
     if (!pktlen) {
         debugs(31, 3, "htcpQuery: htcpBuildPacket() failed");
-        return;
+        return -1;
     }
 
     htcpSend(pkt, (int) pktlen, p->in_addr);
@@ -1565,6 +1565,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 1e8479b1f284d168a9b6c03664429e53710174fa..83f63f37f83e8d1ed637773224a5f10a53b6fe42 100644 (file)
@@ -64,8 +64,20 @@ SQUIDCEXTERN void neighborsHtcpReply(const cache_key *, htcpReplyData *, const I
 /// \ingroup ServerProtocolHTCP
 SQUIDCEXTERN void htcpInit(void);
 
-/// \ingroup ServerProtocolHTCP
-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);
 
 /// \ingroup ServerProtocolHTCP
 SQUIDCEXTERN void htcpClear(StoreEntry * e, const char *uri, HttpRequest * req, const HttpRequestMethod &method, peer * p, htcp_clr_reason reason);
index b984761fad9c077b242bf613ba85ce9408aed72d..f1f842c366ed6f212b35bab2d2743745c413b192 100644 (file)
@@ -635,9 +635,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;
@@ -661,43 +658,48 @@ 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);
 
 #if USE_HTCP
         if (p->options.htcp && !p->options.htcp_only_clr) {
+            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);
+
+                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;
+
+                    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);
+                    query = _icp_common_t::createMessage(ICP_QUERY, flags, url, reqnum, 0);
 
-                icpUdpSend(theOutIcpConnection,
-                           p->in_addr,
-                           query,
-                           LOG_ICP_QUERY,
-                           0);
+                    icpUdpSend(theOutIcpConnection, p->in_addr, query, LOG_ICP_QUERY, 0);
+                }
             }
+        }
 
         queries_sent++;