icp_v3.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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 
23 class ICP3State: public ICPState
24 {
25 
26 public:
27  ICP3State(icp_common_t &aHeader, HttpRequest *aRequest) :
28  ICPState(aHeader, aRequest) {}
29 
30  ~ICP3State();
31  void created (StoreEntry *newEntry);
32 };
33 
35 static void
36 doV3Query(int fd, Ip::Address &from, char *buf, icp_common_t header)
37 {
38  /* We have a valid packet */
39  char *url = buf + sizeof(icp_common_t) + sizeof(uint32_t);
40  HttpRequest *icp_request = icpGetRequest(url, header.reqnum, fd, from);
41 
42  if (!icp_request)
43  return;
44 
45  if (!icpAccessAllowed(from, icp_request)) {
46  icpDenyAccess (from, url, header.reqnum, fd);
47  delete icp_request;
48  return;
49  }
50 
51  /* The peer is allowed to use this cache */
52  ICP3State *state = new ICP3State (header, icp_request);
53  state->fd = fd;
54  state->from = from;
55  state->url = xstrdup(url);
56 
58 }
59 
61 {}
62 
63 void
65 {
66  debugs(12, 5, "icpHandleIcpV3: OPCODE " << icp_opcode_str[header.opcode]);
67  icp_opcode codeToSend;
68 
69  if (foundHit(*e)) {
70  codeToSend = ICP_HIT;
71  } else if (icpGetCommonOpcode() == ICP_ERR)
72  codeToSend = ICP_MISS;
73  else
74  codeToSend = icpGetCommonOpcode();
75 
76  icpCreateAndSend(codeToSend, 0, url, header.reqnum, 0, fd, from, al);
77 
78  // TODO: StoreClients must either store/lock or abandon found entries.
79  //if (!e->isNull())
80  // e->abandon();
81 
82  delete this;
83 }
84 
86 /* Currently Harvest cached-2.x uses ICP_VERSION_3 */
87 void
88 icpHandleIcpV3(int fd, Ip::Address &from, char *buf, int len)
89 {
90  if (len <= 0) {
91  debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
92  return;
93  }
94 
95  icp_common_t header (buf, len);
96  /*
97  * Length field should match the number of bytes read
98  */
99 
100  if (len != header.length) {
101  debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
102  return;
103  }
104 
105  switch (header.opcode) {
106 
107  case ICP_QUERY:
108  doV3Query(fd, from, buf, header);
109  break;
110 
111  case ICP_HIT:
112 
113  case ICP_DECHO:
114 
115  case ICP_MISS:
116 
117  case ICP_DENIED:
118 
119  case ICP_MISS_NOFETCH:
120  header.handleReply(buf, from);
121  break;
122 
123  case ICP_INVALID:
124 
125  case ICP_ERR:
126  break;
127 
128  default:
129  debugs(12, DBG_CRITICAL, "icpHandleIcpV3: UNKNOWN OPCODE: " << header.opcode << " from " << from);
130  break;
131  }
132 }
133 
Definition: ICP.h:64
static void doV3Query(int fd, Ip::Address &from, char *buf, icp_common_t header)
Definition: icp_v3.cc:36
Ip::Address from
Definition: ICP.h:78
icp_opcode icpGetCommonOpcode()
Definition: icp_v2.cc:368
#define xstrdup
ICP3State(icp_common_t &aHeader, HttpRequest *aRequest)
Definition: icp_v3.cc:27
int fd
Definition: ICP.h:76
void handleReply(char *buf, Ip::Address &from)
Definition: icp_v2.cc:512
#define DBG_CRITICAL
Definition: Debug.h:45
unsigned short length
Definition: ICP.h:42
bool icpAccessAllowed(Ip::Address &from, HttpRequest *icp_request)
Definition: icp_v2.cc:427
void icpHandleIcpV3(int fd, Ip::Address &from, char *buf, int len)
Definition: icp_v3.cc:88
uint32_t reqnum
Definition: ICP.h:44
static void getPublic(StoreClient *aClient, const char *uri, const HttpRequestMethod &method)
Definition: store.cc:522
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
unsigned char opcode
Definition: ICP.h:38
char * url
Definition: ICP.h:79
icp_opcode
Definition: icp_opcode.h:13
icp_common_t header
Definition: ICP.h:74
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
HttpRequest * icpGetRequest(char *url, int reqnum, int fd, Ip::Address &from)
Definition: icp_v2.cc:449
void const char * buf
Definition: stub_helper.cc:16
void icpCreateAndSend(icp_opcode, int flags, char const *url, int reqnum, int pad, int fd, const Ip::Address &from, AccessLogEntryPointer)
Definition: icp_v2.cc:404
AccessLogEntryPointer al
Definition: ICP.h:84
void created(StoreEntry *newEntry)
Definition: icp_v3.cc:64
void icpDenyAccess(Ip::Address &from, char *url, int reqnum, int fd)
Definition: icp_v2.cc:411
~ICP3State()
Definition: icp_v3.cc:60
bool foundHit(const StoreEntry &) const
whether the found entry warrants an ICP_HIT response
Definition: icp_v2.cc:144
const char * icp_opcode_str[]

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors