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"
41 #include "eui/Eui48.h"
42 #include "ip/Address.h"
45 static void aclParseArpList(SplayNode
<Eui::Eui48
*> **curlist
);
46 static int aclMatchArp(SplayNode
<Eui::Eui48
*> **dataptr
, Ip::Address
&c
);
47 static SplayNode
<Eui::Eui48
*>::SPLAYCMP aclArpCompare
;
48 static SplayNode
<Eui::Eui48
*>::SPLAYWALKEE aclDumpArpListWalkee
;
54 return new ACLARP(*this);
57 ACLARP::ACLARP (char const *theClass
) : data (NULL
), class_ (theClass
)
60 ACLARP::ACLARP (ACLARP
const & old
) : data (NULL
), class_ (old
.class_
)
62 /* we don't have copy constructors for the data yet */
69 data
->destroy(SplayNode
<Eui::Eui48
*>::DefaultFree
);
73 ACLARP::typeString() const
79 ACLARP::empty () const
84 /* ==== BEGIN ARP ACL SUPPORT ============================================= */
87 * From: dale@server.ctam.bitmcnit.bryansk.su (Dale)
88 * To: wessels@nlanr.net
89 * Subject: Another Squid patch... :)
90 * Date: Thu, 04 Dec 1997 19:55:01 +0300
91 * ============================================================================
93 * Working on setting up a proper firewall for a network containing some
94 * Win'95 computers at our Univ, I've discovered that some smart students
95 * avoid the restrictions easily just changing their IP addresses in Win'95
96 * Contol Panel... It has been getting boring, so I took Squid-1.1.18
97 * sources and added a new acl type for hard-wired access control:
99 * acl <name> arp <Ethernet address> ...
103 * acl students arp 00:00:21:55:ed:22 00:00:21:ff:55:38
105 * NOTE: Linux code by David Luyer <luyer@ucs.uwa.edu.au>.
106 * Original (BSD-specific) code no longer works.
107 * Solaris code by R. Gancarz <radekg@solaris.elektrownia-lagisza.com.pl>
111 aclParseArpData(const char *t
)
114 Eui::Eui48
*q
= new Eui::Eui48
;
115 debugs(28, 5, "aclParseArpData: " << t
);
117 if (sscanf(t
, "%[0-9a-fA-F:]", buf
) != 1) {
118 debugs(28, 0, "aclParseArpData: Bad ethernet address: '" << t
<< "'");
123 if (!q
->decode(buf
)) {
124 debugs(28, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
125 debugs(28, 0, "aclParseArpData: Ignoring invalid ARP acl entry: can't parse '" << buf
<< "'");
134 /*******************/
135 /* aclParseArpList */
136 /*******************/
140 aclParseArpList(&data
);
144 aclParseArpList(SplayNode
<Eui::Eui48
*> **curlist
)
147 SplayNode
<Eui::Eui48
*> **Top
= curlist
;
148 Eui::Eui48
*q
= NULL
;
150 while ((t
= strtokFile())) {
151 if ((q
= aclParseArpData(t
)) == NULL
)
154 *Top
= (*Top
)->insert(q
, aclArpCompare
);
159 ACLARP::match(ACLChecklist
*cl
)
161 ACLFilledChecklist
*checklist
= Filled(cl
);
163 /* IPv6 does not do ARP */
164 if (!checklist
->src_addr
.IsIPv4()) {
165 debugs(14, 3, "ACLARP::match: IPv4 Required for ARP Lookups. Skipping " << checklist
->src_addr
);
169 return aclMatchArp(&data
, checklist
->src_addr
);
176 aclMatchArp(SplayNode
<Eui::Eui48
*> **dataptr
, Ip::Address
&c
)
179 SplayNode
<Eui::Eui48
*> **Top
= dataptr
;
181 if (result
.lookup(c
)) {
182 /* Do ACL match lookup */
183 *Top
= (*Top
)->splay(&result
, aclArpCompare
);
184 debugs(28, 3, "aclMatchArp: '" << c
<< "' " << (splayLastResult
? "NOT found" : "found"));
185 return (0 == splayLastResult
);
189 * Address was not found on any interface
191 debugs(28, 3, "aclMatchArp: " << c
<< " NOT found");
196 aclArpCompare(Eui::Eui48
* const &a
, Eui::Eui48
* const &b
)
198 return memcmp(a
, b
, sizeof(Eui::Eui48
));
202 aclDumpArpListWalkee(Eui::Eui48
* const &node
, void *state
)
205 node
->encode(buf
, 48);
206 wordlistAdd((wordlist
**)state
, buf
);
213 data
->walk(aclDumpArpListWalkee
, &w
);
217 /* ==== END ARP ACL SUPPORT =============================================== */
219 #endif /* USE_SQUID_EUI */