]>
Commit | Line | Data |
---|---|---|
9cef6668 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 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 | 23 | class ICP3State: public ICPState |
62e76326 | 24 | { |
25 | ||
e6ccf245 | 26 | public: |
63be0a78 | 27 | ICP3State(icp_common_t &aHeader, HttpRequest *aRequest) : |
f53969cc | 28 | ICPState(aHeader, aRequest) {} |
62e76326 | 29 | |
337b9aa4 | 30 | ~ICP3State() override = default; |
e6ccf245 | 31 | }; |
32 | ||
63be0a78 | 33 | /// \ingroup ServerProtocolICPInternal3 |
e6ccf245 | 34 | static void |
b7ac5457 | 35 | doV3Query(int fd, Ip::Address &from, char *buf, icp_common_t header) |
e6ccf245 | 36 | { |
37 | /* We have a valid packet */ | |
09aabd84 | 38 | char *url = buf + sizeof(icp_common_t) + sizeof(uint32_t); |
86c63190 | 39 | HttpRequest *icp_request = icpGetRequest(url, header.reqnum, fd, from); |
62e76326 | 40 | |
e6ccf245 | 41 | if (!icp_request) |
62e76326 | 42 | return; |
43 | ||
26ac0430 | 44 | if (!icpAccessAllowed(from, icp_request)) { |
cc192b50 | 45 | icpDenyAccess (from, url, header.reqnum, fd); |
5cafad19 | 46 | delete icp_request; |
62e76326 | 47 | return; |
e6ccf245 | 48 | } |
62e76326 | 49 | |
e6ccf245 | 50 | /* The peer is allowed to use this cache */ |
7976fed3 EB |
51 | ICP3State state(header, icp_request); |
52 | state.fd = fd; | |
53 | state.from = from; | |
54 | state.url = xstrdup(url); | |
62e76326 | 55 | |
e6ccf245 | 56 | icp_opcode codeToSend; |
62e76326 | 57 | |
7976fed3 | 58 | if (state.isHit()) { |
62e76326 | 59 | codeToSend = ICP_HIT; |
e6ccf245 | 60 | } else if (icpGetCommonOpcode() == ICP_ERR) |
62e76326 | 61 | codeToSend = ICP_MISS; |
e6ccf245 | 62 | else |
62e76326 | 63 | codeToSend = icpGetCommonOpcode(); |
64 | ||
7976fed3 | 65 | icpCreateAndSend(codeToSend, 0, url, header.reqnum, 0, fd, from, state.al); |
e6ccf245 | 66 | } |
7a2f978b | 67 | |
63be0a78 | 68 | /// \ingroup ServerProtocolICPInternal3 |
7a2f978b | 69 | /* Currently Harvest cached-2.x uses ICP_VERSION_3 */ |
70 | void | |
b7ac5457 | 71 | icpHandleIcpV3(int fd, Ip::Address &from, char *buf, int len) |
7a2f978b | 72 | { |
26ac0430 | 73 | if (len <= 0) { |
bf8fe701 | 74 | debugs(12, 3, "icpHandleIcpV3: ICP message is too small"); |
62e76326 | 75 | return; |
e6ccf245 | 76 | } |
62e76326 | 77 | |
e6ccf245 | 78 | icp_common_t header (buf, len); |
7b83b3d9 | 79 | /* |
80 | * Length field should match the number of bytes read | |
81 | */ | |
62e76326 | 82 | |
26ac0430 | 83 | if (len != header.length) { |
bf8fe701 | 84 | debugs(12, 3, "icpHandleIcpV3: ICP message is too small"); |
62e76326 | 85 | return; |
7b83b3d9 | 86 | } |
62e76326 | 87 | |
7976fed3 EB |
88 | debugs(12, 5, "OPCODE " << icp_opcode_str[header.getOpCode()] << '=' << uint8_t(header.opcode)); |
89 | ||
26ac0430 | 90 | switch (header.opcode) { |
62e76326 | 91 | |
27cd7235 | 92 | case ICP_QUERY: |
cc192b50 | 93 | doV3Query(fd, from, buf, header); |
62e76326 | 94 | break; |
7a2f978b | 95 | |
27cd7235 | 96 | case ICP_HIT: |
62e76326 | 97 | |
27cd7235 | 98 | case ICP_DECHO: |
62e76326 | 99 | |
27cd7235 | 100 | case ICP_MISS: |
62e76326 | 101 | |
27cd7235 | 102 | case ICP_DENIED: |
62e76326 | 103 | |
27cd7235 | 104 | case ICP_MISS_NOFETCH: |
cc192b50 | 105 | header.handleReply(buf, from); |
62e76326 | 106 | break; |
7a2f978b | 107 | |
27cd7235 | 108 | case ICP_INVALID: |
62e76326 | 109 | |
27cd7235 | 110 | case ICP_ERR: |
62e76326 | 111 | break; |
7a2f978b | 112 | |
113 | default: | |
d816f28d | 114 | debugs(12, DBG_CRITICAL, "ERROR: icpHandleIcpV3: Unknown opcode: " << header.opcode << " from " << from); |
62e76326 | 115 | break; |
7a2f978b | 116 | } |
7a2f978b | 117 | } |
f53969cc | 118 |