neighbors.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 15 Neighbor Routines */
10
11#include "squid.h"
12#include "acl/FilledChecklist.h"
13#include "anyp/PortCfg.h"
14#include "base/EnumIterator.h"
15#include "base/IoManip.h"
16#include "base/PackableStream.h"
17#include "CacheDigest.h"
18#include "CachePeer.h"
19#include "CachePeers.h"
20#include "comm/Connection.h"
21#include "comm/ConnOpener.h"
22#include "debug/Messages.h"
23#include "event.h"
24#include "FwdState.h"
25#include "globals.h"
26#include "htcp.h"
27#include "HttpRequest.h"
28#include "icmp/net_db.h"
29#include "ICP.h"
30#include "int.h"
31#include "ip/Address.h"
32#include "ip/tools.h"
33#include "ipcache.h"
34#include "MemObject.h"
35#include "mgr/Registration.h"
36#include "multicast.h"
37#include "neighbors.h"
39#include "pconn.h"
40#include "PeerDigest.h"
41#include "PeerPoolMgr.h"
42#include "PeerSelectState.h"
43#include "RequestFlags.h"
44#include "SquidConfig.h"
45#include "SquidMath.h"
46#include "stat.h"
47#include "Store.h"
48#include "store_key_md5.h"
49#include "tools.h"
50
51/* count mcast group peers every 15 minutes */
52#define MCAST_COUNT_RATE 900
53
55static int peerWouldBePinged(const CachePeer *, PeerSelector *);
56static void neighborAlive(CachePeer *, const MemObject *, const icp_common_t *);
57#if USE_HTCP
58static void neighborAliveHtcp(CachePeer *, const MemObject *, const HtcpReplyData *);
59#endif
60static void neighborCountIgnored(CachePeer *);
61static void peerRefreshDNS(void *);
63static void peerProbeConnect(CachePeer *, const bool reprobeIfBusy = false);
65static void peerCountMcastPeersDone(void *data);
66static void peerCountMcastPeersStart(void *data);
67static void peerCountMcastPeersSchedule(CachePeer * p, time_t when);
71
72static void neighborIgnoreNonPeer(const Ip::Address &, icp_opcode);
74static void dump_peers(StoreEntry *, CachePeers *);
75
76static unsigned short echo_port;
77
78static int NLateReplies = 0;
79
80const char *
82{
83 if (p->type == PEER_NONE)
84 return "Non-Peer";
85
86 if (p->type == PEER_SIBLING)
87 return "Sibling";
88
89 if (p->type == PEER_MULTICAST)
90 return "Multicast Group";
91
92 return "Parent";
93}
94
97{
98 int j;
99
100 debugs(15, 3, "whichPeer: from " << from);
101
102 for (const auto &p: CurrentCachePeers()) {
103 for (j = 0; j < p->n_addresses; ++j) {
104 if (from == p->addresses[j] && from.port() == p->icp.port) {
105 return p.get();
106 }
107 }
108 }
109
110 return nullptr;
111}
112
113peer_t
114neighborType(const CachePeer * p, const AnyP::Uri &url)
115{
116
117 const NeighborTypeDomainList *d = nullptr;
118
119 for (d = p->typelist; d; d = d->next) {
120 if (0 == matchDomainName(url.host(), d->domain))
121 if (d->type != PEER_NONE)
122 return d->type;
123 }
124#if PEER_MULTICAST_SIBLINGS
125 if (p->type == PEER_MULTICAST)
126 if (p->options.mcast_siblings)
127 return PEER_SIBLING;
128#endif
129
130 return p->type;
131}
132
136bool
138{
139 assert(ps);
140 HttpRequest *request = ps->request;
141 assert(request != nullptr);
142
143 if (neighborType(p, request->url) == PEER_SIBLING) {
144#if PEER_MULTICAST_SIBLINGS
145 if (p->type == PEER_MULTICAST && p->options.mcast_siblings &&
146 (request->flags.noCache || request->flags.refresh || request->flags.loopDetected || request->flags.needValidation))
147 debugs(15, 2, "multicast-siblings optimization match for " << *p << ", " << request->url.authority());
148#endif
149 if (request->flags.noCache)
150 return false;
151
152 if (request->flags.refresh)
153 return false;
154
155 if (request->flags.loopDetected)
156 return false;
157
158 if (request->flags.needValidation)
159 return false;
160 }
161
162 // CONNECT requests are proxy requests. Not to be forwarded to origin servers.
163 // Unless the destination port matches, in which case we MAY perform a 'DIRECT' to this CachePeer.
164 if (p->options.originserver && request->method == Http::METHOD_CONNECT && request->url.port() != p->http_port)
165 return false;
166
167 if (p->access == nullptr)
168 return true;
169
170 ACLFilledChecklist checklist(p->access, request, nullptr);
171 checklist.al = ps->al;
172 if (ps->al && ps->al->reply) {
173 checklist.reply = ps->al->reply.getRaw();
174 HTTPMSGLOCK(checklist.reply);
175 }
176 checklist.syncAle(request, nullptr);
177 return checklist.fastCheck().allowed();
178}
179
180/* Return TRUE if it is okay to send an ICP request to this CachePeer. */
181static int
183{
184 assert(ps);
185 HttpRequest *request = ps->request;
186
187 if (p->icp.port == 0)
188 return 0;
189
190 if (p->options.no_query)
191 return 0;
192
194 return 0;
195
196 if (p->n_addresses == 0)
197 return 0;
198
200 return 0;
201
202 /* the case below seems strange, but can happen if the
203 * URL host is on the other side of a firewall */
204 if (p->type == PEER_SIBLING)
205 if (!request->flags.hierarchical)
206 return 0;
207
208 if (!peerAllowedToUse(p, ps))
209 return 0;
210
211 /* Ping dead peers every timeout interval */
213 return 1;
214
215 if (!neighborUp(p))
216 return 0;
217
218 return 1;
219}
220
221bool
223{
224 const int effectiveLimit = p->max_conn <= 0 ? Squid_MaxFD : p->max_conn;
225 const int remaining = effectiveLimit - p->stats.conn_open;
226 debugs(15, 7, remaining << '=' << effectiveLimit << '-' << p->stats.conn_open);
227 return remaining > 0;
228}
229
230bool
232{
233 // Standby connections can be used without opening new connections.
234 const int standbys = p->standby.pool ? p->standby.pool->count() : 0;
235
236 // XXX: Some idle pconns can be used without opening new connections.
237 // Complication: Idle pconns cannot be reused for some requests.
238 const int usableIdles = 0;
239
240 const int available = standbys + usableIdles;
241 debugs(15, 7, available << '=' << standbys << '+' << usableIdles);
242 return available > 0;
243}
244
245void
247{
248 --p->stats.conn_open;
250 p->standby.waitingForClose = false;
251 PeerPoolMgr::Checkpoint(p->standby.mgr, "conn closed");
252 }
253}
254
255/* Return TRUE if it is okay to send an HTTP request to this CachePeer. */
256int
258{
260 return 0;
261
262 if (!peerAllowedToUse(p, ps))
263 return 0;
264
265 if (!neighborUp(p))
266 return 0;
267
268 return 1;
269}
270
271int
273{
274 int count = 0;
275
276 for (const auto &p: CurrentCachePeers())
277 if (peerWouldBePinged(p.get(), ps))
278 ++count;
279
280 debugs(15, 3, "neighborsCount: " << count);
281
282 return count;
283}
284
285CachePeer *
287{
288 assert(ps);
289 HttpRequest *request = ps->request;
290
291 CachePeer *p = nullptr;
292
293 for (const auto &peer: CurrentCachePeers()) {
294 p = peer.get();
295
296 if (!neighborUp(p))
297 continue;
298
299 if (neighborType(p, request->url) != PEER_PARENT)
300 continue;
301
302 if (!peerHTTPOkay(p, ps))
303 continue;
304
305 break;
306 }
307
308 debugs(15, 3, "returning " << RawPointer(p).orNil());
309 return p;
310}
311
312CachePeer *
314{
315 assert(ps);
316 HttpRequest *request = ps->request;
317
318 CachePeer *q = nullptr;
319
320 for (const auto &peer: CurrentCachePeers()) {
321 const auto p = peer.get();
322 if (!p->options.roundrobin)
323 continue;
324
325 if (neighborType(p, request->url) != PEER_PARENT)
326 continue;
327
328 if (!peerHTTPOkay(p, ps))
329 continue;
330
331 if (p->weight == 0)
332 continue;
333
334 if (q) {
335 if (p->weight == q->weight) {
336 if (q->rr_count < p->rr_count)
337 continue;
338 } else if ( ((double) q->rr_count / q->weight) < ((double) p->rr_count / p->weight)) {
339 continue;
340 }
341 }
342
343 q = p;
344 }
345
346 if (q)
347 ++ q->rr_count;
348
349 debugs(15, 3, "returning " << RawPointer(q).orNil());
350
351 return q;
352}
353
354CachePeer *
356{
357 assert(ps);
358 HttpRequest *request = ps->request;
359
360 CachePeer *q = nullptr;
361 int weighted_rtt;
362
363 for (const auto &peer: CurrentCachePeers()) {
364 const auto p = peer.get();
365
366 if (!p->options.weighted_roundrobin)
367 continue;
368
369 if (neighborType(p, request->url) != PEER_PARENT)
370 continue;
371
372 if (!peerHTTPOkay(p, ps))
373 continue;
374
375 if (q && q->rr_count < p->rr_count)
376 continue;
377
378 q = p;
379 }
380
381 if (q && q->rr_count > 1000000)
382 for (const auto &p: CurrentCachePeers()) {
383 if (!p->options.weighted_roundrobin)
384 continue;
385
386 if (neighborType(p.get(), request->url) != PEER_PARENT)
387 continue;
388
389 p->rr_count = 0;
390 }
391
392 if (q) {
393 weighted_rtt = (q->stats.rtt - q->basetime) / q->weight;
394
395 if (weighted_rtt < 1)
396 weighted_rtt = 1;
397
398 q->rr_count += weighted_rtt;
399
400 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt);
401 }
402
403 debugs(15, 3, "returning " << RawPointer(q).orNil());
404 return q;
405}
406
418static void
420{
421 peerClearRR();
422 eventAdd("peerClearRR", peerClearRRLoop, data, 5 * 60.0, 0);
423}
424
430void
432{
433 static bool event_added = false;
434 if (!event_added) {
435 peerClearRRLoop(nullptr);
436 event_added=true;
437 }
438}
439
447void
449{
450 for (const auto &p: CurrentCachePeers())
451 p->rr_count = 1;
452}
453
454void
456{
457 if (p->stats.logged_state == PEER_DEAD && p->tcp_up) {
458 debugs(15, DBG_IMPORTANT, "Detected REVIVED " << neighborTypeStr(p) << ": " << *p);
460 peerClearRR();
461 if (p->standby.mgr.valid())
462 PeerPoolMgr::Checkpoint(p->standby.mgr, "revived peer");
463 }
464
466 p->stats.probe_start = 0;
467
468 // TODO: Remove or explain how we could detect an alive peer without IP addresses
469 if (!p->n_addresses)
471}
472
473CachePeer *
475{
476 assert(ps);
477 HttpRequest *request = ps->request;
478
479 for (const auto &peer: CurrentCachePeers()) {
480 const auto p = peer.get();
481
482 if (neighborType(p, request->url) != PEER_PARENT)
483 continue;
484
485 if (!p->options.default_parent)
486 continue;
487
488 if (!peerHTTPOkay(p, ps))
489 continue;
490
491 debugs(15, 3, "returning " << *p);
492
493 return p;
494 }
495
496 // TODO: Refactor similar get*() functions to use our return/reporting style
497 debugs(15, 3, "none found");
498 return nullptr;
499}
500
501static void
503{
504 Mgr::RegisterAction("server_list",
505 "Peer Cache Statistics",
506 neighborDumpPeers, 0, 1);
507}
508
509void
511{
512 struct servent *sep = nullptr;
513 const char *me = getMyHostname();
514
516
518 RawCachePeers peersToRemove;
519
520 for (const auto &thisPeer: CurrentCachePeers()) {
521 if (0 != strcmp(thisPeer->host, me))
522 continue;
523
524 for (AnyP::PortCfgPointer s = HttpPortList; s != nullptr; s = s->next) {
525 if (thisPeer->http_port != s->s.port())
526 continue;
527
528 debugs(15, DBG_IMPORTANT, "WARNING: Peer looks like this host." <<
529 Debug::Extra << "Ignoring cache_peer " << *thisPeer);
530
531 peersToRemove.push_back(thisPeer.get());
532 break; // avoid warning about (and removing) the same CachePeer twice
533 }
534 }
535
536 while (peersToRemove.size()) {
537 const auto p = peersToRemove.back();
538 peersToRemove.pop_back();
540 }
541 }
542
543 peerRefreshDNS((void *) 1);
544
545 sep = getservbyname("echo", "udp");
546 echo_port = sep ? ntohs((unsigned short) sep->s_port) : 7;
547}
548
549int
551 StoreEntry * entry,
552 IRCB * callback,
553 PeerSelector *ps,
554 int *exprep,
555 int *timeout)
556{
557 const char *url = entry->url();
558 MemObject *mem = entry->mem_obj;
559 int reqnum = 0;
560 int flags;
561 int peers_pinged = 0;
562 int parent_timeout = 0, parent_exprep = 0;
563 int sibling_timeout = 0, sibling_exprep = 0;
564 int mcast_timeout = 0, mcast_exprep = 0;
565
566 if (Config.peers == nullptr)
567 return 0;
568
569 assert(!entry->hasDisk());
570
572
573 mem->ping_reply_callback = callback;
574
575 mem->ircb_data = ps;
576
577 reqnum = icpSetCacheKey((const cache_key *)entry->key);
578
579 for (size_t i = 0; i < Config.peers->size(); ++i) {
580 const auto p = &Config.peers->nextPeerToPing(i);
581
582 debugs(15, 5, "candidate: " << *p);
583
584 if (!peerWouldBePinged(p, ps))
585 continue; /* next CachePeer */
586
587 ++peers_pinged;
588
589 debugs(15, 4, "pinging cache_peer " << *p << " for '" << url << "'");
590
591 debugs(15, 3, "neighborsUdpPing: key = '" << entry->getMD5Text() << "'");
592
593 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum);
594
595#if USE_HTCP
596 if (p->options.htcp && !p->options.htcp_only_clr) {
597 if (Config.Port.htcp <= 0) {
598 debugs(15, DBG_CRITICAL, "ERROR: HTCP is disabled! Cannot send HTCP request to peer.");
599 continue;
600 }
601
602 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
603 if (htcpQuery(entry, request, p) <= 0)
604 continue; // unable to send.
605 } else
606#endif
607 {
609 debugs(15, DBG_CRITICAL, "ERROR: ICP is disabled! Cannot send ICP request to peer.");
610 continue;
611 } else {
612
613 if (p->type == PEER_MULTICAST)
614 mcastSetTtl(icpOutgoingConn->fd, p->mcast.ttl);
615
616 if (p->icp.port == echo_port) {
617 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
618 // TODO: Get ALE from callback_data if possible.
619 icpCreateAndSend(ICP_DECHO, 0, url, reqnum, 0,
620 icpOutgoingConn->fd, p->in_addr, nullptr);
621 } else {
622 flags = 0;
623
625 if (p->icp.version == ICP_VERSION_2)
626 flags |= ICP_FLAG_SRC_RTT;
627
628 // TODO: Get ALE from callback_data if possible.
629 icpCreateAndSend(ICP_QUERY, flags, url, reqnum, 0,
630 icpOutgoingConn->fd, p->in_addr, nullptr);
631 }
632 }
633 }
634
635 ++ p->stats.pings_sent;
636
637 if (p->type == PEER_MULTICAST) {
638 mcast_exprep += p->mcast.n_replies_expected;
639 mcast_timeout += (p->stats.rtt * p->mcast.n_replies_expected);
640 } else if (neighborUp(p)) {
641 /* its alive, expect a reply from it */
642
643 if (neighborType(p, request->url) == PEER_PARENT) {
644 ++parent_exprep;
645 parent_timeout += p->stats.rtt;
646 } else {
647 ++sibling_exprep;
648 sibling_timeout += p->stats.rtt;
649 }
650 } else {
651 /* Neighbor is dead; ping it anyway, but don't expect a reply */
652 /* log it once at the threshold */
653
654 if (p->stats.logged_state == PEER_ALIVE) {
655 debugs(15, DBG_IMPORTANT, "Detected DEAD " << neighborTypeStr(p) << ": " << *p);
656 p->stats.logged_state = PEER_DEAD;
657 }
658 }
659
660 p->stats.last_query = squid_curtime;
661
662 /*
663 * keep probe_start == 0 for a multicast CachePeer,
664 * so neighborUp() never says this CachePeer is dead.
665 */
666
667 if ((p->type != PEER_MULTICAST) && (p->stats.probe_start == 0))
668 p->stats.probe_start = squid_curtime;
669 }
670
671 /*
672 * How many replies to expect?
673 */
674 *exprep = parent_exprep + sibling_exprep + mcast_exprep;
675
676 /*
677 * If there is a configured timeout, use it
678 */
680 *timeout = Config.Timeout.icp_query;
681 else {
682 if (*exprep > 0) {
683 if (parent_exprep)
684 *timeout = 2 * parent_timeout / parent_exprep;
685 else if (mcast_exprep)
686 *timeout = 2 * mcast_timeout / mcast_exprep;
687 else
688 *timeout = 2 * sibling_timeout / sibling_exprep;
689 } else
690 *timeout = 2000; /* 2 seconds */
691
693 if (*timeout > Config.Timeout.icp_query_max)
694 *timeout = Config.Timeout.icp_query_max;
695
696 if (*timeout < Config.Timeout.icp_query_min)
697 *timeout = Config.Timeout.icp_query_min;
698 }
699
700 return peers_pinged;
701}
702
703/* lookup the digest of a given CachePeer */
706{
707#if USE_CACHE_DIGESTS
708 assert(ps);
709 HttpRequest *request = ps->request;
710 const cache_key *key = request ? storeKeyPublicByRequest(request) : nullptr;
711 assert(p);
712 assert(request);
713 debugs(15, 5, "cache_peer " << *p);
714 /* does the peeer have a valid digest? */
715
716 if (!p->digest) {
717 debugs(15, 5, "peerDigestLookup: gone!");
718 return LOOKUP_NONE;
719 } else if (!peerHTTPOkay(p, ps)) {
720 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
721 return LOOKUP_NONE;
722 } else if (!p->digest->flags.needed) {
723 debugs(15, 5, "peerDigestLookup: note need");
725 return LOOKUP_NONE;
726 } else if (!p->digest->flags.usable) {
727 debugs(15, 5, "peerDigestLookup: !ready && " << (p->digest->flags.requested ? "" : "!") << "requested");
728 return LOOKUP_NONE;
729 }
730
731 debugs(15, 5, "OK to lookup cache_peer " << *p);
732 assert(p->digest->cd);
733 /* does digest predict a hit? */
734
735 if (!p->digest->cd->contains(key))
736 return LOOKUP_MISS;
737
738 debugs(15, 5, "HIT for cache_peer " << *p);
739
740 return LOOKUP_HIT;
741#else
742 (void)p;
743 (void)ps;
744#endif
745
746 return LOOKUP_NONE;
747}
748
749/* select best CachePeer based on cache digests */
750CachePeer *
752{
753 CachePeer *best_p = nullptr;
754#if USE_CACHE_DIGESTS
755 assert(ps);
756 HttpRequest *request = ps->request;
757
758 int best_rtt = 0;
759 int choice_count = 0;
760 int ichoice_count = 0;
761 int p_rtt;
762
763 if (!Config.peers)
764 return nullptr;
765
766 if (!request->flags.hierarchical)
767 return nullptr;
768
770
771 for (size_t i = 0; i < Config.peers->size(); ++i) {
772 const auto p = &Config.peers->nextPeerToPing(i);
773
774 const auto lookup = peerDigestLookup(p, ps);
775
776 if (lookup == LOOKUP_NONE)
777 continue;
778
779 ++choice_count;
780
781 if (lookup == LOOKUP_MISS)
782 continue;
783
784 p_rtt = netdbHostRtt(p->host);
785
786 debugs(15, 5, "cache_peer " << *p << " rtt: " << p_rtt);
787
788 /* is this CachePeer better than others in terms of rtt ? */
789 if (!best_p || (p_rtt && p_rtt < best_rtt)) {
790 best_p = p;
791 best_rtt = p_rtt;
792
793 if (p_rtt) /* informative choice (aka educated guess) */
794 ++ichoice_count;
795
796 debugs(15, 4, "cache_peer " << *p << " leads with rtt " << best_rtt);
797 }
798 }
799
800 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count << " (" << ichoice_count << ")");
801 peerNoteDigestLookup(request, best_p,
802 best_p ? LOOKUP_HIT : (choice_count ? LOOKUP_MISS : LOOKUP_NONE));
803 request->hier.n_choices = choice_count;
804 request->hier.n_ichoices = ichoice_count;
805#else
806 (void)ps;
807#endif
808
809 return best_p;
810}
811
812void
814{
815#if USE_CACHE_DIGESTS
816 if (p)
817 strncpy(request->hier.cd_host, p->host, sizeof(request->hier.cd_host)-1);
818 else
819 *request->hier.cd_host = '\0';
820
821 request->hier.cd_lookup = lookup;
822 debugs(15, 4, "cache_peer " << RawPointer(p).orNil() << ", lookup: " << lookup_t_str[lookup]);
823#else
824 (void)request;
825 (void)p;
826 (void)lookup;
827#endif
828}
829
830static void
831neighborAlive(CachePeer * p, const MemObject *, const icp_common_t * header)
832{
833 peerAlive(p);
834 ++ p->stats.pings_acked;
835
836 if ((icp_opcode) header->opcode <= ICP_END)
837 ++ p->icp.counts[header->opcode];
838
839 p->icp.version = (int) header->version;
840}
841
842static void
844{
845 int rtt, rtt_av_factor;
846
847 if (!mem)
848 return;
849
850 if (!mem->start_ping.tv_sec)
851 return;
852
853 rtt = tvSubMsec(mem->start_ping, current_time);
854
855 if (rtt < 1 || rtt > 10000)
856 return;
857
858 rtt_av_factor = RTT_AV_FACTOR;
859
861 rtt_av_factor = RTT_BACKGROUND_AV_FACTOR;
862
863 p->stats.rtt = Math::intAverage(p->stats.rtt, rtt, p->stats.pings_acked, rtt_av_factor);
864}
865
866#if USE_HTCP
867static void
869{
870 peerAlive(p);
871 ++ p->stats.pings_acked;
872 ++ p->htcp.counts[htcp->hit ? 1 : 0];
873 p->htcp.version = htcp->version;
874}
875
876#endif
877
878static void
880{
881 if (p == nullptr)
882 return;
883
885
886 ++NLateReplies;
887}
888
889static void
891{
892 static uint64_t ignoredReplies = 0;
893 if (isPowTen(++ignoredReplies)) {
894 debugs(15, DBG_IMPORTANT, "WARNING: Ignored " << ignoredReplies << " ICP replies from non-peers" <<
895 Debug::Extra << "last seen non-peer source address: " << from <<
896 Debug::Extra << "last seen ICP reply opcode: " << icp_opcode_str[opcode]);
897 }
898}
899
900/* ignoreMulticastReply
901 *
902 * * We want to ignore replies from multicast peers if the
903 * * cache_host_domain rules would normally prevent the CachePeer
904 * * from being used
905 */
906static int
908{
909 if (p == nullptr)
910 return 0;
911
912 if (!p->options.mcast_responder)
913 return 0;
914
915 if (peerHTTPOkay(p, ps))
916 return 0;
917
918 return 1;
919}
920
928void
929neighborsUdpAck(const cache_key * key, icp_common_t * header, const Ip::Address &from)
930{
931 CachePeer *p = nullptr;
932 StoreEntry *entry;
933 MemObject *mem = nullptr;
934 peer_t ntype = PEER_NONE;
935 icp_opcode opcode = (icp_opcode) header->opcode;
936
937 debugs(15, 6, "neighborsUdpAck: opcode " << opcode << " '" << storeKeyText(key) << "'");
938
939 if ((entry = Store::Root().findCallbackXXX(key)))
940 mem = entry->mem_obj;
941
942 if ((p = whichPeer(from)))
943 neighborAlive(p, mem, header);
944
945 if (opcode > ICP_END)
946 return;
947
948 const char *opcode_d = icp_opcode_str[opcode];
949
950 if (p)
951 neighborUpdateRtt(p, mem);
952
953 /* Does the entry exist? */
954 if (nullptr == entry) {
955 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key) << "' not found");
957 return;
958 }
959
960 /* check if someone is already fetching it */
961 if (EBIT_TEST(entry->flags, ENTRY_DISPATCHED)) {
962 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key) << "' already being fetched.");
964 return;
965 }
966
967 if (mem == nullptr) {
968 debugs(15, 2, "Ignoring " << opcode_d << " for missing mem_obj: " << storeKeyText(key));
970 return;
971 }
972
973 if (entry->ping_status != PING_WAITING) {
974 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d << " for " << storeKeyText(key));
976 return;
977 }
978
979 if (!entry->locked()) {
980 // TODO: many entries are unlocked; why is this reported at level 1?
981 debugs(12, DBG_IMPORTANT, "neighborsUdpAck: '" << storeKeyText(key) << "' has no locks");
983 return;
984 }
985
986 if (!mem->ircb_data) {
987 debugs(12, DBG_IMPORTANT, "ERROR: Squid BUG: missing ICP callback data for " << *entry);
989 return;
990 }
991
992 debugs(15, 3, opcode_d << " for " << storeKeyText(key) << " from " << RawPointer(p).orNil("source"));
993
994 if (p) {
995 ntype = neighborType(p, mem->request->url);
996 }
997
998 if (ignoreMulticastReply(p, mem->ircb_data)) {
1000 } else if (opcode == ICP_MISS) {
1001 if (p == nullptr) {
1002 neighborIgnoreNonPeer(from, opcode);
1003 } else {
1004 mem->ping_reply_callback(p, ntype, AnyP::PROTO_ICP, header, mem->ircb_data);
1005 }
1006 } else if (opcode == ICP_HIT) {
1007 if (p == nullptr) {
1008 neighborIgnoreNonPeer(from, opcode);
1009 } else {
1010 header->opcode = ICP_HIT;
1011 mem->ping_reply_callback(p, ntype, AnyP::PROTO_ICP, header, mem->ircb_data);
1012 }
1013 } else if (opcode == ICP_DECHO) {
1014 if (p == nullptr) {
1015 neighborIgnoreNonPeer(from, opcode);
1016 } else if (ntype == PEER_SIBLING) {
1017 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1018 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1019 } else {
1020 mem->ping_reply_callback(p, ntype, AnyP::PROTO_ICP, header, mem->ircb_data);
1021 }
1022 } else if (opcode == ICP_SECHO) {
1023 if (p) {
1024 debugs(15, DBG_IMPORTANT, "Ignoring SECHO from neighbor " << *p);
1026 } else {
1027 debugs(15, DBG_IMPORTANT, "Unsolicited SECHO from " << from);
1028 }
1029 } else if (opcode == ICP_DENIED) {
1030 if (p == nullptr) {
1031 neighborIgnoreNonPeer(from, opcode);
1032 } else if (p->stats.pings_acked > 100) {
1033 if (100 * p->icp.counts[ICP_DENIED] / p->stats.pings_acked > 95) {
1034 debugs(15, DBG_CRITICAL, "Disabling cache_peer " << *p <<
1035 " because over 95% of its replies are UDP_DENIED");
1037 p = nullptr;
1038 } else {
1040 }
1041 }
1042 } else if (opcode == ICP_MISS_NOFETCH) {
1043 mem->ping_reply_callback(p, ntype, AnyP::PROTO_ICP, header, mem->ircb_data);
1044 } else {
1045 debugs(15, DBG_CRITICAL, "ERROR: neighborsUdpAck: Unexpected ICP reply: " << opcode_d);
1046 }
1047}
1048
1049CachePeer *
1050findCachePeerByName(const char * const name)
1051{
1052 for (const auto &p: CurrentCachePeers()) {
1053 if (!strcasecmp(name, p->name))
1054 return p.get();
1055 }
1056 return nullptr;
1057}
1058
1059int
1061{
1062 if (!p->tcp_up) {
1063 // TODO: When CachePeer gets its own CodeContext, pass that context instead of nullptr
1064 CallService(nullptr, [&] {
1065 peerProbeConnect(const_cast<CachePeer*>(p));
1066 });
1067 return 0;
1068 }
1069
1070 /*
1071 * The CachePeer can not be UP if we don't have any IP addresses
1072 * for it.
1073 */
1074 if (0 == p->n_addresses) {
1075 debugs(15, 8, "DOWN (no-ip): " << *p);
1076 return 0;
1077 }
1078
1079 if (p->options.no_query) {
1080 debugs(15, 8, "UP (no-query): " << *p);
1081 return 1;
1082 }
1083
1084 if (p->stats.probe_start != 0 &&
1086 debugs(15, 8, "DOWN (dead): " << *p);
1087 return 0;
1088 }
1089
1090 debugs(15, 8, "UP: " << *p);
1091 return 1;
1092}
1093
1094time_t
1095positiveTimeout(const time_t timeout)
1096{
1097 return max(static_cast<time_t>(1), timeout);
1098}
1099
1100static void
1102{
1103 // TODO: connections to no-longer valid IP addresses should be
1104 // closed when we can detect such IP addresses.
1105
1106 CachePeer *p = (CachePeer *)data;
1107
1108 if (p->n_addresses == 0) {
1109 debugs(15, Important(29), "Configuring " << neighborTypeStr(p) << " " << *p);
1110
1111 if (p->type == PEER_MULTICAST)
1112 debugs(15, DBG_IMPORTANT, " Multicast TTL = " << p->mcast.ttl);
1113 }
1114
1115 p->n_addresses = 0;
1116
1117 if (ia == nullptr) {
1118 debugs(0, DBG_CRITICAL, "WARNING: DNS lookup for '" << *p << "' failed!");
1119 return;
1120 }
1121
1122 if (ia->empty()) {
1123 debugs(0, DBG_CRITICAL, "WARNING: No IP address found for '" << *p << "'!");
1124 return;
1125 }
1126
1127 for (const auto &ip: ia->goodAndBad()) { // TODO: Consider using just good().
1129 const auto idx = p->n_addresses++;
1130 p->addresses[idx] = ip;
1131 debugs(15, 2, "--> IP address #" << idx << ": " << p->addresses[idx]);
1132 } else {
1133 debugs(15, 3, "ignoring remaining " << (ia->size() - p->n_addresses) << " ips");
1134 break;
1135 }
1136 }
1137
1138 p->in_addr.setEmpty();
1139 p->in_addr = p->addresses[0];
1140 p->in_addr.port(p->icp.port);
1141
1142 peerProbeConnect(p, true); // detect any died or revived peers ASAP
1143
1144 if (p->type == PEER_MULTICAST)
1146
1147#if USE_ICMP
1148 if (p->type != PEER_MULTICAST && IamWorkerProcess())
1149 if (!p->options.no_netdb_exchange)
1150 eventAddIsh("netdbExchangeStart", netdbExchangeStart, p, 30.0, 1);
1151#endif
1152
1153 if (p->standby.mgr.valid())
1154 PeerPoolMgr::Checkpoint(p->standby.mgr, "resolved peer");
1155}
1156
1157static void
1159{
1160 if (eventFind(peerRefreshDNS, nullptr))
1161 eventDelete(peerRefreshDNS, nullptr);
1162
1163 if (!data && 0 == stat5minClientRequests()) {
1164 /* no recent client traffic, wait a bit */
1165 eventAddIsh("peerRefreshDNS", peerRefreshDNS, nullptr, 180.0, 1);
1166 return;
1167 }
1168
1169 for (const auto &p: CurrentCachePeers())
1170 ipcache_nbgethostbyname(p->host, peerDNSConfigure, p.get());
1171
1172 /* Reconfigure the peers every hour */
1173 eventAddIsh("peerRefreshDNS", peerRefreshDNS, nullptr, 3600.0, 1);
1174}
1175
1177static bool
1179{
1180 if (p->testing_now > 0) {
1181 debugs(15, 8, "yes, probing " << p);
1182 return true;
1183 }
1184 if (squid_curtime - p->stats.last_connect_probe == 0) {
1185 debugs(15, 8, "yes, just probed " << p);
1186 return true;
1187 }
1188 return false;
1189}
1190/*
1191* peerProbeConnect will be called on dead peers by neighborUp
1192*/
1193static void
1194peerProbeConnect(CachePeer *p, const bool reprobeIfBusy)
1195{
1196 if (peerProbeIsBusy(p)) {
1197 p->reprobe = reprobeIfBusy;
1198 return;
1199 }
1200 p->reprobe = false;
1201
1202 const auto ctimeout = p->connectTimeout();
1203 /* for each IP address of this CachePeer. find one that we can connect to and probe it. */
1204 for (int i = 0; i < p->n_addresses; ++i) {
1206 conn->remote = p->addresses[i];
1207 conn->remote.port(p->http_port);
1208 conn->setPeer(p);
1209 getOutgoingAddress(nullptr, conn);
1210
1211 ++ p->testing_now;
1212
1213 AsyncCall::Pointer call = commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone, p));
1214 Comm::ConnOpener *cs = new Comm::ConnOpener(conn, call, ctimeout);
1215 cs->setHost(p->host);
1216 AsyncJob::Start(cs);
1217 }
1218
1220}
1221
1222static void
1224{
1225 CachePeer *p = (CachePeer*)data;
1226
1227 if (status == Comm::OK)
1228 p->noteSuccess();
1229 else
1231
1232 -- p->testing_now;
1233 conn->close();
1234 // TODO: log this traffic.
1235
1236 if (p->reprobe)
1238}
1239
1240static void
1242{
1244 return;
1245
1246 eventAdd("peerCountMcastPeersStart",
1248 p,
1249 (double) when, 1);
1250
1252}
1253
1254static void
1256{
1257 const auto peer = static_cast<CachePeer*>(data);
1258 CallContextCreator([peer] {
1260 });
1262}
1263
1265static void
1267{
1268 // XXX: Do not create lots of complex fake objects (while abusing their
1269 // APIs) to pass around a few basic data points like start_ping and ping!
1270 MemObject *mem;
1271 int reqnum;
1272 // TODO: use class AnyP::Uri instead of constructing and re-parsing a string
1273 LOCAL_ARRAY(char, url, MAX_URL);
1274 assert(p->type == PEER_MULTICAST);
1275 p->mcast.flags.count_event_pending = false;
1276 snprintf(url, MAX_URL, "http://");
1277 p->in_addr.toUrl(url+7, MAX_URL -8 );
1278 strcat(url, "/");
1279 const auto mx = MasterXaction::MakePortless<XactionInitiator::initPeerMcast>();
1280 auto *req = HttpRequest::FromUrlXXX(url, mx);
1281 assert(req != nullptr);
1283 ale->request = req;
1284 CodeContext::Reset(ale);
1286 const auto psstate = new PeerSelector(nullptr);
1287 psstate->request = req;
1288 HTTPMSGLOCK(psstate->request);
1289 psstate->entry = fake;
1290 psstate->peerCountMcastPeerXXX = cbdataReference(p);
1291 psstate->ping.start = current_time;
1292 psstate->al = ale;
1293 mem = fake->mem_obj;
1294 mem->request = psstate->request;
1295 mem->start_ping = current_time;
1297 mem->ircb_data = psstate;
1299 p->mcast.id = mem->id;
1300 reqnum = icpSetCacheKey((const cache_key *)fake->key);
1301 icpCreateAndSend(ICP_QUERY, 0, url, reqnum, 0,
1302 icpOutgoingConn->fd, p->in_addr, psstate->al);
1303 fake->ping_status = PING_WAITING; // TODO: refactor to use PeerSelector::startPingWaiting()
1304 eventAdd("peerCountMcastPeersDone",
1306 psstate,
1307 Config.Timeout.mcast_icp_query / 1000.0, 1);
1308 p->mcast.flags.counting = true;
1309}
1310
1311static void
1313{
1314 const auto psstate = static_cast<PeerSelector*>(data);
1315 CallBack(psstate->al, [psstate] {
1316 peerCountMcastPeersAbort(psstate);
1317 delete psstate;
1318 });
1319}
1320
1323static void
1325{
1326 StoreEntry *fake = psstate->entry;
1327
1329 CachePeer *p = (CachePeer *)psstate->peerCountMcastPeerXXX;
1330 p->mcast.flags.counting = false;
1332 debugs(15, DBG_IMPORTANT, "Group " << *p << ": " << psstate->ping.n_recv <<
1333 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1334 p->mcast.avg_n_members <<" average, RTT " << p->stats.rtt);
1336 }
1337
1339
1340 fake->abort(); // sets ENTRY_ABORTED and initiates related cleanup
1341 fake->mem_obj->request = nullptr;
1342 fake->unlock("peerCountMcastPeersDone");
1343}
1344
1345static void
1347{
1348 const auto psstate = static_cast<PeerSelector*>(data);
1349 StoreEntry *fake = psstate->entry;
1350 assert(fake);
1351 MemObject *mem = fake->mem_obj;
1352 assert(mem);
1353 int rtt = tvSubMsec(mem->start_ping, current_time);
1354 assert(proto == AnyP::PROTO_ICP);
1355 ++ psstate->ping.n_recv;
1356 int rtt_av_factor = RTT_AV_FACTOR;
1357
1359 rtt_av_factor = RTT_BACKGROUND_AV_FACTOR;
1360
1361 p->stats.rtt = Math::intAverage(p->stats.rtt, rtt, psstate->ping.n_recv, rtt_av_factor);
1362}
1363
1364static void
1366{
1367 dump_peers(sentry, Config.peers);
1368}
1369
1370void
1372{
1373 PackableStream os(*sentry);
1374
1375 if (p->options.proxy_only)
1376 os << " proxy-only";
1377
1378 if (p->options.no_query)
1379 os << " no-query";
1380
1381 if (p->options.background_ping)
1382 os << " background-ping";
1383
1384 if (p->options.no_digest)
1385 os << " no-digest";
1386
1387 if (p->options.default_parent)
1388 os << " default";
1389
1390 if (p->options.roundrobin)
1391 os << " round-robin";
1392
1393 if (p->options.carp)
1394 os << " carp";
1395
1396#if USE_AUTH
1397 if (p->options.userhash)
1398 os << " userhash";
1399#endif
1400
1401 if (p->options.sourcehash)
1402 os << " sourcehash";
1403
1405 os << " weighted-round-robin";
1406
1407 if (p->options.mcast_responder)
1408 os << " multicast-responder";
1409
1410#if PEER_MULTICAST_SIBLINGS
1411 if (p->options.mcast_siblings)
1412 os << " multicast-siblings";
1413#endif
1414
1415 if (p->weight != 1)
1416 os << " weight=" << p->weight;
1417
1418 if (p->options.closest_only)
1419 os << " closest-only";
1420
1421#if USE_HTCP
1422 if (p->options.htcp) {
1423 os << " htcp";
1425 bool doneopts = false;
1426 if (p->options.htcp_oldsquid) {
1427 os << (doneopts ? ',' : '=') << "oldsquid";
1428 doneopts = true;
1429 }
1430 if (p->options.htcp_no_clr) {
1431 os << (doneopts ? ',' : '=') << "no-clr";
1432 doneopts = true;
1433 }
1434 if (p->options.htcp_no_purge_clr) {
1435 os << (doneopts ? ',' : '=') << "no-purge-clr";
1436 doneopts = true;
1437 }
1438 if (p->options.htcp_only_clr) {
1439 os << (doneopts ? ',' : '=') << "only-clr";
1440 //doneopts = true; // uncomment if more opts are added
1441 }
1442 }
1443 }
1444#endif
1445
1447 os << " no-netdb-exchange";
1448
1449#if USE_DELAY_POOLS
1450 if (p->options.no_delay)
1451 os << " no-delay";
1452#endif
1453
1454 if (p->login)
1455 os << " login=" << p->login;
1456
1457 if (p->mcast.ttl > 0)
1458 os << " ttl=" << p->mcast.ttl;
1459
1460 if (p->connect_timeout_raw > 0)
1461 os << " connect-timeout=" << p->connect_timeout_raw;
1462
1464 os << " connect-fail-limit=" << p->connect_fail_limit;
1465
1466#if USE_CACHE_DIGESTS
1467
1468 if (p->digest_url)
1469 os << " digest-url=" << p->digest_url;
1470
1471#endif
1472
1473 if (p->options.allow_miss)
1474 os << " allow-miss";
1475
1476 if (p->options.no_tproxy)
1477 os << " no-tproxy";
1478
1479 if (p->max_conn > 0)
1480 os << " max-conn=" << p->max_conn;
1481
1482 if (p->standby.limit > 0)
1483 os << " standby=" << p->standby.limit;
1484
1485 if (p->options.originserver)
1486 os << " originserver";
1487
1488 if (p->domain)
1489 os << " forceddomain=" << p->domain;
1490
1491 if (p->connection_auth == 0)
1492 os << " connection-auth=off";
1493 else if (p->connection_auth == 1)
1494 os << " connection-auth=on";
1495 else if (p->connection_auth == 2)
1496 os << " connection-auth=auto";
1497
1498 p->secure.dumpCfg(os, "tls-");
1499 os << '\n';
1500}
1501
1502static void
1504{
1505 char ntoabuf[MAX_IPSTRLEN];
1506 int i;
1507
1508 if (!peers) {
1509 storeAppendPrintf(sentry, "There are no neighbors installed.\n");
1510 return;
1511 }
1512
1513 for (const auto &peer: *peers) {
1514 const auto e = peer.get();
1515 assert(e->host != nullptr);
1516 storeAppendPrintf(sentry, "\n%-11.11s: %s\n",
1517 neighborTypeStr(e),
1518 e->name);
1519 storeAppendPrintf(sentry, "Host : %s/%d/%d\n",
1520 e->host,
1521 e->http_port,
1522 e->icp.port);
1523 storeAppendPrintf(sentry, "Flags :");
1524 dump_peer_options(sentry, e);
1525
1526 for (i = 0; i < e->n_addresses; ++i) {
1527 storeAppendPrintf(sentry, "Address[%d] : %s\n", i,
1528 e->addresses[i].toStr(ntoabuf,MAX_IPSTRLEN) );
1529 }
1530
1531 storeAppendPrintf(sentry, "Status : %s\n",
1532 neighborUp(e) ? "Up" : "Down");
1533 storeAppendPrintf(sentry, "FETCHES : %d\n", e->stats.fetches);
1534 storeAppendPrintf(sentry, "OPEN CONNS : %d\n", e->stats.conn_open);
1535 storeAppendPrintf(sentry, "AVG RTT : %d msec\n", e->stats.rtt);
1536
1537 if (!e->options.no_query) {
1538 storeAppendPrintf(sentry, "LAST QUERY : %8d seconds ago\n",
1539 (int) (squid_curtime - e->stats.last_query));
1540
1541 if (e->stats.last_reply > 0)
1542 storeAppendPrintf(sentry, "LAST REPLY : %8d seconds ago\n",
1543 (int) (squid_curtime - e->stats.last_reply));
1544 else
1545 storeAppendPrintf(sentry, "LAST REPLY : none received\n");
1546
1547 storeAppendPrintf(sentry, "PINGS SENT : %8d\n", e->stats.pings_sent);
1548
1549 storeAppendPrintf(sentry, "PINGS ACKED: %8d %3d%%\n",
1550 e->stats.pings_acked,
1551 Math::intPercent(e->stats.pings_acked, e->stats.pings_sent));
1552 }
1553
1554 storeAppendPrintf(sentry, "IGNORED : %8d %3d%%\n", e->stats.ignored_replies, Math::intPercent(e->stats.ignored_replies, e->stats.pings_acked));
1555
1556 if (!e->options.no_query) {
1557 storeAppendPrintf(sentry, "Histogram of PINGS ACKED:\n");
1558#if USE_HTCP
1559
1560 if (e->options.htcp) {
1561 storeAppendPrintf(sentry, "\tMisses\t%8d %3d%%\n",
1562 e->htcp.counts[0],
1563 Math::intPercent(e->htcp.counts[0], e->stats.pings_acked));
1564 storeAppendPrintf(sentry, "\tHits\t%8d %3d%%\n",
1565 e->htcp.counts[1],
1566 Math::intPercent(e->htcp.counts[1], e->stats.pings_acked));
1567 } else {
1568#endif
1569
1570 for (auto op : WholeEnum<icp_opcode>()) {
1571 if (e->icp.counts[op] == 0)
1572 continue;
1573
1574 storeAppendPrintf(sentry, " %12.12s : %8d %3d%%\n",
1575 icp_opcode_str[op],
1576 e->icp.counts[op],
1577 Math::intPercent(e->icp.counts[op], e->stats.pings_acked));
1578 }
1579
1580#if USE_HTCP
1581
1582 }
1583
1584#endif
1585
1586 }
1587
1588 if (e->stats.last_connect_failure) {
1589 storeAppendPrintf(sentry, "Last failed connect() at: %s\n",
1590 Time::FormatHttpd(e->stats.last_connect_failure));
1591 }
1592
1593 storeAppendPrintf(sentry, "keep-alive ratio: %d%%\n", Math::intPercent(e->stats.n_keepalives_recv, e->stats.n_keepalives_sent));
1594 }
1595}
1596
1597#if USE_HTCP
1598void
1600{
1602 MemObject *mem = nullptr;
1603 CachePeer *p;
1604 peer_t ntype = PEER_NONE;
1605 debugs(15, 6, "neighborsHtcpReply: " <<
1606 (htcp->hit ? "HIT" : "MISS") << " " <<
1607 storeKeyText(key) );
1608
1609 if (nullptr != e)
1610 mem = e->mem_obj;
1611
1612 if ((p = whichPeer(from)))
1613 neighborAliveHtcp(p, mem, htcp);
1614
1615 /* Does the entry exist? */
1616 if (nullptr == e) {
1617 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key) << "' not found");
1619 return;
1620 }
1621
1622 /* check if someone is already fetching it */
1623 if (EBIT_TEST(e->flags, ENTRY_DISPATCHED)) {
1624 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key) << "' already being fetched.");
1626 return;
1627 }
1628
1629 if (mem == nullptr) {
1630 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key));
1632 return;
1633 }
1634
1635 if (e->ping_status != PING_WAITING) {
1636 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key) << " is not PING_WAITING");
1638 return;
1639 }
1640
1641 if (!e->locked()) {
1642 // TODO: many entries are unlocked; why is this reported at level 1?
1643 debugs(12, DBG_IMPORTANT, "neighborsUdpAck: '" << storeKeyText(key) << "' has no locks");
1645 return;
1646 }
1647
1648 if (!mem->ircb_data) {
1649 debugs(12, DBG_IMPORTANT, "ERROR: Squid BUG: missing HTCP callback data for " << *e);
1651 return;
1652 }
1653
1654 if (p) {
1655 ntype = neighborType(p, mem->request->url);
1656 neighborUpdateRtt(p, mem);
1657 }
1658
1659 if (ignoreMulticastReply(p, mem->ircb_data)) {
1661 return;
1662 }
1663
1664 debugs(15, 3, "neighborsHtcpReply: e = " << e);
1665 // TODO: Refactor (ping_reply_callback,ircb_data) to add CodeContext.
1666 mem->ping_reply_callback(p, ntype, AnyP::PROTO_HTCP, htcp, mem->ircb_data);
1667}
1668
1669/*
1670 * Send HTCP CLR messages to all peers configured to receive them.
1671 */
1672void
1674{
1675 char buf[128];
1676
1677 for (const auto &p: CurrentCachePeers()) {
1678 if (!p->options.htcp) {
1679 continue;
1680 }
1681 if (p->options.htcp_no_clr) {
1682 continue;
1683 }
1684 if (p->options.htcp_no_purge_clr && reason == HTCP_CLR_PURGE) {
1685 continue;
1686 }
1687 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p->in_addr.toUrl(buf, 128));
1688 htcpClear(e, req, method, p.get(), reason);
1689 }
1690}
1691
1692#endif
1693
const CachePeers & CurrentCachePeers()
Definition: CachePeers.cc:41
void DeleteConfigured(CachePeer *const peer)
destroys the given peer after removing it from the set of configured peers
Definition: CachePeers.cc:51
std::vector< CachePeer *, PoolingAllocator< CachePeer * > > RawCachePeers
Temporary, local storage of raw pointers to zero or more Config.peers.
Definition: CachePeers.h:66
void CallContextCreator(Fun &&creator)
Definition: CodeContext.h:148
void CallService(const CodeContext::Pointer &serviceContext, Fun &&service)
Definition: CodeContext.h:133
void CallBack(const CodeContext::Pointer &callbackContext, Fun &&callback)
Definition: CodeContext.h:116
CommCbFunPtrCallT< Dialer > * commCbCall(int debugSection, int debugLevel, const char *callName, const Dialer &dialer)
Definition: CommCalls.h:312
void CNCB(const Comm::ConnectionPointer &conn, Comm::Flag status, int xerrno, void *data)
Definition: CommCalls.h:33
void getOutgoingAddress(HttpRequest *request, const Comm::ConnectionPointer &conn)
Definition: FwdState.cc:1476
RawPointerT< Pointer > RawPointer(const char *label, const Pointer &ptr)
convenience wrapper for creating RawPointerT<> objects
Definition: IoManip.h:43
time_t squid_curtime
Definition: stub_libtime.cc:20
AnyP::PortCfgPointer HttpPortList
list of Squid http(s)_port configured
Definition: PortCfg.cc:22
class SquidConfig Config
Definition: SquidConfig.cc:12
int conn
the current server connection FD
Definition: Transport.cc:26
int matchDomainName(const char *h, const char *d, MatchDomainNameFlags flags)
Definition: Uri.cc:820
#define assert(EX)
Definition: assert.h:17
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:265
#define cbdataReferenceDone(var)
Definition: cbdata.h:352
#define cbdataReference(var)
Definition: cbdata.h:343
Acl::Answer const & fastCheck()
Definition: Checklist.cc:332
AccessLogEntry::Pointer al
info for the future access.log, and external ACL
void syncAle(HttpRequest *adaptedRequest, const char *logUri) const override
assigns uninitialized adapted_request and url ALE components
HttpReplyPointer reply
HttpRequest * request
bool allowed() const
Definition: Acl.h:156
Definition: Uri.h:31
SBuf & authority(bool requirePort=false) const
Definition: Uri.cc:646
void port(const Port p)
reset authority port subcomponent
Definition: Uri.h:95
void host(const char *src)
Definition: Uri.cc:100
static void Start(const Pointer &job)
Definition: AsyncJob.cc:37
bool contains(const cache_key *key) const
Definition: CacheDigest.cc:93
CbcPointer< PeerPoolMgr > mgr
pool manager
Definition: CachePeer.h:211
acl_access * access
Definition: CachePeer.h:105
bool closest_only
Definition: CachePeer.h:116
int weight
Definition: CachePeer.h:151
bool no_tproxy
Definition: CachePeer.h:144
void noteSuccess()
reacts to a successful establishment of a connection to this cache_peer
Definition: CachePeer.cc:61
bool htcp_oldsquid
Definition: CachePeer.h:119
struct CachePeer::@28 options
bool no_query
Definition: CachePeer.h:109
NeighborTypeDomainList * typelist
Definition: CachePeer.h:104
int basetime
Definition: CachePeer.h:152
bool originserver
Definition: CachePeer.h:143
time_t probe_start
Definition: CachePeer.h:79
bool background_ping
Definition: CachePeer.h:110
peer_t type
Definition: CachePeer.h:67
bool roundrobin
Definition: CachePeer.h:113
int n_addresses
Definition: CachePeer.h:181
int connection_auth
0 - off, 1 - on, 2 - auto
Definition: CachePeer.h:224
unsigned short http_port
Definition: CachePeer.h:103
bool proxy_only
Definition: CachePeer.h:108
int logged_state
so we can print dead/revived msgs
Definition: CachePeer.h:84
char * login
Definition: CachePeer.h:203
time_t last_connect_probe
Definition: CachePeer.h:83
bool htcp_no_purge_clr
Definition: CachePeer.h:121
char * host
Definition: CachePeer.h:65
Security::PeerOptions secure
security settings for peer connection
Definition: CachePeer.h:219
time_t connect_timeout_raw
connect_timeout; use connectTimeout() instead!
Definition: CachePeer.h:204
bool mcast_siblings
Definition: CachePeer.h:146
char * domain
Forced domain.
Definition: CachePeer.h:216
int limit
the limit itself
Definition: CachePeer.h:212
time_t last_query
Definition: CachePeer.h:80
PeerDigest * digest
Definition: CachePeer.h:168
int n_replies_expected
Definition: CachePeer.h:157
struct CachePeer::@29 mcast
int tcp_up
Definition: CachePeer.h:175
bool counting
Definition: CachePeer.h:163
int rtt
Definition: CachePeer.h:75
bool no_digest
Definition: CachePeer.h:111
Ip::Address in_addr
Definition: CachePeer.h:69
PconnPool * pool
idle connection pool for this peer
Definition: CachePeer.h:210
int rr_count
Definition: CachePeer.h:182
bool waitingForClose
a conn must close before we open a standby conn
Definition: CachePeer.h:213
bool sourcehash
Definition: CachePeer.h:142
int connect_fail_limit
Definition: CachePeer.h:205
double avg_n_members
Definition: CachePeer.h:155
int n_times_counted
Definition: CachePeer.h:156
struct CachePeer::icp_ icp
struct CachePeer::@26 stats
time_t last_reply
Definition: CachePeer.h:81
int pings_acked
Definition: CachePeer.h:73
bool no_netdb_exchange
Definition: CachePeer.h:125
int max_conn
Definition: CachePeer.h:206
struct CachePeer::@33 standby
optional "cache_peer standby=limit" feature
bool htcp_only_clr
Definition: CachePeer.h:122
time_t connectTimeout() const
Definition: CachePeer.cc:119
struct CachePeer::@29::@35 flags
int counts[2]
Definition: CachePeer.h:98
bool count_event_pending
Definition: CachePeer.h:162
Ip::Address addresses[10]
Definition: CachePeer.h:180
bool userhash
Definition: CachePeer.h:140
int conn_open
current opened connections
Definition: CachePeer.h:85
int testing_now
Definition: CachePeer.h:183
bool default_parent
Definition: CachePeer.h:112
bool carp
Definition: CachePeer.h:130
bool reprobe
whether to do another TCP probe after current TCP probes
Definition: CachePeer.h:178
bool allow_miss
Definition: CachePeer.h:129
struct CachePeer::@27 htcp
char * digest_url
Definition: CachePeer.h:169
int ignored_replies
Definition: CachePeer.h:76
double version
Definition: CachePeer.h:97
void noteFailure(Http::StatusCode code)
Definition: CachePeer.cc:73
bool mcast_responder
Definition: CachePeer.h:115
bool weighted_roundrobin
Definition: CachePeer.h:114
bool htcp_no_clr
Definition: CachePeer.h:120
bool no_delay
Definition: CachePeer.h:127
cache_peer configuration storage
Definition: CachePeers.h:21
CachePeer & nextPeerToPing(size_t iteration)
Definition: CachePeers.cc:14
auto size() const
the number of currently stored (i.e. added and not removed) cache_peers
Definition: CachePeers.h:33
Cbc * valid() const
was set and is valid
Definition: CbcPointer.h:41
static void Reset()
forgets the current context, setting it to nil/unknown
Definition: CodeContext.cc:77
void setHost(const char *)
set the hostname note for this connection
Definition: ConnOpener.cc:100
static std::ostream & Extra(std::ostream &)
Definition: debug.cc:1313
size_t size() const noexcept
all cached IPs
Definition: ipcache.h:62
IpsSelector< IpsIterator > goodAndBad() const
all IPs
Definition: ipcache.h:249
bool empty() const noexcept
whether we cached no IPs at all
Definition: ipcache.h:61
encapsulates DNS lookup results
Definition: LookupDetails.h:23
char cd_host[SQUIDHOSTNAMELEN]
double version
Definition: htcp.h:33
int hit
Definition: htcp.h:30
HttpRequestMethod method
Definition: HttpRequest.h:114
static HttpRequest * FromUrlXXX(const char *url, const MasterXaction::Pointer &, const HttpRequestMethod &method=Http::METHOD_GET)
Definition: HttpRequest.cc:528
HierarchyLogEntry hier
Definition: HttpRequest.h:157
RequestFlags flags
Definition: HttpRequest.h:141
AnyP::Uri url
the request URI
Definition: HttpRequest.h:115
void setEmpty()
Fast reset of the stored content to what would be after default constructor.
Definition: Address.cc:184
char * toUrl(char *buf, unsigned int len) const
Definition: Address.cc:874
unsigned short port() const
Definition: Address.cc:778
IRCB * ping_reply_callback
Definition: MemObject.h:215
HttpRequestPointer request
Definition: MemObject.h:212
struct timeval start_ping
Definition: MemObject.h:214
PeerSelector * ircb_data
Definition: MemObject.h:216
representation of a neighbor_type_domain configuration directive. A POD
NeighborTypeDomainList * next
void count(int uses)
bool requested
Definition: PeerDigest.h:90
bool usable
Definition: PeerDigest.h:89
bool needed
Definition: PeerDigest.h:88
CacheDigest * cd
Definition: PeerDigest.h:83
struct PeerDigest::@84 flags
static void Checkpoint(const Pointer &mgr, const char *reason)
Definition: PeerPoolMgr.cc:229
HttpRequest * request
AccessLogEntry::Pointer al
info for the future access.log entry
void * peerCountMcastPeerXXX
a hack to help peerCountMcastPeersStart()
ping_data ping
StoreEntry * entry
C * getRaw() const
Definition: RefCount.h:89
bool needValidation
Definition: RequestFlags.h:50
bool loopDetected
Definition: RequestFlags.h:40
bool hierarchical
Definition: RequestFlags.h:38
virtual void dumpCfg(std::ostream &, const char *pfx) const
output squid.conf syntax with 'pfx' prefix on parameters for the stored settings
Definition: PeerOptions.cc:105
struct SquidConfig::@94 Port
time_t deadPeer
Definition: SquidConfig.h:124
int mcast_icp_query
Definition: SquidConfig.h:129
struct SquidConfig::@106 onoff
int icp_query_max
Definition: SquidConfig.h:127
CachePeers * peers
Definition: SquidConfig.h:247
int icp_query_min
Definition: SquidConfig.h:128
unsigned short icp
Definition: SquidConfig.h:141
struct SquidConfig::@93 Timeout
time_t backgroundPingRate
Definition: SquidConfig.h:108
unsigned short htcp
Definition: SquidConfig.h:144
uint16_t flags
Definition: Store.h:232
int locked() const
Definition: Store.h:146
int unlock(const char *context)
Definition: store.cc:455
const char * url() const
Definition: store.cc:1552
bool hasDisk(const sdirno dirn=-1, const sfileno filen=-1) const
Definition: store.cc:1915
const char * getMD5Text() const
Definition: store.cc:206
MemObject * mem_obj
Definition: Store.h:221
ping_status_t ping_status
Definition: Store.h:242
void abort()
Definition: store.cc:1063
StoreEntry * findCallbackXXX(const cache_key *)
Definition: Controller.cc:395
unsigned char version
Definition: ICP.h:40
unsigned char opcode
Definition: ICP.h:38
int n_recv
Definition: PingData.h:39
A const & max(A const &lhs, A const &rhs)
#define Important(id)
Definition: Messages.h:93
#define DBG_IMPORTANT
Definition: Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define DBG_CRITICAL
Definition: Stream.h:37
#define RTT_BACKGROUND_AV_FACTOR
Definition: defines.h:83
#define PEER_TCP_MAGIC_COUNT
Definition: defines.h:124
#define PEER_MAX_ADDRESSES
Definition: defines.h:81
#define ICP_FLAG_SRC_RTT
Definition: defines.h:41
#define PEER_ALIVE
Definition: defines.h:86
#define PEER_DEAD
Definition: defines.h:85
#define ICP_VERSION_2
Definition: defines.h:44
#define EBIT_TEST(flag, bit)
Definition: defines.h:69
#define RTT_AV_FACTOR
Definition: defines.h:82
#define MAX_URL
Definition: defines.h:78
@ PING_WAITING
Sent ICP queries to peers and still awaiting responses.
Definition: enums.h:43
htcp_clr_reason
Definition: enums.h:240
@ HTCP_CLR_PURGE
Definition: enums.h:241
peer_t
Definition: enums.h:27
@ PEER_SIBLING
Definition: enums.h:29
@ PEER_PARENT
Definition: enums.h:30
@ PEER_NONE
Definition: enums.h:28
@ PEER_MULTICAST
Definition: enums.h:31
@ ENTRY_DISPATCHED
Definition: enums.h:101
void eventAddIsh(const char *name, EVH *func, void *arg, double delta_ish, int weight)
Definition: event.cc:114
int eventFind(EVH *func, void *arg)
Definition: event.cc:145
void eventDelete(EVH *func, void *arg)
Definition: event.cc:127
void eventAdd(const char *name, EVH *func, void *arg, double when, int weight, bool cbdata)
Definition: event.cc:107
int Squid_MaxFD
void ipcache_nbgethostbyname(const char *name, IPH *handler, void *handlerData)
Definition: ipcache.cc:608
int icpSetCacheKey(const cache_key *key)
Definition: icp_v2.cc:861
void icpCreateAndSend(icp_opcode, int flags, char const *url, int reqnum, int pad, int fd, const Ip::Address &from, AccessLogEntryPointer)
Definition: icp_v2.cc:418
icp_opcode
Definition: icp_opcode.h:13
@ ICP_DECHO
Definition: icp_opcode.h:26
@ ICP_QUERY
Definition: icp_opcode.h:16
@ ICP_MISS_NOFETCH
Definition: icp_opcode.h:36
@ ICP_END
Definition: icp_opcode.h:39
@ ICP_DENIED
Definition: icp_opcode.h:37
@ ICP_SECHO
Definition: icp_opcode.h:25
@ ICP_MISS
Definition: icp_opcode.h:18
@ ICP_HIT
Definition: icp_opcode.h:17
Comm::ConnectionPointer icpOutgoingConn
Definition: icp_v2.cc:101
Comm::ConnectionPointer icpIncomingConn
Definition: icp_v2.cc:99
int htcpQuery(StoreEntry *e, HttpRequest *req, CachePeer *p)
Definition: htcp.cc:1515
void htcpClear(StoreEntry *e, HttpRequest *req, const HttpRequestMethod &, CachePeer *p, htcp_clr_reason reason)
Definition: htcp.cc:1564
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:161
const char * icp_opcode_str[]
int isPowTen(int count)
Definition: int.cc:17
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
Definition: forward.h:25
void IPH(const ipcache_addrs *, const Dns::LookupDetails &details, void *)
Definition: ipcache.h:227
const char * lookup_t_str[]
lookup_t
Definition: lookup_t.h:12
@ LOOKUP_MISS
Definition: lookup_t.h:15
@ LOOKUP_HIT
Definition: lookup_t.h:14
@ LOOKUP_NONE
Definition: lookup_t.h:13
void OBJH(StoreEntry *)
Definition: forward.h:44
int mcastSetTtl(int fd, int mcast_ttl)
Definition: multicast.cc:20
ProtocolType
Definition: ProtocolType.h:23
@ PROTO_HTCP
Definition: ProtocolType.h:33
@ PROTO_ICP
Definition: ProtocolType.h:31
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:27
Flag
Definition: Flag.h:15
@ OK
Definition: Flag.h:16
@ scNone
Definition: StatusCode.h:21
@ METHOD_CONNECT
Definition: MethodType.h:29
@ METHOD_GET
Definition: MethodType.h:25
int intPercent(const int a, const int b)
Definition: SquidMath.cc:13
double doubleAverage(const double, const double, int, const int)
Definition: SquidMath.cc:31
int intAverage(const int, const int, int, const int)
Definition: SquidMath.cc:40
void RegisterAction(char const *action, char const *desc, OBJH *handler, int pw_req_flag, int atomic)
Definition: Registration.cc:16
SSL Connection
Definition: Session.h:45
Controller & Root()
safely access controller singleton
Definition: Controller.cc:938
const char * FormatHttpd(time_t)
Definition: gadgets.cc:116
static void dump_peers(StoreEntry *, CachePeers *)
Definition: neighbors.cc:1503
static void peerClearRRLoop(void *data)
Definition: neighbors.cc:419
static void peerCountMcastPeersDone(void *data)
Definition: neighbors.cc:1312
void peerNoteDigestLookup(HttpRequest *request, CachePeer *p, lookup_t lookup)
Definition: neighbors.cc:813
static int peerWouldBePinged(const CachePeer *, PeerSelector *)
Definition: neighbors.cc:182
static void neighborAliveHtcp(CachePeer *, const MemObject *, const HtcpReplyData *)
Definition: neighbors.cc:868
static void peerCountMcastPeersSchedule(CachePeer *p, time_t when)
Definition: neighbors.cc:1241
void neighborsHtcpClear(StoreEntry *e, HttpRequest *req, const HttpRequestMethod &method, htcp_clr_reason reason)
Definition: neighbors.cc:1673
CachePeer * getFirstUpParent(PeerSelector *ps)
Definition: neighbors.cc:286
CachePeer * findCachePeerByName(const char *const name)
cache_peer with a given name (or nil)
Definition: neighbors.cc:1050
static IPH peerDNSConfigure
Definition: neighbors.cc:62
CachePeer * whichPeer(const Ip::Address &from)
Definition: neighbors.cc:96
static void peerCountMcastPeersCreateAndSend(CachePeer *p)
initiates an ICP transaction to a multicast peer
Definition: neighbors.cc:1266
void neighborsHtcpReply(const cache_key *key, HtcpReplyData *htcp, const Ip::Address &from)
Definition: neighbors.cc:1599
static void neighborUpdateRtt(CachePeer *p, MemObject *mem)
Definition: neighbors.cc:843
static CNCB peerProbeConnectDone
Definition: neighbors.cc:64
void peerAlive(CachePeer *p)
Definition: neighbors.cc:455
void peerClearRR()
Definition: neighbors.cc:448
void neighbors_init(void)
Definition: neighbors.cc:510
static OBJH neighborDumpPeers
Definition: neighbors.cc:73
bool peerHasConnAvailable(const CachePeer *p)
Whether the peer has idle or standby connections that can be used now.
Definition: neighbors.cc:231
int neighborsCount(PeerSelector *ps)
Definition: neighbors.cc:272
static void peerCountMcastPeersAbort(PeerSelector *)
Definition: neighbors.cc:1324
void dump_peer_options(StoreEntry *sentry, CachePeer *p)
Definition: neighbors.cc:1371
int neighborUp(const CachePeer *p)
Definition: neighbors.cc:1060
static bool peerProbeIsBusy(const CachePeer *p)
whether new TCP probes are currently banned
Definition: neighbors.cc:1178
int peerHTTPOkay(const CachePeer *p, PeerSelector *ps)
Definition: neighbors.cc:257
CachePeer * getDefaultParent(PeerSelector *ps)
Definition: neighbors.cc:474
CachePeer * getRoundRobinParent(PeerSelector *ps)
Definition: neighbors.cc:313
const char * neighborTypeStr(const CachePeer *p)
Definition: neighbors.cc:81
time_t positiveTimeout(const time_t timeout)
Definition: neighbors.cc:1095
bool peerAllowedToUse(const CachePeer *, PeerSelector *)
Definition: neighbors.cc:137
static void neighborsRegisterWithCacheManager()
Definition: neighbors.cc:502
void peerClearRRStart(void)
Definition: neighbors.cc:431
bool peerCanOpenMore(const CachePeer *p)
Whether we can open new connections to the peer (e.g., despite max-conn)
Definition: neighbors.cc:222
static int NLateReplies
Definition: neighbors.cc:78
peer_t neighborType(const CachePeer *p, const AnyP::Uri &url)
Definition: neighbors.cc:114
int neighborsUdpPing(HttpRequest *request, StoreEntry *entry, IRCB *callback, PeerSelector *ps, int *exprep, int *timeout)
Definition: neighbors.cc:550
CachePeer * neighborsDigestSelect(PeerSelector *ps)
Definition: neighbors.cc:751
static IRCB peerCountHandleIcpReply
Definition: neighbors.cc:70
static unsigned short echo_port
Definition: neighbors.cc:76
static void peerRefreshDNS(void *)
Definition: neighbors.cc:1158
static void neighborAlive(CachePeer *, const MemObject *, const icp_common_t *)
Definition: neighbors.cc:831
lookup_t peerDigestLookup(CachePeer *p, PeerSelector *ps)
Definition: neighbors.cc:705
#define MCAST_COUNT_RATE
Definition: neighbors.cc:52
static void neighborCountIgnored(CachePeer *)
Definition: neighbors.cc:879
void peerConnClosed(CachePeer *p)
Notifies peer of an associated connection closure.
Definition: neighbors.cc:246
static void neighborIgnoreNonPeer(const Ip::Address &, icp_opcode)
Definition: neighbors.cc:890
static int ignoreMulticastReply(CachePeer *p, PeerSelector *ps)
Definition: neighbors.cc:907
void neighborsUdpAck(const cache_key *key, icp_common_t *header, const Ip::Address &from)
Definition: neighbors.cc:929
static void peerProbeConnect(CachePeer *, const bool reprobeIfBusy=false)
Definition: neighbors.cc:1194
CachePeer * getWeightedRoundRobinParent(PeerSelector *ps)
Definition: neighbors.cc:355
static void peerCountMcastPeersStart(void *data)
Definition: neighbors.cc:1255
int netdbHostRtt(const char *host)
Definition: net_db.cc:960
void netdbExchangeStart(void *data)
Definition: net_db.cc:1197
void peerDigestNeeded(PeerDigest *pd)
Definition: peer_digest.cc:128
#define LOCAL_ARRAY(type, name, size)
Definition: squid.h:68
int stat5minClientRequests(void)
Definition: stat.cc:1687
unsigned char cache_key
Store key.
Definition: forward.h:29
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:841
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:745
const cache_key * storeKeyPublicByRequest(HttpRequest *request, const KeyScope keyScope)
const char * storeKeyText(const cache_key *key)
unsigned short port
Definition: CachePeer.h:92
int counts[ICP_END+1]
Definition: CachePeer.h:91
int unsigned int
Definition: stub_fd.cc:19
bool IamWorkerProcess()
whether the current process handles HTTP transactions and such
Definition: stub_tools.cc:47
struct timeval current_time
the current UNIX time in timeval {seconds, microseconds} format
Definition: gadgets.cc:17
int tvSubMsec(struct timeval t1, struct timeval t2)
Definition: gadgets.cc:51
const char * getMyHostname(void)
Definition: tools.cc:467
void debug_trap(const char *message)
Definition: tools.cc:458
void IRCB(CachePeer *, peer_t, AnyP::ProtocolType, void *, void *data)
Definition: typedefs.h:22

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors