icp_v3.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 12 Internet Cache Protocol (ICP) */
10
16#include "squid.h"
17#include "acl/FilledChecklist.h"
18#include "HttpRequest.h"
19#include "ICP.h"
20#include "Store.h"
21
23class ICP3State: public ICPState
24{
25
26public:
27 ICP3State(icp_common_t &aHeader, HttpRequest *aRequest) :
28 ICPState(aHeader, aRequest) {}
29
30 ~ICP3State() override = default;
31};
32
34static void
35doV3Query(int fd, Ip::Address &from, char *buf, icp_common_t header)
36{
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);
40
41 if (!icp_request)
42 return;
43
44 if (!icpAccessAllowed(from, icp_request)) {
45 icpDenyAccess (from, url, header.reqnum, fd);
46 delete icp_request;
47 return;
48 }
49
50 /* The peer is allowed to use this cache */
51 ICP3State state(header, icp_request);
52 state.fd = fd;
53 state.from = from;
54 state.url = xstrdup(url);
55
56 icp_opcode codeToSend;
57
58 if (state.isHit()) {
59 codeToSend = ICP_HIT;
60 } else if (icpGetCommonOpcode() == ICP_ERR)
61 codeToSend = ICP_MISS;
62 else
63 codeToSend = icpGetCommonOpcode();
64
65 icpCreateAndSend(codeToSend, 0, url, header.reqnum, 0, fd, from, state.al);
66}
67
69/* Currently Harvest cached-2.x uses ICP_VERSION_3 */
70void
71icpHandleIcpV3(int fd, Ip::Address &from, char *buf, int len)
72{
73 if (len <= 0) {
74 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
75 return;
76 }
77
78 icp_common_t header (buf, len);
79 /*
80 * Length field should match the number of bytes read
81 */
82
83 if (len != header.length) {
84 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
85 return;
86 }
87
88 debugs(12, 5, "OPCODE " << icp_opcode_str[header.getOpCode()] << '=' << uint8_t(header.opcode));
89
90 switch (header.opcode) {
91
92 case ICP_QUERY:
93 doV3Query(fd, from, buf, header);
94 break;
95
96 case ICP_HIT:
97
98 case ICP_DECHO:
99
100 case ICP_MISS:
101
102 case ICP_DENIED:
103
104 case ICP_MISS_NOFETCH:
105 header.handleReply(buf, from);
106 break;
107
108 case ICP_INVALID:
109
110 case ICP_ERR:
111 break;
112
113 default:
114 debugs(12, DBG_CRITICAL, "ERROR: icpHandleIcpV3: Unknown opcode: " << header.opcode << " from " << from);
115 break;
116 }
117}
118
~ICP3State() override=default
ICP3State(icp_common_t &aHeader, HttpRequest *aRequest)
Definition: icp_v3.cc:27
Definition: ICP.h:62
bool isHit() const
whether the cache contains the requested entry
Definition: icp_v2.cc:155
AccessLogEntryPointer al
Definition: ICP.h:77
Ip::Address from
Definition: ICP.h:75
char * url
Definition: ICP.h:76
int fd
Definition: ICP.h:73
void handleReply(char *buf, Ip::Address &from)
Definition: icp_v2.cc:540
icp_opcode getOpCode() const
Definition: icp_v2.cc:129
uint32_t reqnum
Definition: ICP.h:44
unsigned char opcode
Definition: ICP.h:38
unsigned short length
Definition: ICP.h:42
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define DBG_CRITICAL
Definition: Stream.h:37
icp_opcode icpGetCommonOpcode()
Definition: icp_v2.cc:376
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
bool icpAccessAllowed(Ip::Address &from, HttpRequest *icp_request)
Definition: icp_v2.cc:444
void icpDenyAccess(Ip::Address &from, char *url, int reqnum, int fd)
Definition: icp_v2.cc:428
HttpRequest * icpGetRequest(char *url, int reqnum, int fd, Ip::Address &from)
Definition: icp_v2.cc:457
@ ICP_DECHO
Definition: icp_opcode.h:26
@ ICP_INVALID
Definition: icp_opcode.h:15
@ ICP_QUERY
Definition: icp_opcode.h:16
@ ICP_MISS_NOFETCH
Definition: icp_opcode.h:36
@ ICP_DENIED
Definition: icp_opcode.h:37
@ ICP_ERR
Definition: icp_opcode.h:19
@ ICP_MISS
Definition: icp_opcode.h:18
@ ICP_HIT
Definition: icp_opcode.h:17
static void doV3Query(int fd, Ip::Address &from, char *buf, icp_common_t header)
Definition: icp_v3.cc:35
void icpHandleIcpV3(int fd, Ip::Address &from, char *buf, int len)
Definition: icp_v3.cc:71
const char * icp_opcode_str[]
#define xstrdup

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors