]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ACLDestinationIP.cc
Document the 'carp' cache_peer option
[thirdparty/squid.git] / src / ACLDestinationIP.cc
CommitLineData
8000a965 1/*
2 * $Id$
3 *
4 * DEBUG: section 28 Access Control
5 * AUTHOR: Duane Wessels
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
34 */
35
36#include "squid.h"
37#include "ACLDestinationIP.h"
38#include "ACLChecklist.h"
39
40MemPool *ACLDestinationIP::Pool(NULL);
41void *
42ACLDestinationIP::operator new (size_t byteCount)
43{
44 /* derived classes with different sizes must implement their own new */
45 assert (byteCount == sizeof (ACLDestinationIP));
46 if (!Pool)
47 Pool = memPoolCreate("ACLDestinationIP", sizeof (ACLDestinationIP));
48 return memPoolAlloc(Pool);
49}
50
51void
52ACLDestinationIP::operator delete (void *address)
53{
54 memPoolFree (Pool, address);
55}
56
57void
58ACLDestinationIP::deleteSelf() const
59{
60 delete this;
61}
62
63char const *
64ACLDestinationIP::typeString() const
65{
66 return "dst";
67}
68
69int
70ACLDestinationIP::match(ACLChecklist *checklist)
71{
72 const ipcache_addrs *ia = ipcache_gethostbyname(checklist->request->host, IP_LOOKUP_IF_MISS);
73 if (ia) {
74 /* Entry in cache found */
75 for (int k = 0; k < (int) ia->count; k++) {
76 if (ACLIP::match(ia->in_addrs[k]))
77 return 1;
78 }
79 return 0;
80 } else if (!checklist->request->flags.destinationIPLookedUp()) {
81 /* No entry in cache, lookup not attempted */
82 debug(28, 3) ("aclMatchAcl: Can't yet compare '%s' ACL for '%s'\n",
83 name, checklist->request->host);
84 checklist->changeState (DestinationIPLookup::Instance());
85 return 0;
86 } else {
87 return ACLIP::match(no_addr);
88 }
89}
90
91DestinationIPLookup DestinationIPLookup::instance_;
92
93DestinationIPLookup *
94DestinationIPLookup::Instance()
95{
96 return &instance_;
97}
98
99void
100DestinationIPLookup::checkForAsync(ACLChecklist *checklist)const
101{
102 checklist->asyncInProgress(true);
103 ipcache_nbgethostbyname(checklist->request->host, LookupDone, checklist);
104}
105
106void
107DestinationIPLookup::LookupDone(const ipcache_addrs * ia, void *data)
108{
109 ACLChecklist *checklist = (ACLChecklist *)data;
110 assert (checklist->asyncState() == DestinationIPLookup::Instance());
111 checklist->request->flags.destinationIPLookupCompleted();
112 checklist->asyncInProgress(false);
113 checklist->changeState (ACLChecklist::NullState::Instance());
114 checklist->check();
115}
116
117ACL::Prototype ACLDestinationIP::RegistryProtoype(&ACLDestinationIP::RegistryEntry_, "dst");
118
119ACLDestinationIP ACLDestinationIP::RegistryEntry_;
120
121ACL *
122ACLDestinationIP::clone() const
123{
124 return new ACLDestinationIP(*this);
125}