]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Eui64.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / Eui64.cc
1 /*
2 * DEBUG: section 28 Access Control
3 * AUTHOR: Amos Jeffries
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 *
32 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
33 */
34
35 #include "squid.h"
36
37 #if USE_SQUID_EUI
38
39 #include "acl/Eui64.h"
40 #include "acl/FilledChecklist.h"
41 #include "Debug.h"
42 #include "eui/Eui64.h"
43 #include "ip/Address.h"
44 #include "protos.h"
45 #include "wordlist.h"
46
47 static void aclParseEuiList(SplayNode<Eui::Eui64 *> **curlist);
48 static int aclMatchEui(SplayNode<Eui::Eui64 *> **dataptr, Ip::Address &c);
49 static SplayNode<Eui::Eui64 *>::SPLAYCMP aclEui64Compare;
50 static SplayNode<Eui::Eui64 *>::SPLAYWALKEE aclDumpEuiListWalkee;
51
52 ACL *
53 ACLEui64::clone() const
54 {
55 return new ACLEui64(*this);
56 }
57
58 ACLEui64::ACLEui64 (char const *theClass) : data (NULL), class_ (theClass)
59 {}
60
61 ACLEui64::ACLEui64 (ACLEui64 const & old) : data (NULL), class_ (old.class_)
62 {
63 /* we don't have copy constructors for the data yet */
64 assert (!old.data);
65 }
66
67 ACLEui64::~ACLEui64()
68 {
69 if (data)
70 data->destroy(SplayNode<Eui::Eui64*>::DefaultFree);
71 }
72
73 char const *
74 ACLEui64::typeString() const
75 {
76 return class_;
77 }
78
79 bool
80 ACLEui64::empty () const
81 {
82 return data->empty();
83 }
84
85 Eui::Eui64 *
86 aclParseEuiData(const char *t)
87 {
88 char buf[256];
89 Eui::Eui64 *q = new Eui::Eui64;
90 debugs(28, 5, "aclParseEuiData: " << t);
91
92 if (sscanf(t, "%[0-9a-fA-F:]", buf) != 1) {
93 debugs(28, DBG_CRITICAL, "aclParseEuiData: Bad EUI-64 address: '" << t << "'");
94 safe_free(q);
95 return NULL;
96 }
97
98 if (!q->decode(buf)) {
99 debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
100 debugs(28, DBG_CRITICAL, "aclParseEuiData: Ignoring invalid EUI-64 acl entry: can't parse '" << buf << "'");
101 safe_free(q);
102 return NULL;
103 }
104
105 return q;
106 }
107
108 /*******************/
109 /* aclParseEuiList */
110 /*******************/
111 void
112 ACLEui64::parse()
113 {
114 aclParseEuiList(&data);
115 }
116
117 void
118 aclParseEuiList(SplayNode<Eui::Eui64 *> **curlist)
119 {
120 char *t = NULL;
121 SplayNode<Eui::Eui64*> **Top = curlist;
122 Eui::Eui64 *q = NULL;
123
124 while ((t = strtokFile())) {
125 if ((q = aclParseEuiData(t)) == NULL)
126 continue;
127
128 *Top = (*Top)->insert(q, aclEui64Compare);
129 }
130 }
131
132 int
133 ACLEui64::match(ACLChecklist *cl)
134 {
135 ACLFilledChecklist *checklist = Filled(cl);
136
137 /* IPv4 does not do EUI-64 (yet) */
138 if (!checklist->src_addr.IsIPv6()) {
139 debugs(14, 3, "ACLEui64::match: IPv6 Required for EUI-64 Lookups. Skipping " << checklist->src_addr );
140 return 0;
141 }
142
143 return aclMatchEui(&data, checklist->src_addr);
144 }
145
146 /***************/
147 /* aclMatchEui */
148 /***************/
149 int
150 aclMatchEui(SplayNode<Eui::Eui64 *> **dataptr, Ip::Address &c)
151 {
152 Eui::Eui64 result;
153 SplayNode<Eui::Eui64 *> **Top = dataptr;
154
155 if (result.lookup(c)) {
156 /* Do ACL match lookup */
157 *Top = (*Top)->splay(&result, aclEui64Compare);
158 debugs(28, 3, "aclMatchEui: '" << c << "' " << (splayLastResult ? "NOT found" : "found"));
159 return (0 == splayLastResult);
160 }
161
162 /*
163 * Address was not found on any interface
164 */
165 debugs(28, 3, "aclMatchEui: " << c << " NOT found");
166 return 0;
167 }
168
169 static int
170 aclEui64Compare(Eui::Eui64 * const &a, Eui::Eui64 * const &b)
171 {
172 return memcmp(a, b, sizeof(Eui::Eui64));
173 }
174
175 static void
176 aclDumpEuiListWalkee(Eui::Eui64 * const &node, void *state)
177 {
178 static char buf[48];
179 node->encode(buf, 48);
180 wordlistAdd((wordlist **)state, buf);
181 }
182
183 wordlist *
184 ACLEui64::dump() const
185 {
186 wordlist *w = NULL;
187 data->walk(aclDumpEuiListWalkee, &w);
188 return w;
189 }
190
191 #endif /* USE_SQUID_EUI */