From: Amos Jeffries Date: Tue, 13 Jan 2009 06:17:33 +0000 (+1300) Subject: Bug 2556: HTCP fails without icp_port X-Git-Tag: SQUID_3_2_0_1~1268 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bebf08ff5a2b02fb334ec7b845b0aeafbdd851e8;p=thirdparty%2Fsquid.git Bug 2556: HTCP fails without icp_port 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. --- diff --git a/src/htcp.cc b/src/htcp.cc index 4a7527417a..7b36d5ab87 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -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; } /* @@ -1583,7 +1585,7 @@ htcpClear(StoreEntry * e, const char *uri, HttpRequest * req, const HttpRequestM http_state_flags flags; if (htcpInSocket < 0) - return; + return 0; old_squid_format = p->options.htcp_oldsquid; memset(&flags, '\0', sizeof(flags)); diff --git a/src/htcp.h b/src/htcp.h index 1e8479b1f2..83f63f37f8 100644 --- a/src/htcp.h +++ b/src/htcp.h @@ -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); diff --git a/src/neighbors.cc b/src/neighbors.cc index b984761fad..f1f842c366 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -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++;