]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Arp.cc
Merged from trunk
[thirdparty/squid.git] / src / acl / Arp.cc
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 28 Access Control */
10
11 #include "squid.h"
12
13 #if USE_SQUID_EUI
14
15 #include "acl/Arp.h"
16 #include "acl/FilledChecklist.h"
17 #include "cache_cf.h"
18 #include "Debug.h"
19 #include "eui/Eui48.h"
20 #include "globals.h"
21 #include "ip/Address.h"
22
23 #include <algorithm>
24
25 ACL *
26 ACLARP::clone() const
27 {
28 return new ACLARP(*this);
29 }
30
31 ACLARP::ACLARP (char const *theClass) : class_ (theClass)
32 {}
33
34 ACLARP::ACLARP (ACLARP const & old) : class_ (old.class_), aclArpData(old.aclArpData)
35 {
36 }
37
38 ACLARP::~ACLARP()
39 {
40 }
41
42 char const *
43 ACLARP::typeString() const
44 {
45 return class_;
46 }
47
48 bool
49 ACLARP::empty () const
50 {
51 return aclArpData.empty();
52 }
53
54 /* ==== BEGIN ARP ACL SUPPORT ============================================= */
55
56 /*
57 * From: dale@server.ctam.bitmcnit.bryansk.su (Dale)
58 * To: wessels@nlanr.net
59 * Subject: Another Squid patch... :)
60 * Date: Thu, 04 Dec 1997 19:55:01 +0300
61 * ============================================================================
62 *
63 * Working on setting up a proper firewall for a network containing some
64 * Win'95 computers at our Univ, I've discovered that some smart students
65 * avoid the restrictions easily just changing their IP addresses in Win'95
66 * Contol Panel... It has been getting boring, so I took Squid-1.1.18
67 * sources and added a new acl type for hard-wired access control:
68 *
69 * acl <name> arp <Ethernet address> ...
70 *
71 * For example,
72 *
73 * acl students arp 00:00:21:55:ed:22 00:00:21:ff:55:38
74 *
75 * NOTE: Linux code by David Luyer <luyer@ucs.uwa.edu.au>.
76 * Original (BSD-specific) code no longer works.
77 * Solaris code by R. Gancarz <radekg@solaris.elektrownia-lagisza.com.pl>
78 */
79
80 Eui::Eui48 *
81 aclParseArpData(const char *t)
82 {
83 char buf[256];
84 Eui::Eui48 *q = new Eui::Eui48;
85 debugs(28, 5, "aclParseArpData: " << t);
86
87 if (sscanf(t, "%[0-9a-fA-F:]", buf) != 1) {
88 debugs(28, DBG_CRITICAL, "aclParseArpData: Bad ethernet address: '" << t << "'");
89 safe_free(q);
90 return NULL;
91 }
92
93 if (!q->decode(buf)) {
94 debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
95 debugs(28, DBG_CRITICAL, "aclParseArpData: Ignoring invalid ARP acl entry: can't parse '" << buf << "'");
96 safe_free(q);
97 return NULL;
98 }
99
100 return q;
101 }
102
103 /*******************/
104 /* aclParseArpList */
105 /*******************/
106 void
107 ACLARP::parse()
108 {
109 char *t = NULL;
110 Eui::Eui48 *q = NULL;
111
112 while ((t = strtokFile())) {
113 if ((q = aclParseArpData(t)) == NULL)
114 continue;
115
116 aclArpData.insert(*q);
117 safe_free(q);
118 }
119
120 }
121
122 int
123 ACLARP::match(ACLChecklist *cl)
124 {
125 ACLFilledChecklist *checklist = Filled(cl);
126
127 /* IPv6 does not do ARP */
128 if (!checklist->src_addr.isIPv4()) {
129 debugs(14, 3, "ACLARP::match: IPv4 Required for ARP Lookups. Skipping " << checklist->src_addr );
130 return 0;
131 }
132
133 Eui::Eui48 lookingFor;
134 lookingFor.lookup(checklist->src_addr);
135 return (aclArpData.find(lookingFor) != aclArpData.end());
136 }
137
138 SBufList
139 ACLARP::dump() const
140 {
141 SBufList sl;
142 for (auto i = aclArpData.cbegin(); i != aclArpData.cend(); ++i) {
143 char buf[48];
144 i->encode(buf,48);
145 sl.push_back(SBuf(buf));
146 }
147 return sl;
148 }
149
150 /* ==== END ARP ACL SUPPORT =============================================== */
151
152 #endif /* USE_SQUID_EUI */
153