]> git.ipfire.org Git - thirdparty/squid.git/blame - src/icp_v3.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / icp_v3.cc
CommitLineData
9cef6668 1/*
f6e9a3ee 2 * Copyright (C) 1996-2019 The Squid Software Foundation and contributors
9cef6668 3 *
bbc27441
AJ
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.
9cef6668 7 */
8
bbc27441
AJ
9/* DEBUG: section 12 Internet Cache Protocol (ICP) */
10
63be0a78 11/**
12 \defgroup ServerProtocolICPInternal3 ICPv3 Internals
13 \ingroup ServerProtocolICPAPI
14 */
15
582c2af2 16#include "squid.h"
819be284 17#include "acl/FilledChecklist.h"
528b2c61 18#include "HttpRequest.h"
602d9612
A
19#include "ICP.h"
20#include "Store.h"
e6ccf245 21
63be0a78 22/// \ingroup ServerProtocolICPInternal3
819be284 23class ICP3State: public ICPState
62e76326 24{
25
e6ccf245 26public:
63be0a78 27 ICP3State(icp_common_t &aHeader, HttpRequest *aRequest) :
f53969cc 28 ICPState(aHeader, aRequest) {}
62e76326 29
e6ccf245 30 ~ICP3State();
31 void created (StoreEntry *newEntry);
32};
33
63be0a78 34/// \ingroup ServerProtocolICPInternal3
e6ccf245 35static void
b7ac5457 36doV3Query(int fd, Ip::Address &from, char *buf, icp_common_t header)
e6ccf245 37{
38 /* We have a valid packet */
09aabd84 39 char *url = buf + sizeof(icp_common_t) + sizeof(uint32_t);
86c63190 40 HttpRequest *icp_request = icpGetRequest(url, header.reqnum, fd, from);
62e76326 41
e6ccf245 42 if (!icp_request)
62e76326 43 return;
44
26ac0430 45 if (!icpAccessAllowed(from, icp_request)) {
cc192b50 46 icpDenyAccess (from, url, header.reqnum, fd);
5cafad19 47 delete icp_request;
62e76326 48 return;
e6ccf245 49 }
62e76326 50
e6ccf245 51 /* The peer is allowed to use this cache */
f72fb56b 52 ICP3State *state = new ICP3State (header, icp_request);
e6ccf245 53 state->fd = fd;
54 state->from = from;
86c63190 55 state->url = xstrdup(url);
62e76326 56
c2a7cefd 57 StoreEntry::getPublic (state, url, Http::METHOD_GET);
e6ccf245 58}
59
63be0a78 60ICP3State::~ICP3State()
62e76326 61{}
e6ccf245 62
63void
819be284 64ICP3State::created(StoreEntry *e)
e6ccf245 65{
bf8fe701 66 debugs(12, 5, "icpHandleIcpV3: OPCODE " << icp_opcode_str[header.opcode]);
e6ccf245 67 icp_opcode codeToSend;
62e76326 68
69565793 69 if (e && confirmAndPrepHit(*e)) {
62e76326 70 codeToSend = ICP_HIT;
e6ccf245 71 } else if (icpGetCommonOpcode() == ICP_ERR)
62e76326 72 codeToSend = ICP_MISS;
e6ccf245 73 else
62e76326 74 codeToSend = icpGetCommonOpcode();
75
819be284
EB
76 icpCreateAndSend(codeToSend, 0, url, header.reqnum, 0, fd, from, al);
77
78 // TODO: StoreClients must either store/lock or abandon found entries.
69565793 79 //if (e)
819be284 80 // e->abandon();
62e76326 81
e6ccf245 82 delete this;
83}
7a2f978b 84
63be0a78 85/// \ingroup ServerProtocolICPInternal3
7a2f978b 86/* Currently Harvest cached-2.x uses ICP_VERSION_3 */
87void
b7ac5457 88icpHandleIcpV3(int fd, Ip::Address &from, char *buf, int len)
7a2f978b 89{
26ac0430 90 if (len <= 0) {
bf8fe701 91 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
62e76326 92 return;
e6ccf245 93 }
62e76326 94
e6ccf245 95 icp_common_t header (buf, len);
7b83b3d9 96 /*
97 * Length field should match the number of bytes read
98 */
62e76326 99
26ac0430 100 if (len != header.length) {
bf8fe701 101 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
62e76326 102 return;
7b83b3d9 103 }
62e76326 104
26ac0430 105 switch (header.opcode) {
62e76326 106
27cd7235 107 case ICP_QUERY:
cc192b50 108 doV3Query(fd, from, buf, header);
62e76326 109 break;
7a2f978b 110
27cd7235 111 case ICP_HIT:
62e76326 112
27cd7235 113 case ICP_DECHO:
62e76326 114
27cd7235 115 case ICP_MISS:
62e76326 116
27cd7235 117 case ICP_DENIED:
62e76326 118
27cd7235 119 case ICP_MISS_NOFETCH:
cc192b50 120 header.handleReply(buf, from);
62e76326 121 break;
7a2f978b 122
27cd7235 123 case ICP_INVALID:
62e76326 124
27cd7235 125 case ICP_ERR:
62e76326 126 break;
7a2f978b 127
128 default:
fa84c01d 129 debugs(12, DBG_CRITICAL, "icpHandleIcpV3: UNKNOWN OPCODE: " << header.opcode << " from " << from);
62e76326 130 break;
7a2f978b 131 }
7a2f978b 132}
f53969cc 133