2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 28 Access Control */
16 #include "acl/FilledChecklist.h"
19 #include "eui/Eui48.h"
21 #include "ip/Address.h"
23 static void aclParseArpList(Splay
<Eui::Eui48
*> **curlist
);
24 static int aclMatchArp(Splay
<Eui::Eui48
*> **dataptr
, Ip::Address
&c
);
25 static Splay
<Eui::Eui48
*>::SPLAYCMP aclArpCompare
;
30 return new ACLARP(*this);
33 ACLARP::ACLARP (char const *theClass
) : data (NULL
), class_ (theClass
)
36 ACLARP::ACLARP (ACLARP
const & old
) : data (NULL
), class_ (old
.class_
)
38 /* we don't have copy constructors for the data yet */
49 ACLARP::typeString() const
55 ACLARP::empty () const
60 /* ==== BEGIN ARP ACL SUPPORT ============================================= */
63 * From: dale@server.ctam.bitmcnit.bryansk.su (Dale)
64 * To: wessels@nlanr.net
65 * Subject: Another Squid patch... :)
66 * Date: Thu, 04 Dec 1997 19:55:01 +0300
67 * ============================================================================
69 * Working on setting up a proper firewall for a network containing some
70 * Win'95 computers at our Univ, I've discovered that some smart students
71 * avoid the restrictions easily just changing their IP addresses in Win'95
72 * Contol Panel... It has been getting boring, so I took Squid-1.1.18
73 * sources and added a new acl type for hard-wired access control:
75 * acl <name> arp <Ethernet address> ...
79 * acl students arp 00:00:21:55:ed:22 00:00:21:ff:55:38
81 * NOTE: Linux code by David Luyer <luyer@ucs.uwa.edu.au>.
82 * Original (BSD-specific) code no longer works.
83 * Solaris code by R. Gancarz <radekg@solaris.elektrownia-lagisza.com.pl>
87 aclParseArpData(const char *t
)
90 Eui::Eui48
*q
= new Eui::Eui48
;
91 debugs(28, 5, "aclParseArpData: " << t
);
93 if (sscanf(t
, "%[0-9a-fA-F:]", buf
) != 1) {
94 debugs(28, DBG_CRITICAL
, "aclParseArpData: Bad ethernet address: '" << t
<< "'");
99 if (!q
->decode(buf
)) {
100 debugs(28, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
101 debugs(28, DBG_CRITICAL
, "aclParseArpData: Ignoring invalid ARP acl entry: can't parse '" << buf
<< "'");
109 /*******************/
110 /* aclParseArpList */
111 /*******************/
115 aclParseArpList(&data
);
119 aclParseArpList(Splay
<Eui::Eui48
*> **curlist
)
122 Eui::Eui48
*q
= NULL
;
124 while ((t
= strtokFile())) {
125 if ((q
= aclParseArpData(t
)) == NULL
)
128 (*curlist
)->insert(q
, aclArpCompare
);
133 ACLARP::match(ACLChecklist
*cl
)
135 ACLFilledChecklist
*checklist
= Filled(cl
);
137 /* IPv6 does not do ARP */
138 if (!checklist
->src_addr
.isIPv4()) {
139 debugs(14, 3, "ACLARP::match: IPv4 Required for ARP Lookups. Skipping " << checklist
->src_addr
);
143 return aclMatchArp(&data
, checklist
->src_addr
);
150 aclMatchArp(Splay
<Eui::Eui48
*> **dataptr
, Ip::Address
&c
)
152 Eui::Eui48 lookingFor
;
153 if (lookingFor
.lookup(c
)) {
154 Eui::Eui48
* const* lookupResult
;
155 lookupResult
= (*dataptr
)->find(&lookingFor
,aclArpCompare
);
156 debugs(28, 3, "aclMatchArp: '" << c
<< "' " << (lookupResult
? "found" : "NOT found"));
157 return (lookupResult
!= NULL
);
159 debugs(28, 3, "aclMatchArp: " << c
<< " NOT found");
164 aclArpCompare(Eui::Eui48
* const &a
, Eui::Eui48
* const &b
)
166 return memcmp(a
, b
, sizeof(Eui::Eui48
));
169 // visitor functor to collect the contents of the Arp Acl
170 struct ArpAclDumpVisitor
{
172 void operator() (const Eui::Eui48
* v
) {
175 contents
.push_back(SBuf(buf
));
182 ArpAclDumpVisitor visitor
;
183 data
->visit(visitor
);
184 return visitor
.contents
;
187 /* ==== END ARP ACL SUPPORT =============================================== */
189 #endif /* USE_SQUID_EUI */