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