]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Arp.cc
Merge from trunk rev.13866
[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 delete 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 delete q;
93 return NULL;
94 }
95
96 return q;
97 }
98
99 /*******************/
100 /* aclParseArpList */
101 /*******************/
102 void
103 ACLARP::parse()
104 {
105 while (const char *t = strtokFile()) {
106 if (Eui::Eui48 *q = aclParseArpData(t)) {
107 aclArpData.insert(*q);
108 delete q;
109 }
110 }
111 }
112
113 int
114 ACLARP::match(ACLChecklist *cl)
115 {
116 ACLFilledChecklist *checklist = Filled(cl);
117
118 /* IPv6 does not do ARP */
119 if (!checklist->src_addr.isIPv4()) {
120 debugs(14, 3, "ACLARP::match: IPv4 Required for ARP Lookups. Skipping " << checklist->src_addr );
121 return 0;
122 }
123
124 Eui::Eui48 lookingFor;
125 lookingFor.lookup(checklist->src_addr);
126 return (aclArpData.find(lookingFor) != aclArpData.end());
127 }
128
129 SBufList
130 ACLARP::dump() const
131 {
132 SBufList sl;
133 for (auto i = aclArpData.cbegin(); i != aclArpData.cend(); ++i) {
134 char buf[48];
135 i->encode(buf,48);
136 sl.push_back(SBuf(buf));
137 }
138 return sl;
139 }
140
141 /* ==== END ARP ACL SUPPORT =============================================== */
142
143 #endif /* USE_SQUID_EUI */
144