]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/icp_v3.cc
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 12 Internet Cache Protocol (ICP) */
12 \defgroup ServerProtocolICPInternal3 ICPv3 Internals
13 \ingroup ServerProtocolICPAPI
17 #include "acl/FilledChecklist.h"
18 #include "HttpRequest.h"
22 /// \ingroup ServerProtocolICPInternal3
23 class ICP3State
: public ICPState
27 ICP3State(icp_common_t
&aHeader
, HttpRequest
*aRequest
) :
28 ICPState(aHeader
, aRequest
) {}
30 ~ICP3State() override
= default;
33 /// \ingroup ServerProtocolICPInternal3
35 doV3Query(int fd
, Ip::Address
&from
, char *buf
, icp_common_t header
)
37 /* We have a valid packet */
38 char *url
= buf
+ sizeof(icp_common_t
) + sizeof(uint32_t);
39 HttpRequest
*icp_request
= icpGetRequest(url
, header
.reqnum
, fd
, from
);
44 if (!icpAccessAllowed(from
, icp_request
)) {
45 icpDenyAccess (from
, url
, header
.reqnum
, fd
);
50 /* The peer is allowed to use this cache */
51 ICP3State
state(header
, icp_request
);
54 state
.url
= xstrdup(url
);
56 icp_opcode codeToSend
;
60 } else if (icpGetCommonOpcode() == ICP_ERR
)
61 codeToSend
= ICP_MISS
;
63 codeToSend
= icpGetCommonOpcode();
65 icpCreateAndSend(codeToSend
, 0, url
, header
.reqnum
, 0, fd
, from
, state
.al
);
68 /// \ingroup ServerProtocolICPInternal3
69 /* Currently Harvest cached-2.x uses ICP_VERSION_3 */
71 icpHandleIcpV3(int fd
, Ip::Address
&from
, char *buf
, int len
)
74 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
78 icp_common_t
header (buf
, len
);
80 * Length field should match the number of bytes read
83 if (len
!= header
.length
) {
84 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
88 debugs(12, 5, "OPCODE " << icp_opcode_str
[header
.getOpCode()] << '=' << uint8_t(header
.opcode
));
90 switch (header
.opcode
) {
93 doV3Query(fd
, from
, buf
, header
);
104 case ICP_MISS_NOFETCH
:
105 header
.handleReply(buf
, from
);
114 debugs(12, DBG_CRITICAL
, "ERROR: icpHandleIcpV3: Unknown opcode: " << header
.opcode
<< " from " << from
);