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 */
51 ACLARP::typeString() const
57 ACLARP::empty () const
62 /* ==== BEGIN ARP ACL SUPPORT ============================================= */
65 * From: dale@server.ctam.bitmcnit.bryansk.su (Dale)
66 * To: wessels@nlanr.net
67 * Subject: Another Squid patch... :)
68 * Date: Thu, 04 Dec 1997 19:55:01 +0300
69 * ============================================================================
71 * Working on setting up a proper firewall for a network containing some
72 * Win'95 computers at our Univ, I've discovered that some smart students
73 * avoid the restrictions easily just changing their IP addresses in Win'95
74 * Contol Panel... It has been getting boring, so I took Squid-1.1.18
75 * sources and added a new acl type for hard-wired access control:
77 * acl <name> arp <Ethernet address> ...
81 * acl students arp 00:00:21:55:ed:22 00:00:21:ff:55:38
83 * NOTE: Linux code by David Luyer <luyer@ucs.uwa.edu.au>.
84 * Original (BSD-specific) code no longer works.
85 * Solaris code by R. Gancarz <radekg@solaris.elektrownia-lagisza.com.pl>
89 aclParseArpData(const char *t
)
92 Eui::Eui48
*q
= new Eui::Eui48
;
93 debugs(28, 5, "aclParseArpData: " << t
);
95 if (sscanf(t
, "%[0-9a-fA-F:]", buf
) != 1) {
96 debugs(28, DBG_CRITICAL
, "aclParseArpData: Bad ethernet address: '" << t
<< "'");
101 if (!q
->decode(buf
)) {
102 debugs(28, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
103 debugs(28, DBG_CRITICAL
, "aclParseArpData: Ignoring invalid ARP acl entry: can't parse '" << buf
<< "'");
111 /*******************/
112 /* aclParseArpList */
113 /*******************/
117 aclParseArpList(&data
);
121 aclParseArpList(Splay
<Eui::Eui48
*> **curlist
)
124 Eui::Eui48
*q
= NULL
;
126 while ((t
= strtokFile())) {
127 if ((q
= aclParseArpData(t
)) == NULL
)
130 (*curlist
)->insert(q
, aclArpCompare
);
135 ACLARP::match(ACLChecklist
*cl
)
137 ACLFilledChecklist
*checklist
= Filled(cl
);
139 /* IPv6 does not do ARP */
140 if (!checklist
->src_addr
.isIPv4()) {
141 debugs(14, 3, "ACLARP::match: IPv4 Required for ARP Lookups. Skipping " << checklist
->src_addr
);
145 return aclMatchArp(&data
, checklist
->src_addr
);
152 aclMatchArp(Splay
<Eui::Eui48
*> **dataptr
, Ip::Address
&c
)
154 Eui::Eui48 lookingFor
;
155 if (lookingFor
.lookup(c
)) {
156 Eui::Eui48
* const* lookupResult
= (*dataptr
)->find(&lookingFor
,aclArpCompare
);
157 debugs(28, 3, "aclMatchArp: '" << c
<< "' " << (lookupResult
? "found" : "NOT found"));
158 return (lookupResult
!= NULL
);
160 debugs(28, 3, "aclMatchArp: " << c
<< " NOT found");
165 aclArpCompare(Eui::Eui48
* const &a
, Eui::Eui48
* const &b
)
167 return memcmp(a
, b
, sizeof(Eui::Eui48
));
170 // visitor functor to collect the contents of the Arp Acl
171 struct ArpAclDumpVisitor
{
173 void operator() (const Eui::Eui48
* v
) {
176 contents
.push_back(SBuf(buf
));
183 ArpAclDumpVisitor visitor
;
184 data
->visit(visitor
);
185 return visitor
.contents
;
188 /* ==== END ARP ACL SUPPORT =============================================== */
190 #endif /* USE_SQUID_EUI */