From: Amos Jeffries Date: Sat, 17 Jan 2009 03:04:27 +0000 (+1300) Subject: Bug 2556: HTCP fails without icp_port X-Git-Tag: SQUID_3_0_STABLE12~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd3e7534f8968f38a49f8a99a13757dcaee37163;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 6a9ce5455d..dd44362ffe 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -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; } /* diff --git a/src/htcp.h b/src/htcp.h index 5f3791462c..094a610cea 100644 --- a/src/htcp.h +++ b/src/htcp.h @@ -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); diff --git a/src/neighbors.cc b/src/neighbors.cc index 12288f29eb..094e342b97 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -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++;