]>
Commit | Line | Data |
---|---|---|
a98c2da5 AJ |
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 "eui/Eui64.h" | |
42 | #include "ip/IpAddress.h" | |
43 | #include "wordlist.h" | |
44 | ||
45 | static void aclParseEuiList(SplayNode<Eui::Eui64 *> **curlist); | |
b7ac5457 | 46 | static int aclMatchEui(SplayNode<Eui::Eui64 *> **dataptr, Ip::Address &c); |
a98c2da5 AJ |
47 | static SplayNode<Eui::Eui64 *>::SPLAYCMP aclEui64Compare; |
48 | static SplayNode<Eui::Eui64 *>::SPLAYWALKEE aclDumpEuiListWalkee; | |
49 | ||
50 | ||
51 | ACL * | |
52 | ACLEui64::clone() const | |
53 | { | |
54 | return new ACLEui64(*this); | |
55 | } | |
56 | ||
57 | ACLEui64::ACLEui64 (char const *theClass) : data (NULL), class_ (theClass) | |
58 | {} | |
59 | ||
60 | ACLEui64::ACLEui64 (ACLEui64 const & old) : data (NULL), class_ (old.class_) | |
61 | { | |
62 | /* we don't have copy constructors for the data yet */ | |
63 | assert (!old.data); | |
64 | } | |
65 | ||
66 | ACLEui64::~ACLEui64() | |
67 | { | |
68 | if (data) | |
69 | data->destroy(SplayNode<Eui::Eui64*>::DefaultFree); | |
70 | } | |
71 | ||
72 | char const * | |
73 | ACLEui64::typeString() const | |
74 | { | |
75 | return class_; | |
76 | } | |
77 | ||
78 | bool | |
79 | ACLEui64::empty () const | |
80 | { | |
81 | return data->empty(); | |
82 | } | |
83 | ||
84 | Eui::Eui64 * | |
85 | aclParseEuiData(const char *t) | |
86 | { | |
87 | char buf[256]; | |
88 | Eui::Eui64 *q = new Eui::Eui64; | |
89 | debugs(28, 5, "aclParseEuiData: " << t); | |
90 | ||
91 | if (sscanf(t, "%[0-9a-fA-F:]", buf) != 1) { | |
92 | debugs(28, 0, "aclParseEuiData: Bad EUI-64 address: '" << t << "'"); | |
93 | safe_free(q); | |
94 | return NULL; | |
95 | } | |
96 | ||
97 | if (!q->decode(buf)) { | |
98 | debugs(28, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); | |
99 | debugs(28, 0, "aclParseEuiData: Ignoring invalid EUI-64 acl entry: can't parse '" << buf << "'"); | |
100 | safe_free(q); | |
101 | return NULL; | |
102 | } | |
103 | ||
104 | return q; | |
105 | } | |
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 | |
b7ac5457 | 150 | aclMatchEui(SplayNode<Eui::Eui64 *> **dataptr, Ip::Address &c) |
a98c2da5 AJ |
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 */ |