2 * DEBUG: section 28 Access Control
3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
40 #include "acl/FilledChecklist.h"
42 #include "eui/Eui48.h"
43 #include "ip/Address.h"
47 static void aclParseArpList(SplayNode
<Eui::Eui48
*> **curlist
);
48 static int aclMatchArp(SplayNode
<Eui::Eui48
*> **dataptr
, Ip::Address
&c
);
49 static SplayNode
<Eui::Eui48
*>::SPLAYCMP aclArpCompare
;
50 static SplayNode
<Eui::Eui48
*>::SPLAYWALKEE aclDumpArpListWalkee
;
56 return new ACLARP(*this);
59 ACLARP::ACLARP (char const *theClass
) : data (NULL
), class_ (theClass
)
62 ACLARP::ACLARP (ACLARP
const & old
) : data (NULL
), class_ (old
.class_
)
64 /* we don't have copy constructors for the data yet */
71 data
->destroy(SplayNode
<Eui::Eui48
*>::DefaultFree
);
75 ACLARP::typeString() const
81 ACLARP::empty () const
86 /* ==== BEGIN ARP ACL SUPPORT ============================================= */
89 * From: dale@server.ctam.bitmcnit.bryansk.su (Dale)
90 * To: wessels@nlanr.net
91 * Subject: Another Squid patch... :)
92 * Date: Thu, 04 Dec 1997 19:55:01 +0300
93 * ============================================================================
95 * Working on setting up a proper firewall for a network containing some
96 * Win'95 computers at our Univ, I've discovered that some smart students
97 * avoid the restrictions easily just changing their IP addresses in Win'95
98 * Contol Panel... It has been getting boring, so I took Squid-1.1.18
99 * sources and added a new acl type for hard-wired access control:
101 * acl <name> arp <Ethernet address> ...
105 * acl students arp 00:00:21:55:ed:22 00:00:21:ff:55:38
107 * NOTE: Linux code by David Luyer <luyer@ucs.uwa.edu.au>.
108 * Original (BSD-specific) code no longer works.
109 * Solaris code by R. Gancarz <radekg@solaris.elektrownia-lagisza.com.pl>
113 aclParseArpData(const char *t
)
116 Eui::Eui48
*q
= new Eui::Eui48
;
117 debugs(28, 5, "aclParseArpData: " << t
);
119 if (sscanf(t
, "%[0-9a-fA-F:]", buf
) != 1) {
120 debugs(28, DBG_CRITICAL
, "aclParseArpData: Bad ethernet address: '" << t
<< "'");
125 if (!q
->decode(buf
)) {
126 debugs(28, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
127 debugs(28, DBG_CRITICAL
, "aclParseArpData: Ignoring invalid ARP acl entry: can't parse '" << buf
<< "'");
136 /*******************/
137 /* aclParseArpList */
138 /*******************/
142 aclParseArpList(&data
);
146 aclParseArpList(SplayNode
<Eui::Eui48
*> **curlist
)
149 SplayNode
<Eui::Eui48
*> **Top
= curlist
;
150 Eui::Eui48
*q
= NULL
;
152 while ((t
= strtokFile())) {
153 if ((q
= aclParseArpData(t
)) == NULL
)
156 *Top
= (*Top
)->insert(q
, aclArpCompare
);
161 ACLARP::match(ACLChecklist
*cl
)
163 ACLFilledChecklist
*checklist
= Filled(cl
);
165 /* IPv6 does not do ARP */
166 if (!checklist
->src_addr
.IsIPv4()) {
167 debugs(14, 3, "ACLARP::match: IPv4 Required for ARP Lookups. Skipping " << checklist
->src_addr
);
171 return aclMatchArp(&data
, checklist
->src_addr
);
178 aclMatchArp(SplayNode
<Eui::Eui48
*> **dataptr
, Ip::Address
&c
)
181 SplayNode
<Eui::Eui48
*> **Top
= dataptr
;
183 if (result
.lookup(c
)) {
184 /* Do ACL match lookup */
185 *Top
= (*Top
)->splay(&result
, aclArpCompare
);
186 debugs(28, 3, "aclMatchArp: '" << c
<< "' " << (splayLastResult
? "NOT found" : "found"));
187 return (0 == splayLastResult
);
191 * Address was not found on any interface
193 debugs(28, 3, "aclMatchArp: " << c
<< " NOT found");
198 aclArpCompare(Eui::Eui48
* const &a
, Eui::Eui48
* const &b
)
200 return memcmp(a
, b
, sizeof(Eui::Eui48
));
204 aclDumpArpListWalkee(Eui::Eui48
* const &node
, void *state
)
207 node
->encode(buf
, 48);
208 wordlistAdd((wordlist
**)state
, buf
);
215 data
->walk(aclDumpArpListWalkee
, &w
);
219 /* ==== END ARP ACL SUPPORT =============================================== */
221 #endif /* USE_SQUID_EUI */